Skip to content

SigNoz is an open-source, OpenTelemetry-native observability platform for your team and their AI agents. Get logs, metrics, and traces in one tool with features like APM, distributed tracing, log management, infra monitoring, etc. Combined with SigNoz MCP and a native AI teammate (in SigNoz Cloud) it helps you build more resilient apps.

1.1 KB
Raw Blame
package querier

import (
	"context"
	"testing"
	"time"

	"github.com/stretchr/testify/assert"
	"github.com/stretchr/testify/require"

	"github.com/SigNoz/signoz/pkg/config"
	"github.com/SigNoz/signoz/pkg/config/configtest"
	"github.com/SigNoz/signoz/pkg/factory"
)

func TestSchemaMetadataStoreCacheTTLFromEnv(t *testing.T) {
	testCases := []struct {
		name string
		env  map[string]string
		want time.Duration
	}{
		{
			name: "Unset_CachesForProcessLifetime",
			want: 0,
		},
		{
			name: "Nanosecond_ExpiresImmediately",
			env:  map[string]string{"SIGNOZ_QUERIER_SCHEMAMETADATASTORE_CACHE__TTL": "1ns"},
			want: time.Nanosecond,
		},
	}

	for _, testCase := range testCases {
		t.Run(testCase.name, func(t *testing.T) {
			for key, value := range testCase.env {
				t.Setenv(key, value)
			}
			conf, err := config.New(context.Background(), configtest.NewResolverConfig(), []factory.ConfigFactory{NewConfigFactory()})
			require.NoError(t, err)

			actual := Config{}
			require.NoError(t, conf.Unmarshal("querier", &actual))
			assert.Equal(t, testCase.want, actual.SchemaMetadataStore.CacheTTL)
		})
	}
}