diff --git a/prometheus/registry.go b/prometheus/registry.go index 4a6aa88..5626ab2 100644 --- a/prometheus/registry.go +++ b/prometheus/registry.go @@ -281,6 +281,13 @@ func (r *registry) dumpDelimitedPB(w io.Writer) { container.Metric.dumpChildren(f) for name, value := range container.BaseLabels { + if model.LabelName(name) == model.MetricNameLabel { + // The name is already in MetricFamily. + continue + // TODO: Once JSON is history, do not anymore + // add the __name__ label to BaseLabels and + // then remove this check. + } p := &dto.LabelPair{ Name: proto.String(name), Value: proto.String(value), diff --git a/prometheus/registry_test.go b/prometheus/registry_test.go index 46af528..ec58927 100644 --- a/prometheus/registry_test.go +++ b/prometheus/registry_test.go @@ -229,10 +229,6 @@ func testHandler(t tester) { Name: proto.String("externalbasename"), Value: proto.String("externalbasevalue"), }, - &dto.LabelPair{ - Name: proto.String("__name__"), - Value: proto.String("externalname"), - }, }, Counter: &dto.Counter{ Value: proto.Float64(1), @@ -272,10 +268,6 @@ func testHandler(t tester) { Name: proto.String("basename"), Value: proto.String("basevalue"), }, - &dto.LabelPair{ - Name: proto.String("__name__"), - Value: proto.String("name"), - }, }, Counter: &dto.Counter{ Value: proto.Float64(1), @@ -291,10 +283,6 @@ func testHandler(t tester) { Name: proto.String("basename"), Value: proto.String("basevalue"), }, - &dto.LabelPair{ - Name: proto.String("__name__"), - Value: proto.String("name"), - }, }, Counter: &dto.Counter{ Value: proto.Float64(1),