From ec818332dcc7a381add078d091bc3968c0d91d3f Mon Sep 17 00:00:00 2001 From: Arve Knudsen Date: Tue, 16 Jul 2024 14:49:04 +0200 Subject: [PATCH] Add config tests Signed-off-by: Arve Knudsen --- config/config_test.go | 18 ++++++++++++++++++ config/testdata/conf.good.yml | 3 +++ .../otlp_sanitize_resource_attributes.good.yml | 2 ++ 3 files changed, 23 insertions(+) create mode 100644 config/testdata/otlp_sanitize_resource_attributes.good.yml diff --git a/config/config_test.go b/config/config_test.go index 3c4907a46..5822d2ceb 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -156,6 +156,12 @@ var expectedConf = &Config{ }, }, + OTLPConfig: OTLPConfig{ + PromoteResourceAttributes: []string{ + "k8s.cluster.name", "k8s.job.name", "k8s.namespace.name", + }, + }, + RemoteReadConfigs: []*RemoteReadConfig{ { URL: mustParseURL("http://remote1/read"), @@ -1471,6 +1477,18 @@ func TestRemoteWriteRetryOnRateLimit(t *testing.T) { require.False(t, got.RemoteWriteConfigs[1].QueueConfig.RetryOnRateLimit) } +func TestOTLPSanitizeResourceAttributes(t *testing.T) { + want, err := LoadFile(filepath.Join("testdata", "otlp_sanitize_resource_attributes.good.yml"), false, false, log.NewNopLogger()) + require.NoError(t, err) + + out, err := yaml.Marshal(want) + require.NoError(t, err) + var got Config + require.NoError(t, yaml.UnmarshalStrict(out, &got)) + + require.Equal(t, []string{"k8s.cluster.name", "k8s.job.name", "k8s.namespace.name"}, got.OTLPConfig.PromoteResourceAttributes) +} + func TestLoadConfig(t *testing.T) { // Parse a valid file that sets a global scrape timeout. This tests whether parsing // an overwritten default field in the global config permanently changes the default. diff --git a/config/testdata/conf.good.yml b/config/testdata/conf.good.yml index 0e0aa2bd5..56741822c 100644 --- a/config/testdata/conf.good.yml +++ b/config/testdata/conf.good.yml @@ -45,6 +45,9 @@ remote_write: headers: name: value +otlp: + promote_resource_attributes: ["k8s.cluster.name", "k8s.job.name", "k8s.namespace.name"] + remote_read: - url: http://remote1/read read_recent: true diff --git a/config/testdata/otlp_sanitize_resource_attributes.good.yml b/config/testdata/otlp_sanitize_resource_attributes.good.yml new file mode 100644 index 000000000..ce91302fe --- /dev/null +++ b/config/testdata/otlp_sanitize_resource_attributes.good.yml @@ -0,0 +1,2 @@ +otlp: + promote_resource_attributes: ["k8s.cluster.name", "k8s.job.name", "k8s.namespace.name", " k8s.job.name "]