From a53b48a912200a9e5628eb889b76deb502031345 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gy=C3=B6rgy=20Krajcsovits?= Date: Mon, 25 Nov 2024 09:27:50 +0100 Subject: [PATCH] OTLP translate: keep identifying attributes in target_info MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: György Krajcsovits --- .../otlptranslator/prometheusremotewrite/helper.go | 13 +++++-------- .../prometheusremotewrite/helper_test.go | 2 +- .../prometheusremotewrite/histograms.go | 1 - .../prometheusremotewrite/number_data_points.go | 2 -- 4 files changed, 6 insertions(+), 12 deletions(-) diff --git a/storage/remote/otlptranslator/prometheusremotewrite/helper.go b/storage/remote/otlptranslator/prometheusremotewrite/helper.go index 30cfa8643..89e00f375 100644 --- a/storage/remote/otlptranslator/prometheusremotewrite/helper.go +++ b/storage/remote/otlptranslator/prometheusremotewrite/helper.go @@ -22,7 +22,6 @@ import ( "fmt" "log" "math" - "slices" "sort" "strconv" "unicode/utf8" @@ -117,7 +116,7 @@ var seps = []byte{'\xff'} // if logOnOverwrite is true, the overwrite is logged. Resulting label names are sanitized. // If settings.PromoteResourceAttributes is not empty, it's a set of resource attributes that should be promoted to labels. func createAttributes(resource pcommon.Resource, attributes pcommon.Map, settings Settings, - ignoreAttrs []string, logOnOverwrite bool, extras ...string) []prompb.Label { + logOnOverwrite bool, extras ...string) []prompb.Label { resourceAttrs := resource.Attributes() serviceName, haveServiceName := resourceAttrs.Get(conventions.AttributeServiceName) instance, haveInstanceID := resourceAttrs.Get(conventions.AttributeServiceInstanceID) @@ -147,9 +146,7 @@ func createAttributes(resource pcommon.Resource, attributes pcommon.Map, setting // XXX: Should we always drop service namespace/service name/service instance ID from the labels // (as they get mapped to other Prometheus labels)? attributes.Range(func(key string, value pcommon.Value) bool { - if !slices.Contains(ignoreAttrs, key) { - labels = append(labels, prompb.Label{Name: key, Value: value.AsString()}) - } + labels = append(labels, prompb.Label{Name: key, Value: value.AsString()}) return true }) sort.Stable(ByLabelName(labels)) @@ -251,7 +248,7 @@ func (c *PrometheusConverter) addHistogramDataPoints(ctx context.Context, dataPo pt := dataPoints.At(x) timestamp := convertTimeStamp(pt.Timestamp()) - baseLabels := createAttributes(resource, pt.Attributes(), settings, nil, false) + baseLabels := createAttributes(resource, pt.Attributes(), settings, false) // If the sum is unset, it indicates the _sum metric point should be // omitted @@ -451,7 +448,7 @@ func (c *PrometheusConverter) addSummaryDataPoints(ctx context.Context, dataPoin pt := dataPoints.At(x) timestamp := convertTimeStamp(pt.Timestamp()) - baseLabels := createAttributes(resource, pt.Attributes(), settings, nil, false) + baseLabels := createAttributes(resource, pt.Attributes(), settings, false) // treat sum as a sample in an individual TimeSeries sum := &prompb.Sample{ @@ -600,7 +597,7 @@ func addResourceTargetInfo(resource pcommon.Resource, settings Settings, timesta } settings.PromoteResourceAttributes = nil - labels := createAttributes(resource, attributes, settings, identifyingAttrs, false, model.MetricNameLabel, name) + labels := createAttributes(resource, attributes, settings, false, model.MetricNameLabel, name) haveIdentifier := false for _, l := range labels { if l.Name == model.JobLabel || l.Name == model.InstanceLabel { diff --git a/storage/remote/otlptranslator/prometheusremotewrite/helper_test.go b/storage/remote/otlptranslator/prometheusremotewrite/helper_test.go index b22282097..b3b93dcc0 100644 --- a/storage/remote/otlptranslator/prometheusremotewrite/helper_test.go +++ b/storage/remote/otlptranslator/prometheusremotewrite/helper_test.go @@ -161,7 +161,7 @@ func TestCreateAttributes(t *testing.T) { settings := Settings{ PromoteResourceAttributes: tc.promoteResourceAttributes, } - lbls := createAttributes(resource, attrs, settings, nil, false, model.MetricNameLabel, "test_metric") + lbls := createAttributes(resource, attrs, settings, false, model.MetricNameLabel, "test_metric") assert.ElementsMatch(t, lbls, tc.expectedLabels) }) diff --git a/storage/remote/otlptranslator/prometheusremotewrite/histograms.go b/storage/remote/otlptranslator/prometheusremotewrite/histograms.go index 8349d4f90..dfe0c9f90 100644 --- a/storage/remote/otlptranslator/prometheusremotewrite/histograms.go +++ b/storage/remote/otlptranslator/prometheusremotewrite/histograms.go @@ -54,7 +54,6 @@ func (c *PrometheusConverter) addExponentialHistogramDataPoints(ctx context.Cont resource, pt.Attributes(), settings, - nil, true, model.MetricNameLabel, promName, diff --git a/storage/remote/otlptranslator/prometheusremotewrite/number_data_points.go b/storage/remote/otlptranslator/prometheusremotewrite/number_data_points.go index 6cdab450e..035c0676c 100644 --- a/storage/remote/otlptranslator/prometheusremotewrite/number_data_points.go +++ b/storage/remote/otlptranslator/prometheusremotewrite/number_data_points.go @@ -40,7 +40,6 @@ func (c *PrometheusConverter) addGaugeNumberDataPoints(ctx context.Context, data resource, pt.Attributes(), settings, - nil, true, model.MetricNameLabel, name, @@ -76,7 +75,6 @@ func (c *PrometheusConverter) addSumNumberDataPoints(ctx context.Context, dataPo resource, pt.Attributes(), settings, - nil, true, model.MetricNameLabel, name,