@@ -4192,6 +4192,53 @@ func TestDistributor_Push_Relabel(t *testing.T) {
41924192 }
41934193}
41944194
4195+ func TestRemoveEmptyLabels (t * testing.T ) {
4196+ t .Parallel ()
4197+
4198+ tests := []struct {
4199+ name string
4200+ input []cortexpb.LabelAdapter
4201+ expected []cortexpb.LabelAdapter
4202+ }{
4203+ {
4204+ name : "no empty labels" ,
4205+ input : []cortexpb.LabelAdapter {{Name : "job" , Value : "test" }, {Name : "instance" , Value : "localhost" }},
4206+ expected : []cortexpb.LabelAdapter {{Name : "job" , Value : "test" }, {Name : "instance" , Value : "localhost" }},
4207+ },
4208+ {
4209+ name : "empty label at beginning" ,
4210+ input : []cortexpb.LabelAdapter {{Name : "empty" , Value : "" }, {Name : "job" , Value : "test" }},
4211+ expected : []cortexpb.LabelAdapter {{Name : "job" , Value : "test" }},
4212+ },
4213+ {
4214+ name : "empty label in middle" ,
4215+ input : []cortexpb.LabelAdapter {{Name : "job" , Value : "test" }, {Name : "empty" , Value : "" }, {Name : "instance" , Value : "localhost" }},
4216+ expected : []cortexpb.LabelAdapter {{Name : "job" , Value : "test" }, {Name : "instance" , Value : "localhost" }},
4217+ },
4218+ {
4219+ name : "empty label at end" ,
4220+ input : []cortexpb.LabelAdapter {{Name : "job" , Value : "test" }, {Name : "empty" , Value : "" }},
4221+ expected : []cortexpb.LabelAdapter {{Name : "job" , Value : "test" }},
4222+ },
4223+ {
4224+ name : "multiple empty labels - removes all empty ones" ,
4225+ input : []cortexpb.LabelAdapter {{Name : "empty1" , Value : "" }, {Name : "job" , Value : "test" }, {Name : "empty2" , Value : "" }},
4226+ expected : []cortexpb.LabelAdapter {{Name : "job" , Value : "test" }},
4227+ },
4228+ }
4229+
4230+ for _ , tt := range tests {
4231+ t .Run (tt .name , func (t * testing.T ) {
4232+ // Make a copy of the input to avoid modifying the original
4233+ input := make ([]cortexpb.LabelAdapter , len (tt .input ))
4234+ copy (input , tt .input )
4235+
4236+ removeEmptyLabels (& input )
4237+ assert .Equal (t , tt .expected , input )
4238+ })
4239+ }
4240+ }
4241+
41954242func TestDistributor_Push_EmptyLabel (t * testing.T ) {
41964243 t .Parallel ()
41974244 ctx := user .InjectOrgID (context .Background (), "pushEmptyLabel" )
@@ -4255,6 +4302,10 @@ func TestDistributor_Push_EmptyLabel(t *testing.T) {
42554302 timeseries := ingesters [i ].series ()
42564303 if len (timeseries ) > 0 {
42574304 ingesterWithSeries ++
4305+ // Assert on the expected series
4306+ for _ , v := range timeseries {
4307+ assert .Equal (t , tc .expectedSeries , cortexpb .FromLabelAdaptersToLabels (v .Labels ))
4308+ }
42584309 }
42594310 }
42604311 assert .Equal (t , 1 , ingesterWithSeries )
0 commit comments