From 84a2d0dc2b86a6cd5174aa81ed7d71dfd84803f8 Mon Sep 17 00:00:00 2001 From: Thibault Mange <22740367+thibaultmg@users.noreply.github.com> Date: Tue, 14 Jan 2025 11:25:50 +0100 Subject: [PATCH] dedup __name__ label Signed-off-by: Thibault Mange <22740367+thibaultmg@users.noreply.github.com> --- collectors/metrics/pkg/metricsclient/metricsclient.go | 1 + .../metrics/pkg/metricsclient/metricsclient_test.go | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/collectors/metrics/pkg/metricsclient/metricsclient.go b/collectors/metrics/pkg/metricsclient/metricsclient.go index 4f28c065e..354f40828 100644 --- a/collectors/metrics/pkg/metricsclient/metricsclient.go +++ b/collectors/metrics/pkg/metricsclient/metricsclient.go @@ -389,6 +389,7 @@ func convertToTimeseries(p *PartitionedMetrics, now time.Time) ([]prompb.TimeSer }} dedup := make(map[string]struct{}) + dedup[nameLabelName] = struct{}{} for _, l := range m.Label { // Skip empty labels. if *l.Name == "" || *l.Value == "" { diff --git a/collectors/metrics/pkg/metricsclient/metricsclient_test.go b/collectors/metrics/pkg/metricsclient/metricsclient_test.go index 05402bac4..57c8dcb8b 100644 --- a/collectors/metrics/pkg/metricsclient/metricsclient_test.go +++ b/collectors/metrics/pkg/metricsclient/metricsclient_test.go @@ -46,6 +46,7 @@ func Test_convertToTimeseries(t *testing.T) { fooLabelName := "foo" fooLabelValue1 := "bar" fooLabelValue2 := "baz" + nameLabel := nameLabelName emptyLabelName := "" @@ -206,8 +207,12 @@ func Test_convertToTimeseries(t *testing.T) { Counter: &clientmodel.Counter{Value: &value42}, TimestampMs: ×tamp, }, { - // With duplicate labels. - Label: []*clientmodel.LabelPair{{Name: &fooLabelName, Value: &fooLabelValue2}, {Name: &fooLabelName, Value: &fooLabelValue2}}, + // With duplicate labels, including the __name__ label. + Label: []*clientmodel.LabelPair{ + {Name: &fooLabelName, Value: &fooLabelValue2}, + {Name: &fooLabelName, Value: &fooLabelValue2}, + {Name: &nameLabel, Value: &barMetricName}, + }, Counter: &clientmodel.Counter{Value: &value42}, TimestampMs: ×tamp, }, {