Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release-2.12] Fix: Deduplicate the __name__ label in the metrics collector #1783

Open
wants to merge 1 commit into
base: release-2.12
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading