From dd9e125455ac4d76dd7204def26f1d47edaee85f Mon Sep 17 00:00:00 2001 From: beorn7 Date: Sun, 30 Sep 2018 10:38:57 +0200 Subject: [PATCH] Expose failure to detect duplicate label names This is #471. Signed-off-by: beorn7 --- prometheus/registry_test.go | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/prometheus/registry_test.go b/prometheus/registry_test.go index f37c4ce..0c79261 100644 --- a/prometheus/registry_test.go +++ b/prometheus/registry_test.go @@ -308,6 +308,29 @@ collected metric named "complex_count" collides with previously collected summar collected metric named "complex_count" collides with previously collected histogram named "complex" `) + externalMetricFamilyWithDuplicateLabel := &dto.MetricFamily{ + Name: proto.String("broken_metric"), + Help: proto.String("The registry should detect the duplicate label."), + Type: dto.MetricType_COUNTER.Enum(), + Metric: []*dto.Metric{ + { + Label: []*dto.LabelPair{ + { + Name: proto.String("foo"), + Value: proto.String("bar"), + }, + { + Name: proto.String("foo"), + Value: proto.String("baz"), + }, + }, + Counter: &dto.Counter{ + Value: proto.Float64(2.7), + }, + }, + }, + } + duplicateLabelMsg := []byte(`duplicate label mumble mumble`) type output struct { headers map[string]string @@ -646,6 +669,20 @@ collected metric named "complex_count" collides with previously collected histog externalMetricFamilyWithBucketSuffix, }, }, + { // 22 + headers: map[string]string{ + "Accept": "text/plain", + }, + out: output{ + headers: map[string]string{ + "Content-Type": `text/plain; version=0.0.4; charset=utf-8`, + }, + body: duplicateLabelMsg, + }, + externalMF: []*dto.MetricFamily{ + externalMetricFamilyWithDuplicateLabel, + }, + }, } for i, scenario := range scenarios { registry := prometheus.NewPedanticRegistry()