Skip to content

Commit

Permalink
dedup __name__ label
Browse files Browse the repository at this point in the history
Signed-off-by: Thibault Mange <[email protected]>
  • Loading branch information
thibaultmg committed Jan 15, 2025
1 parent b2f7fdd commit 84a2d0d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions collectors/metrics/pkg/metricsclient/metricsclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 == "" {
Expand Down
9 changes: 7 additions & 2 deletions collectors/metrics/pkg/metricsclient/metricsclient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ func Test_convertToTimeseries(t *testing.T) {
fooLabelName := "foo"
fooLabelValue1 := "bar"
fooLabelValue2 := "baz"
nameLabel := nameLabelName

emptyLabelName := ""

Expand Down Expand Up @@ -206,8 +207,12 @@ func Test_convertToTimeseries(t *testing.T) {
Counter: &clientmodel.Counter{Value: &value42},
TimestampMs: &timestamp,
}, {
// 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: &timestamp,
}, {
Expand Down

0 comments on commit 84a2d0d

Please sign in to comment.