Skip to content

Commit dd9e125

Browse files
author
beorn7
committed
Expose failure to detect duplicate label names
This is #471. Signed-off-by: beorn7 <[email protected]>
1 parent daeaac0 commit dd9e125

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

prometheus/registry_test.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,29 @@ collected metric named "complex_count" collides with previously collected summar
308308
309309
collected metric named "complex_count" collides with previously collected histogram named "complex"
310310
`)
311+
externalMetricFamilyWithDuplicateLabel := &dto.MetricFamily{
312+
Name: proto.String("broken_metric"),
313+
Help: proto.String("The registry should detect the duplicate label."),
314+
Type: dto.MetricType_COUNTER.Enum(),
315+
Metric: []*dto.Metric{
316+
{
317+
Label: []*dto.LabelPair{
318+
{
319+
Name: proto.String("foo"),
320+
Value: proto.String("bar"),
321+
},
322+
{
323+
Name: proto.String("foo"),
324+
Value: proto.String("baz"),
325+
},
326+
},
327+
Counter: &dto.Counter{
328+
Value: proto.Float64(2.7),
329+
},
330+
},
331+
},
332+
}
333+
duplicateLabelMsg := []byte(`duplicate label mumble mumble`)
311334

312335
type output struct {
313336
headers map[string]string
@@ -646,6 +669,20 @@ collected metric named "complex_count" collides with previously collected histog
646669
externalMetricFamilyWithBucketSuffix,
647670
},
648671
},
672+
{ // 22
673+
headers: map[string]string{
674+
"Accept": "text/plain",
675+
},
676+
out: output{
677+
headers: map[string]string{
678+
"Content-Type": `text/plain; version=0.0.4; charset=utf-8`,
679+
},
680+
body: duplicateLabelMsg,
681+
},
682+
externalMF: []*dto.MetricFamily{
683+
externalMetricFamilyWithDuplicateLabel,
684+
},
685+
},
649686
}
650687
for i, scenario := range scenarios {
651688
registry := prometheus.NewPedanticRegistry()

0 commit comments

Comments
 (0)