@@ -1102,17 +1102,6 @@ func TestDistributor_Push_LabelRemoval(t *testing.T) {
1102
1102
{Name : "__name__" , Value : "some_metric" },
1103
1103
},
1104
1104
},
1105
- // Edge case: remove label __name__ will drop all user metrics
1106
- {
1107
- removeReplica : true ,
1108
- removeLabels : []string {"__name__" },
1109
- inputSeries : labels.Labels {
1110
- {Name : "__name__" , Value : "some_metric" },
1111
- {Name : "cluster" , Value : "one" },
1112
- {Name : "__replica__" , Value : "two" },
1113
- },
1114
- expectedSeries : labels.Labels {},
1115
- },
1116
1105
// Remove multiple labels and replica.
1117
1106
{
1118
1107
removeReplica : true ,
@@ -1165,22 +1154,59 @@ func TestDistributor_Push_LabelRemoval(t *testing.T) {
1165
1154
_ , err = ds [0 ].Push (ctx , req )
1166
1155
require .NoError (t , err )
1167
1156
1168
- expectedTimeseriesLen := 0
1169
- if len (tc .expectedSeries ) > 0 {
1170
- expectedTimeseriesLen = 1
1171
- }
1172
1157
// Since each test pushes only 1 series, we do expect the ingester
1173
1158
// to have received exactly 1 series
1174
1159
for i := range ingesters {
1175
1160
timeseries := ingesters [i ].series ()
1176
- assert .Equal (t , expectedTimeseriesLen , len (timeseries ))
1161
+ assert .Equal (t , 1 , len (timeseries ))
1177
1162
for _ , v := range timeseries {
1178
1163
assert .Equal (t , tc .expectedSeries , cortexpb .FromLabelAdaptersToLabels (v .Labels ))
1179
1164
}
1180
1165
}
1181
1166
}
1182
1167
}
1183
1168
1169
+ func TestDistributor_Push_LabelRemoval_RemovingNameLabelWillError (t * testing.T ) {
1170
+ ctx := user .InjectOrgID (context .Background (), "user" )
1171
+ type testcase struct {
1172
+ inputSeries labels.Labels
1173
+ expectedSeries labels.Labels
1174
+ removeReplica bool
1175
+ removeLabels []string
1176
+ }
1177
+
1178
+ tc := testcase {
1179
+ removeReplica : true ,
1180
+ removeLabels : []string {"__name__" },
1181
+ inputSeries : labels.Labels {
1182
+ {Name : "__name__" , Value : "some_metric" },
1183
+ {Name : "cluster" , Value : "one" },
1184
+ {Name : "__replica__" , Value : "two" },
1185
+ },
1186
+ expectedSeries : labels.Labels {},
1187
+ }
1188
+
1189
+ var err error
1190
+ var limits validation.Limits
1191
+ flagext .DefaultValues (& limits )
1192
+ limits .DropLabels = tc .removeLabels
1193
+ limits .AcceptHASamples = tc .removeReplica
1194
+
1195
+ ds , _ , _ := prepare (t , prepConfig {
1196
+ numIngesters : 2 ,
1197
+ happyIngesters : 2 ,
1198
+ numDistributors : 1 ,
1199
+ shardByAllLabels : true ,
1200
+ limits : & limits ,
1201
+ })
1202
+
1203
+ // Push the series to the distributor
1204
+ req := mockWriteRequest ([]labels.Labels {tc .inputSeries }, 1 , 1 )
1205
+ _ , err = ds [0 ].Push (ctx , req )
1206
+ require .Error (t , err )
1207
+ assert .Equal (t , "rpc error: code = Code(400) desc = sample missing metric name" , err .Error ())
1208
+ }
1209
+
1184
1210
func TestDistributor_Push_ShouldGuaranteeShardingTokenConsistencyOverTheTime (t * testing.T ) {
1185
1211
ctx := user .InjectOrgID (context .Background (), "user" )
1186
1212
tests := map [string ]struct {
0 commit comments