From 174f828d7008c3189e5740e60461469762bc1bd6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gy=C3=B6rgy=20Krajcsovits?= Date: Fri, 29 Nov 2024 15:19:14 +0100 Subject: [PATCH] Rename to keep_identifying_resource_attributes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: György Krajcsovits --- config/config.go | 6 +++--- config/config_test.go | 4 ++-- ...keep_identifying_resource_attributes.good.yml | 2 ++ ...lp_allow_service_name_in_target_info.good.yml | 2 -- .../prometheusremotewrite/helper.go | 2 +- .../prometheusremotewrite/metrics_to_prw.go | 16 ++++++++-------- .../prometheusremotewrite/metrics_to_prw_test.go | 8 ++++---- storage/remote/write_handler.go | 8 ++++---- 8 files changed, 24 insertions(+), 24 deletions(-) create mode 100644 config/testdata/otlp_allow_keep_identifying_resource_attributes.good.yml delete mode 100644 config/testdata/otlp_allow_service_name_in_target_info.good.yml diff --git a/config/config.go b/config/config.go index dfa3c7cd6..86d856353 100644 --- a/config/config.go +++ b/config/config.go @@ -1429,9 +1429,9 @@ var ( // OTLPConfig is the configuration for writing to the OTLP endpoint. type OTLPConfig struct { - PromoteResourceAttributes []string `yaml:"promote_resource_attributes,omitempty"` - TranslationStrategy translationStrategyOption `yaml:"translation_strategy,omitempty"` - ServiceNameInTargetInfo bool `yaml:"service_name_in_target_info,omitempty"` + PromoteResourceAttributes []string `yaml:"promote_resource_attributes,omitempty"` + TranslationStrategy translationStrategyOption `yaml:"translation_strategy,omitempty"` + KeepIdentifyingResourceAttributes bool `yaml:"keep_identifying_resource_attributes,omitempty"` } // UnmarshalYAML implements the yaml.Unmarshaler interface. diff --git a/config/config_test.go b/config/config_test.go index 2fed3a06e..01eeb6235 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -1556,7 +1556,7 @@ func TestOTLPSanitizeResourceAttributes(t *testing.T) { func TestOTLPAllowServiceNameInTargetInfo(t *testing.T) { t.Run("good config", func(t *testing.T) { - want, err := LoadFile(filepath.Join("testdata", "otlp_allow_service_name_in_target_info.good.yml"), false, promslog.NewNopLogger()) + want, err := LoadFile(filepath.Join("testdata", "otlp_allow_keep_identifying_resource_attributes.good.yml"), false, promslog.NewNopLogger()) require.NoError(t, err) out, err := yaml.Marshal(want) @@ -1564,7 +1564,7 @@ func TestOTLPAllowServiceNameInTargetInfo(t *testing.T) { var got Config require.NoError(t, yaml.UnmarshalStrict(out, &got)) - require.Equal(t, true, got.OTLPConfig.ServiceNameInTargetInfo) + require.Equal(t, true, got.OTLPConfig.KeepIdentifyingResourceAttributes) }) } diff --git a/config/testdata/otlp_allow_keep_identifying_resource_attributes.good.yml b/config/testdata/otlp_allow_keep_identifying_resource_attributes.good.yml new file mode 100644 index 000000000..63151e2a7 --- /dev/null +++ b/config/testdata/otlp_allow_keep_identifying_resource_attributes.good.yml @@ -0,0 +1,2 @@ +otlp: + keep_identifying_resource_attributes: true diff --git a/config/testdata/otlp_allow_service_name_in_target_info.good.yml b/config/testdata/otlp_allow_service_name_in_target_info.good.yml deleted file mode 100644 index 3bd389d2e..000000000 --- a/config/testdata/otlp_allow_service_name_in_target_info.good.yml +++ /dev/null @@ -1,2 +0,0 @@ -otlp: - service_name_in_target_info: true diff --git a/storage/remote/otlptranslator/prometheusremotewrite/helper.go b/storage/remote/otlptranslator/prometheusremotewrite/helper.go index e15ca4b56..316dd60c6 100644 --- a/storage/remote/otlptranslator/prometheusremotewrite/helper.go +++ b/storage/remote/otlptranslator/prometheusremotewrite/helper.go @@ -600,7 +600,7 @@ func addResourceTargetInfo(resource pcommon.Resource, settings Settings, timesta } settings.PromoteResourceAttributes = nil - if settings.ServiceNameInTargetInfo { + if settings.KeepIdentifyingResourceAttributes { // Do not pass identifying attributes as ignoreAttrs below. identifyingAttrs = nil } diff --git a/storage/remote/otlptranslator/prometheusremotewrite/metrics_to_prw.go b/storage/remote/otlptranslator/prometheusremotewrite/metrics_to_prw.go index 1979b9185..6779c9ed8 100644 --- a/storage/remote/otlptranslator/prometheusremotewrite/metrics_to_prw.go +++ b/storage/remote/otlptranslator/prometheusremotewrite/metrics_to_prw.go @@ -32,14 +32,14 @@ import ( ) type Settings struct { - Namespace string - ExternalLabels map[string]string - DisableTargetInfo bool - ExportCreatedMetric bool - AddMetricSuffixes bool - AllowUTF8 bool - PromoteResourceAttributes []string - ServiceNameInTargetInfo bool + Namespace string + ExternalLabels map[string]string + DisableTargetInfo bool + ExportCreatedMetric bool + AddMetricSuffixes bool + AllowUTF8 bool + PromoteResourceAttributes []string + KeepIdentifyingResourceAttributes bool } // PrometheusConverter converts from OTel write format to Prometheus remote write format. diff --git a/storage/remote/otlptranslator/prometheusremotewrite/metrics_to_prw_test.go b/storage/remote/otlptranslator/prometheusremotewrite/metrics_to_prw_test.go index 2bb29ecd7..7c9699a7e 100644 --- a/storage/remote/otlptranslator/prometheusremotewrite/metrics_to_prw_test.go +++ b/storage/remote/otlptranslator/prometheusremotewrite/metrics_to_prw_test.go @@ -35,8 +35,8 @@ import ( func TestFromMetrics(t *testing.T) { - for _, serviceNameInTargetInfo := range []bool{false, true} { - t.Run(fmt.Sprintf("successful/keepIdentifyingAttributes=%v", serviceNameInTargetInfo), func(t *testing.T) { + for _, keepIdentifyingResourceAttributes := range []bool{false, true} { + t.Run(fmt.Sprintf("successful/keepIdentifyingAttributes=%v", keepIdentifyingResourceAttributes), func(t *testing.T) { converter := NewPrometheusConverter() payload := createExportRequest(5, 128, 128, 2, 0) var expMetadata []prompb.MetricMetadata @@ -61,7 +61,7 @@ func TestFromMetrics(t *testing.T) { annots, err := converter.FromMetrics( context.Background(), payload.Metrics(), - Settings{ServiceNameInTargetInfo: serviceNameInTargetInfo}, + Settings{KeepIdentifyingResourceAttributes: keepIdentifyingResourceAttributes}, ) require.NoError(t, err) require.Empty(t, annots) @@ -81,7 +81,7 @@ func TestFromMetrics(t *testing.T) { target_info_count++ require.Equal(t, "test-namespace/test-service", lbls.Get("job")) require.Equal(t, "id1234", lbls.Get("instance")) - if serviceNameInTargetInfo { + if keepIdentifyingResourceAttributes { require.Equal(t, "test-service", lbls.Get("service_name")) require.Equal(t, "test-namespace", lbls.Get("service_namespace")) require.Equal(t, "id1234", lbls.Get("service_instance_id")) diff --git a/storage/remote/write_handler.go b/storage/remote/write_handler.go index 67c7f7627..afb50ef26 100644 --- a/storage/remote/write_handler.go +++ b/storage/remote/write_handler.go @@ -512,10 +512,10 @@ func (h *otlpWriteHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { converter := otlptranslator.NewPrometheusConverter() annots, err := converter.FromMetrics(r.Context(), req.Metrics(), otlptranslator.Settings{ - AddMetricSuffixes: true, - AllowUTF8: otlpCfg.TranslationStrategy == config.NoUTF8EscapingWithSuffixes, - PromoteResourceAttributes: otlpCfg.PromoteResourceAttributes, - ServiceNameInTargetInfo: otlpCfg.ServiceNameInTargetInfo, + AddMetricSuffixes: true, + AllowUTF8: otlpCfg.TranslationStrategy == config.NoUTF8EscapingWithSuffixes, + PromoteResourceAttributes: otlpCfg.PromoteResourceAttributes, + KeepIdentifyingResourceAttributes: otlpCfg.KeepIdentifyingResourceAttributes, }) if err != nil { h.logger.Warn("Error translating OTLP metrics to Prometheus write request", "err", err)