@@ -66,7 +66,7 @@ func TestManagedRegistry_counter(t *testing.T) {
6666
6767 counter := registry .NewCounter ("my_counter" )
6868
69- counter .Inc (newLabelValueCombo ([]string {"label" }, []string {"value-1" }), 1.0 )
69+ counter .Inc (newLabelValueCombo ([]string {"label" , "label" }, []string {"repeated-value" , "value-1" }), 1.0 )
7070
7171 expectedSamples := []sample {
7272 newSample (map [string ]string {"__name__" : "my_counter" , "label" : "value-1" , "__metrics_gen_instance" : mustGetHostname ()}, 0 , 0.0 ),
@@ -304,6 +304,14 @@ func collectRegistryMetricsAndAssert(t *testing.T, r *ManagedRegistry, appender
304304 collectionTimeMs := time .Now ().UnixMilli ()
305305 r .CollectMetrics (context .Background ())
306306
307+ // Validate that there are no duplicate label names in any sample
308+ for i , sample := range appender .samples {
309+ if duplicateLabel , hasDuplicate := sample .l .HasDuplicateLabelNames (); hasDuplicate {
310+ t .Errorf ("Sample %d has duplicate label name %q. Full labels: %v" ,
311+ i , duplicateLabel , sample .l )
312+ }
313+ }
314+
307315 // Ignore the collection time on expected samples, since we won't know when the collection will actually take place.
308316 for i := range expectedSamples {
309317 expectedSamples [i ].t = collectionTimeMs
0 commit comments