@@ -1289,13 +1289,23 @@ func Test_EnsureLabelConsistencyAndRemoveDuplicates(t *testing.T) {
12891289 NewPrometheusMetric ("metric1" , []string {"label1" , "label2" , "label3" }, []string {"" , "" , "" }, 3.0 ),
12901290 },
12911291 },
1292+ {
1293+ name : "removes duplicate labels" ,
1294+ metrics : []* PrometheusMetric {
1295+ NewPrometheusMetric ("metric1" , []string {"label1" , "label1" , "label2" }, []string {"value1" , "value1" , "value2" }, 1.0 ),
1296+ },
1297+ observedLabels : map [string ]model.LabelSet {"metric1" : {"label1" : {}, "label2" : {}}},
1298+ output : []* PrometheusMetric {
1299+ NewPrometheusMetric ("metric1" , []string {"label1" , "label2" }, []string {"value1" , "value2" }, 1.0 ),
1300+ },
1301+ },
12921302 {
12931303 name : "duplicate metric" ,
12941304 metrics : []* PrometheusMetric {
12951305 NewPrometheusMetric ("metric1" , []string {"label1" }, []string {"value1" }, 1.0 ),
12961306 NewPrometheusMetric ("metric1" , []string {"label1" }, []string {"value1" }, 1.0 ),
12971307 },
1298- observedLabels : map [string ]model.LabelSet {},
1308+ observedLabels : map [string ]model.LabelSet {"metric1" : { "label1" : {}} },
12991309 output : []* PrometheusMetric {
13001310 NewPrometheusMetric ("metric1" , []string {"label1" }, []string {"value1" }, 1.0 ),
13011311 },
@@ -1306,7 +1316,7 @@ func Test_EnsureLabelConsistencyAndRemoveDuplicates(t *testing.T) {
13061316 NewPrometheusMetric ("metric1" , []string {"label1" , "label2" }, []string {"value1" , "value2" }, 1.0 ),
13071317 NewPrometheusMetric ("metric1" , []string {"label2" , "label1" }, []string {"value2" , "value1" }, 1.0 ),
13081318 },
1309- observedLabels : map [string ]model.LabelSet {},
1319+ observedLabels : map [string ]model.LabelSet {"metric1" : { "label1" : {}, "label2" : {}} },
13101320 output : []* PrometheusMetric {
13111321 NewPrometheusMetric ("metric1" , []string {"label1" , "label2" }, []string {"value1" , "value2" }, 1.0 ),
13121322 },
@@ -1317,10 +1327,10 @@ func Test_EnsureLabelConsistencyAndRemoveDuplicates(t *testing.T) {
13171327 NewPrometheusMetric ("metric1" , []string {"label1" }, []string {"value1" }, 1.0 ),
13181328 NewPrometheusMetric ("metric1" , []string {"label2" }, []string {"value2" }, 1.0 ),
13191329 },
1320- observedLabels : map [string ]model.LabelSet {},
1330+ observedLabels : map [string ]model.LabelSet {"metric1" : { "label1" : {}, "label2" : {}} },
13211331 output : []* PrometheusMetric {
1322- NewPrometheusMetric ("metric1" , []string {"label1" }, []string {"value1" }, 1.0 ),
1323- NewPrometheusMetric ("metric1" , []string {"label2" }, []string {"value2" }, 1.0 ),
1332+ NewPrometheusMetric ("metric1" , []string {"label1" , "label2" }, []string {"value1" , " " }, 1.0 ),
1333+ NewPrometheusMetric ("metric1" , []string {"label1" , " label2" }, []string {"" , "value2" }, 1.0 ),
13241334 },
13251335 },
13261336 {
@@ -1329,7 +1339,7 @@ func Test_EnsureLabelConsistencyAndRemoveDuplicates(t *testing.T) {
13291339 NewPrometheusMetric ("metric1" , []string {"label1" }, []string {"value1" }, 1.0 ),
13301340 NewPrometheusMetric ("metric2" , []string {"label1" }, []string {"value1" }, 1.0 ),
13311341 },
1332- observedLabels : map [string ]model.LabelSet {},
1342+ observedLabels : map [string ]model.LabelSet {"metric1" : { "label1" : {}}, "metric2" : { "label1" : {}} },
13331343 output : []* PrometheusMetric {
13341344 NewPrometheusMetric ("metric1" , []string {"label1" }, []string {"value1" }, 1.0 ),
13351345 NewPrometheusMetric ("metric2" , []string {"label1" }, []string {"value1" }, 1.0 ),
@@ -1341,7 +1351,7 @@ func Test_EnsureLabelConsistencyAndRemoveDuplicates(t *testing.T) {
13411351 NewPrometheusMetric ("metric1" , []string {"label1" }, []string {"value1" }, 1.0 ),
13421352 NewPrometheusMetric ("metric2" , []string {"label2" }, []string {"value2" }, 1.0 ),
13431353 },
1344- observedLabels : map [string ]model.LabelSet {},
1354+ observedLabels : map [string ]model.LabelSet {"metric1" : { "label1" : {}}, "metric2" : { "label2" : {}} },
13451355 output : []* PrometheusMetric {
13461356 NewPrometheusMetric ("metric1" , []string {"label1" }, []string {"value1" }, 1.0 ),
13471357 NewPrometheusMetric ("metric2" , []string {"label2" }, []string {"value2" }, 1.0 ),
@@ -1356,18 +1366,18 @@ func Test_EnsureLabelConsistencyAndRemoveDuplicates(t *testing.T) {
13561366 NewPrometheusMetric ("metric1" , []string {"label1" }, []string {"value1" }, 1.0 ),
13571367 NewPrometheusMetric ("metric1" , []string {"label1" }, []string {"value1" }, 1.0 ),
13581368 },
1359- observedLabels : map [string ]model.LabelSet {},
1369+ observedLabels : map [string ]model.LabelSet {"metric1" : { "label1" : {}}, "metric2" : { "label1" : {}, "label2" : {}} },
13601370 output : []* PrometheusMetric {
1361- NewPrometheusMetric ("metric2" , []string {"label2" }, []string {"value2" }, 1.0 ),
1362- NewPrometheusMetric ("metric2" , []string {"label1" }, []string {"value1" }, 1.0 ),
1371+ NewPrometheusMetric ("metric2" , []string {"label1" , " label2" }, []string {"" , "value2" }, 1.0 ),
1372+ NewPrometheusMetric ("metric2" , []string {"label1" , "label2" }, []string {"value1" , " " }, 1.0 ),
13631373 NewPrometheusMetric ("metric1" , []string {"label1" }, []string {"value1" }, 1.0 ),
13641374 },
13651375 },
13661376 }
13671377
13681378 for _ , tc := range testCases {
13691379 t .Run (tc .name , func (t * testing.T ) {
1370- actual := EnsureLabelConsistencyAndRemoveDuplicates (tc .metrics , tc .observedLabels )
1380+ actual := EnsureLabelConsistencyAndRemoveDuplicates (tc .metrics , tc .observedLabels , logging . NewNopLogger () )
13711381 require .ElementsMatch (t , tc .output , actual )
13721382 })
13731383 }
@@ -1381,14 +1391,15 @@ func Benchmark_EnsureLabelConsistencyAndRemoveDuplicates(b *testing.B) {
13811391 NewPrometheusMetric ("metric1" , []string {"label1" }, []string {"value1" }, 1.0 ),
13821392 }
13831393 observedLabels := map [string ]model.LabelSet {"metric1" : {"label1" : {}, "label2" : {}, "label3" : {}}}
1394+ logger := logging .NewNopLogger ()
13841395
13851396 var output []* PrometheusMetric
13861397
13871398 b .ReportAllocs ()
13881399 b .ResetTimer ()
13891400
13901401 for i := 0 ; i < b .N ; i ++ {
1391- output = EnsureLabelConsistencyAndRemoveDuplicates (metrics , observedLabels )
1402+ output = EnsureLabelConsistencyAndRemoveDuplicates (metrics , observedLabels , logger )
13921403 }
13931404
13941405 expectedOutput := []* PrometheusMetric {
0 commit comments