@@ -303,7 +303,7 @@ func (o *ObjectivesServer) ListObjectives(ctx context.Context, query string) (op
303
303
}, nil
304
304
}
305
305
306
- func (o * ObjectivesServer ) GetObjectiveStatus (ctx context.Context , expr string ) (openapiserver.ImplResponse , error ) {
306
+ func (o * ObjectivesServer ) GetObjectiveStatus (ctx context.Context , expr string , grouping string ) (openapiserver.ImplResponse , error ) {
307
307
clientObjectives , _ , err := o .apiclient .ObjectivesApi .ListObjectives (ctx ).Expr (expr ).Execute ()
308
308
if err != nil {
309
309
var apiErr openapiclient.GenericOpenAPIError
@@ -320,6 +320,26 @@ func (o *ObjectivesServer) GetObjectiveStatus(ctx context.Context, expr string)
320
320
321
321
objective := openapi .InternalFromClient (clientObjectives [0 ])
322
322
323
+ // Merge grouping into objective's query
324
+ if grouping != "" {
325
+ groupingMatchers , err := parser .ParseMetricSelector (grouping )
326
+ if err != nil {
327
+ return openapiserver.ImplResponse {}, err
328
+ }
329
+ if objective .Indicator .Ratio != nil {
330
+ for _ , m := range groupingMatchers {
331
+ objective .Indicator .Ratio .Errors .LabelMatchers = append (objective .Indicator .Ratio .Errors .LabelMatchers , m )
332
+ objective .Indicator .Ratio .Total .LabelMatchers = append (objective .Indicator .Ratio .Total .LabelMatchers , m )
333
+ }
334
+ }
335
+ if objective .Indicator .Latency != nil {
336
+ for _ , m := range groupingMatchers {
337
+ objective .Indicator .Latency .Success .LabelMatchers = append (objective .Indicator .Latency .Success .LabelMatchers , m )
338
+ objective .Indicator .Latency .Total .LabelMatchers = append (objective .Indicator .Latency .Total .LabelMatchers , m )
339
+ }
340
+ }
341
+ }
342
+
323
343
ts := RoundUp (time .Now ().UTC (), 5 * time .Minute )
324
344
325
345
queryTotal := objective .QueryTotal (objective .Window )
@@ -403,15 +423,37 @@ func (o *ObjectivesServer) GetObjectiveErrorBudget(ctx context.Context, expr str
403
423
return openapiserver.ImplResponse {}, err
404
424
}
405
425
if objective .Indicator .Ratio != nil {
426
+ groupings := map [string ]struct {}{}
427
+ for _ , g := range objective .Indicator .Ratio .Grouping {
428
+ groupings [g ] = struct {}{}
429
+ }
430
+
406
431
for _ , m := range groupingMatchers {
407
432
objective .Indicator .Ratio .Errors .LabelMatchers = append (objective .Indicator .Ratio .Errors .LabelMatchers , m )
408
433
objective .Indicator .Ratio .Total .LabelMatchers = append (objective .Indicator .Ratio .Total .LabelMatchers , m )
434
+ delete (groupings , m .Name )
435
+ }
436
+
437
+ objective .Indicator .Ratio .Grouping = []string {}
438
+ for g := range groupings {
439
+ objective .Indicator .Ratio .Grouping = append (objective .Indicator .Ratio .Grouping , g )
409
440
}
410
441
}
411
442
if objective .Indicator .Latency != nil {
443
+ groupings := map [string ]struct {}{}
444
+ for _ , g := range objective .Indicator .Ratio .Grouping {
445
+ groupings [g ] = struct {}{}
446
+ }
447
+
412
448
for _ , m := range groupingMatchers {
413
449
objective .Indicator .Latency .Success .LabelMatchers = append (objective .Indicator .Latency .Success .LabelMatchers , m )
414
450
objective .Indicator .Latency .Total .LabelMatchers = append (objective .Indicator .Latency .Total .LabelMatchers , m )
451
+ delete (groupings , m .Name )
452
+ }
453
+
454
+ objective .Indicator .Ratio .Grouping = []string {}
455
+ for g := range groupings {
456
+ objective .Indicator .Ratio .Grouping = append (objective .Indicator .Ratio .Grouping , g )
415
457
}
416
458
}
417
459
}
@@ -443,10 +485,6 @@ func (o *ObjectivesServer) GetObjectiveErrorBudget(ctx context.Context, expr str
443
485
return openapiserver.ImplResponse {Code : http .StatusInternalServerError }, fmt .Errorf ("no matrix returned" )
444
486
}
445
487
446
- //if len(matrix) != 1 {
447
- // return openapiserver.ImplResponse{Code: http.StatusNotFound}, fmt.Errorf("no data")
448
- //}
449
-
450
488
if len (matrix ) == 0 {
451
489
return openapiserver.ImplResponse {Code : http .StatusNotFound }, fmt .Errorf ("no data" )
452
490
}
@@ -487,6 +525,31 @@ func (o *ObjectivesServer) GetMultiBurnrateAlerts(ctx context.Context, expr stri
487
525
488
526
objective := openapi .InternalFromClient (clientObjectives [0 ])
489
527
528
+ // Merge grouping into objective's query
529
+ if grouping != "" {
530
+ groupingMatchers , err := parser .ParseMetricSelector (grouping )
531
+ if err != nil {
532
+ return openapiserver.ImplResponse {}, err
533
+ }
534
+
535
+ if objective .Indicator .Ratio != nil {
536
+ objective .Indicator .Ratio .Grouping = nil // Don't group by here
537
+
538
+ for _ , m := range groupingMatchers {
539
+ objective .Indicator .Ratio .Errors .LabelMatchers = append (objective .Indicator .Ratio .Errors .LabelMatchers , m )
540
+ objective .Indicator .Ratio .Total .LabelMatchers = append (objective .Indicator .Ratio .Total .LabelMatchers , m )
541
+ }
542
+ }
543
+ if objective .Indicator .Latency != nil {
544
+ objective .Indicator .Latency .Grouping = nil // Don't group by here
545
+
546
+ for _ , m := range groupingMatchers {
547
+ objective .Indicator .Latency .Success .LabelMatchers = append (objective .Indicator .Latency .Success .LabelMatchers , m )
548
+ objective .Indicator .Latency .Total .LabelMatchers = append (objective .Indicator .Latency .Total .LabelMatchers , m )
549
+ }
550
+ }
551
+ }
552
+
490
553
baseAlerts , err := objective .Alerts ()
491
554
if err != nil {
492
555
return openapiserver.ImplResponse {Code : http .StatusInternalServerError }, err
0 commit comments