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

Fix: Deduplicate the __name__ label in the metrics collector #1778

Open
wants to merge 1 commit into
base: main
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 @@ -101,7 +101,7 @@
err := withCancel(ctx, c.client, req, func(resp *http.Response) error {
switch resp.StatusCode {
case http.StatusOK:
c.metrics.FederateRequests.WithLabelValues("recording", "200").Inc()

Check failure on line 104 in collectors/metrics/pkg/metricsclient/metricsclient.go

View workflow job for this annotation

GitHub Actions / Formatters + Linters (Static Analysis) for Go

c.metrics.FederateRequests.WithLabelValues("recording", "200").Inc undefined (type prometheus.Counter has no field or method Inc)
case http.StatusUnauthorized:
c.metrics.FederateRequests.WithLabelValues("recording", "401").Inc()
return fmt.Errorf("prometheus server requires authentication: %s", resp.Request.URL)
Expand Down Expand Up @@ -389,6 +389,7 @@
}}

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