@@ -1188,7 +1188,7 @@ func (d *Distributor) ForReplicationSet(ctx context.Context, replicationSet ring
1188
1188
})
1189
1189
}
1190
1190
1191
- func (d * Distributor ) LabelValuesForLabelNameCommon (ctx context.Context , from , to model.Time , labelName model.LabelName , hints * storage.LabelHints , f func (ctx context.Context , rs ring.ReplicationSet , req * ingester_client.LabelValuesRequest ) ([]interface {}, error ), matchers ... * labels.Matcher ) ([]string , error ) {
1191
+ func (d * Distributor ) LabelValuesForLabelNameCommon (ctx context.Context , from , to model.Time , labelName model.LabelName , hints * storage.LabelHints , f func (ctx context.Context , rs ring.ReplicationSet , req * ingester_client.LabelValuesRequest , limiter * limiter. QueryLimiter ) ([]interface {}, error ), matchers ... * labels.Matcher ) ([]string , error ) {
1192
1192
span , ctx := opentracing .StartSpanFromContext (ctx , "Distributor.LabelValues" , opentracing.Tags {
1193
1193
"name" : labelName ,
1194
1194
"start" : from .Unix (),
@@ -1205,7 +1205,8 @@ func (d *Distributor) LabelValuesForLabelNameCommon(ctx context.Context, from, t
1205
1205
return nil , err
1206
1206
}
1207
1207
1208
- resps , err := f (ctx , replicationSet , req )
1208
+ queryLimiter := limiter .QueryLimiterFromContextWithFallback (ctx )
1209
+ resps , err := f (ctx , replicationSet , req , queryLimiter )
1209
1210
if err != nil {
1210
1211
return nil , err
1211
1212
}
@@ -1229,20 +1230,23 @@ func (d *Distributor) LabelValuesForLabelNameCommon(ctx context.Context, from, t
1229
1230
1230
1231
// LabelValuesForLabelName returns all the label values that are associated with a given label name.
1231
1232
func (d * Distributor ) LabelValuesForLabelName (ctx context.Context , from , to model.Time , labelName model.LabelName , hint * storage.LabelHints , partialDataEnabled bool , matchers ... * labels.Matcher ) ([]string , error ) {
1232
- return d .LabelValuesForLabelNameCommon (ctx , from , to , labelName , hint , func (ctx context.Context , rs ring.ReplicationSet , req * ingester_client.LabelValuesRequest ) ([]interface {}, error ) {
1233
+ return d .LabelValuesForLabelNameCommon (ctx , from , to , labelName , hint , func (ctx context.Context , rs ring.ReplicationSet , req * ingester_client.LabelValuesRequest , queryLimiter * limiter. QueryLimiter ) ([]interface {}, error ) {
1233
1234
return d .ForReplicationSet (ctx , rs , d .cfg .ZoneResultsQuorumMetadata , partialDataEnabled , func (ctx context.Context , client ingester_client.IngesterClient ) (interface {}, error ) {
1234
1235
resp , err := client .LabelValues (ctx , req )
1235
1236
if err != nil {
1236
1237
return nil , err
1237
1238
}
1239
+ if err := queryLimiter .AddDataBytes (resp .Size ()); err != nil {
1240
+ return nil , validation .LimitError (err .Error ())
1241
+ }
1238
1242
return resp .LabelValues , nil
1239
1243
})
1240
1244
}, matchers ... )
1241
1245
}
1242
1246
1243
1247
// LabelValuesForLabelNameStream returns all the label values that are associated with a given label name.
1244
1248
func (d * Distributor ) LabelValuesForLabelNameStream (ctx context.Context , from , to model.Time , labelName model.LabelName , hint * storage.LabelHints , partialDataEnabled bool , matchers ... * labels.Matcher ) ([]string , error ) {
1245
- return d .LabelValuesForLabelNameCommon (ctx , from , to , labelName , hint , func (ctx context.Context , rs ring.ReplicationSet , req * ingester_client.LabelValuesRequest ) ([]interface {}, error ) {
1249
+ return d .LabelValuesForLabelNameCommon (ctx , from , to , labelName , hint , func (ctx context.Context , rs ring.ReplicationSet , req * ingester_client.LabelValuesRequest , queryLimiter * limiter. QueryLimiter ) ([]interface {}, error ) {
1246
1250
return d .ForReplicationSet (ctx , rs , d .cfg .ZoneResultsQuorumMetadata , partialDataEnabled , func (ctx context.Context , client ingester_client.IngesterClient ) (interface {}, error ) {
1247
1251
stream , err := client .LabelValuesStream (ctx , req )
1248
1252
if err != nil {
@@ -1252,12 +1256,15 @@ func (d *Distributor) LabelValuesForLabelNameStream(ctx context.Context, from, t
1252
1256
allLabelValues := []string {}
1253
1257
for {
1254
1258
resp , err := stream .Recv ()
1255
-
1256
1259
if err == io .EOF {
1257
1260
break
1258
1261
} else if err != nil {
1259
1262
return nil , err
1260
1263
}
1264
+ if err := queryLimiter .AddDataBytes (resp .Size ()); err != nil {
1265
+ return nil , validation .LimitError (err .Error ())
1266
+ }
1267
+
1261
1268
allLabelValues = append (allLabelValues , resp .LabelValues ... )
1262
1269
}
1263
1270
@@ -1266,7 +1273,7 @@ func (d *Distributor) LabelValuesForLabelNameStream(ctx context.Context, from, t
1266
1273
}, matchers ... )
1267
1274
}
1268
1275
1269
- func (d * Distributor ) LabelNamesCommon (ctx context.Context , from , to model.Time , hints * storage.LabelHints , f func (ctx context.Context , rs ring.ReplicationSet , req * ingester_client.LabelNamesRequest ) ([]interface {}, error ), matchers ... * labels.Matcher ) ([]string , error ) {
1276
+ func (d * Distributor ) LabelNamesCommon (ctx context.Context , from , to model.Time , hints * storage.LabelHints , f func (ctx context.Context , rs ring.ReplicationSet , req * ingester_client.LabelNamesRequest , limiter * limiter. QueryLimiter ) ([]interface {}, error ), matchers ... * labels.Matcher ) ([]string , error ) {
1270
1277
span , ctx := opentracing .StartSpanFromContext (ctx , "Distributor.LabelNames" , opentracing.Tags {
1271
1278
"start" : from .Unix (),
1272
1279
"end" : to .Unix (),
@@ -1283,7 +1290,8 @@ func (d *Distributor) LabelNamesCommon(ctx context.Context, from, to model.Time,
1283
1290
return nil , err
1284
1291
}
1285
1292
1286
- resps , err := f (ctx , replicationSet , req )
1293
+ queryLimiter := limiter .QueryLimiterFromContextWithFallback (ctx )
1294
+ resps , err := f (ctx , replicationSet , req , queryLimiter )
1287
1295
if err != nil {
1288
1296
return nil , err
1289
1297
}
@@ -1308,7 +1316,7 @@ func (d *Distributor) LabelNamesCommon(ctx context.Context, from, to model.Time,
1308
1316
}
1309
1317
1310
1318
func (d * Distributor ) LabelNamesStream (ctx context.Context , from , to model.Time , hints * storage.LabelHints , partialDataEnabled bool , matchers ... * labels.Matcher ) ([]string , error ) {
1311
- return d .LabelNamesCommon (ctx , from , to , hints , func (ctx context.Context , rs ring.ReplicationSet , req * ingester_client.LabelNamesRequest ) ([]interface {}, error ) {
1319
+ return d .LabelNamesCommon (ctx , from , to , hints , func (ctx context.Context , rs ring.ReplicationSet , req * ingester_client.LabelNamesRequest , queryLimiter * limiter. QueryLimiter ) ([]interface {}, error ) {
1312
1320
return d .ForReplicationSet (ctx , rs , d .cfg .ZoneResultsQuorumMetadata , partialDataEnabled , func (ctx context.Context , client ingester_client.IngesterClient ) (interface {}, error ) {
1313
1321
stream , err := client .LabelNamesStream (ctx , req )
1314
1322
if err != nil {
@@ -1318,12 +1326,15 @@ func (d *Distributor) LabelNamesStream(ctx context.Context, from, to model.Time,
1318
1326
allLabelNames := []string {}
1319
1327
for {
1320
1328
resp , err := stream .Recv ()
1321
-
1322
1329
if err == io .EOF {
1323
1330
break
1324
1331
} else if err != nil {
1325
1332
return nil , err
1326
1333
}
1334
+ if err := queryLimiter .AddDataBytes (resp .Size ()); err != nil {
1335
+ return nil , validation .LimitError (err .Error ())
1336
+ }
1337
+
1327
1338
allLabelNames = append (allLabelNames , resp .LabelNames ... )
1328
1339
}
1329
1340
@@ -1334,12 +1345,16 @@ func (d *Distributor) LabelNamesStream(ctx context.Context, from, to model.Time,
1334
1345
1335
1346
// LabelNames returns all the label names.
1336
1347
func (d * Distributor ) LabelNames (ctx context.Context , from , to model.Time , hint * storage.LabelHints , partialDataEnabled bool , matchers ... * labels.Matcher ) ([]string , error ) {
1337
- return d .LabelNamesCommon (ctx , from , to , hint , func (ctx context.Context , rs ring.ReplicationSet , req * ingester_client.LabelNamesRequest ) ([]interface {}, error ) {
1348
+ return d .LabelNamesCommon (ctx , from , to , hint , func (ctx context.Context , rs ring.ReplicationSet , req * ingester_client.LabelNamesRequest , queryLimiter * limiter. QueryLimiter ) ([]interface {}, error ) {
1338
1349
return d .ForReplicationSet (ctx , rs , d .cfg .ZoneResultsQuorumMetadata , partialDataEnabled , func (ctx context.Context , client ingester_client.IngesterClient ) (interface {}, error ) {
1339
1350
resp , err := client .LabelNames (ctx , req )
1340
1351
if err != nil {
1341
1352
return nil , err
1342
1353
}
1354
+ if err := queryLimiter .AddDataBytes (resp .Size ()); err != nil {
1355
+ return nil , validation .LimitError (err .Error ())
1356
+ }
1357
+
1343
1358
return resp .LabelNames , nil
1344
1359
})
1345
1360
}, matchers ... )
@@ -1385,15 +1400,15 @@ func (d *Distributor) MetricsForLabelMatchersStream(ctx context.Context, from, t
1385
1400
defer stream .CloseSend () //nolint:errcheck
1386
1401
for {
1387
1402
resp , err := stream .Recv ()
1388
- if err := queryLimiter .AddDataBytes (resp .Size ()); err != nil {
1389
- return nil , validation .LimitError (err .Error ())
1390
- }
1391
-
1392
1403
if err == io .EOF {
1393
1404
break
1394
1405
} else if err != nil {
1395
1406
return nil , err
1396
1407
}
1408
+ if err := queryLimiter .AddDataBytes (resp .Size ()); err != nil {
1409
+ return nil , validation .LimitError (err .Error ())
1410
+ }
1411
+
1397
1412
s := make ([][]cortexpb.LabelAdapter , 0 , len (resp .Metric ))
1398
1413
for _ , metric := range resp .Metric {
1399
1414
m := cortexpb .FromLabelAdaptersToMetricWithCopy (metric .Labels )
0 commit comments