@@ -308,13 +308,13 @@ func (o *vectorOperator) execBinaryUnless(lhs, rhs model.StepVector) (model.Step
308
308
return step , nil
309
309
}
310
310
311
- func (o * vectorOperator ) computeBinaryPairing (hval , lval float64 , hlhs , hrhs * histogram.FloatHistogram , annos * annotations.Annotations ) (float64 , * histogram.FloatHistogram , bool , error ) {
311
+ func (o * vectorOperator ) computeBinaryPairing (ctx context. Context , hval , lval float64 , hlhs , hrhs * histogram.FloatHistogram , annos * annotations.Annotations ) (float64 , * histogram.FloatHistogram , bool , error ) {
312
312
// operand is not commutative so we need to address potential swapping
313
313
if o .matching .Card == parser .CardOneToMany {
314
- v , h , keep , err := vectorElemBinop (o .opType , lval , hval , hlhs , hrhs , annos )
314
+ v , h , keep , err := vectorElemBinop (ctx , o .opType , lval , hval , hlhs , hrhs , annos )
315
315
return v , h , keep , err
316
316
}
317
- v , h , keep , err := vectorElemBinop (o .opType , hval , lval , hlhs , hrhs , annos )
317
+ v , h , keep , err := vectorElemBinop (ctx , o .opType , hval , lval , hlhs , hrhs , annos )
318
318
return v , h , keep , err
319
319
}
320
320
@@ -380,9 +380,9 @@ func (o *vectorOperator) execBinaryArithmetic(ctx context.Context, lhs, rhs mode
380
380
jp .bts = ts
381
381
382
382
if jp .histogramVal != nil {
383
- _ , h , keep , err = o .computeBinaryPairing (0 , 0 , hcs .Histograms [i ], jp .histogramVal , & annos )
383
+ _ , h , keep , err = o .computeBinaryPairing (ctx , 0 , 0 , hcs .Histograms [i ], jp .histogramVal , & annos )
384
384
} else {
385
- _ , h , keep , err = o .computeBinaryPairing (0 , jp .val , hcs .Histograms [i ], nil , & annos )
385
+ _ , h , keep , err = o .computeBinaryPairing (ctx , 0 , jp .val , hcs .Histograms [i ], nil , & annos )
386
386
}
387
387
if countWarnings , countInfo := annos .CountWarningsAndInfo (); countWarnings > 0 || countInfo > 0 {
388
388
warnings .MergeToContext (annos , ctx )
@@ -423,7 +423,7 @@ func (o *vectorOperator) execBinaryArithmetic(ctx context.Context, lhs, rhs mode
423
423
var val float64
424
424
425
425
if jp .histogramVal != nil {
426
- _ , h , _ , err = o .computeBinaryPairing (hcs .Samples [i ], 0 , nil , jp .histogramVal , & annos )
426
+ _ , h , _ , err = o .computeBinaryPairing (ctx , hcs .Samples [i ], 0 , nil , jp .histogramVal , & annos )
427
427
if countWarnings , countInfo := annos .CountWarningsAndInfo (); countWarnings > 0 || countInfo > 0 {
428
428
warnings .MergeToContext (annos , ctx )
429
429
continue
@@ -433,7 +433,7 @@ func (o *vectorOperator) execBinaryArithmetic(ctx context.Context, lhs, rhs mode
433
433
}
434
434
step .AppendHistogram (o .pool , jp .sid , h )
435
435
} else {
436
- val , _ , keep , err = o .computeBinaryPairing (hcs .Samples [i ], jp .val , nil , nil , & annos )
436
+ val , _ , keep , err = o .computeBinaryPairing (ctx , hcs .Samples [i ], jp .val , nil , nil , & annos )
437
437
if countWarnings , countInfo := annos .CountWarningsAndInfo (); countWarnings > 0 || countInfo > 0 {
438
438
warnings .MergeToContext (annos , ctx )
439
439
continue
@@ -626,7 +626,7 @@ func signatureFunc(on bool, names ...string) func(labels.Labels) uint64 {
626
626
// Lifted from: https://github.com/prometheus/prometheus/blob/v3.1.0/promql/engine.go#L2797.
627
627
// nolint: unparam
628
628
// vectorElemBinop evaluates a binary operation between two Vector elements.
629
- func vectorElemBinop (op parser.ItemType , lhs , rhs float64 , hlhs , hrhs * histogram.FloatHistogram , annos * annotations.Annotations ) (float64 , * histogram.FloatHistogram , bool , error ) {
629
+ func vectorElemBinop (ctx context. Context , op parser.ItemType , lhs , rhs float64 , hlhs , hrhs * histogram.FloatHistogram , annos * annotations.Annotations ) (float64 , * histogram.FloatHistogram , bool , error ) {
630
630
opName := parser .ItemTypeStr [op ]
631
631
632
632
switch {
@@ -689,12 +689,26 @@ func vectorElemBinop(op parser.ItemType, lhs, rhs float64, hlhs, hrhs *histogram
689
689
case parser .ADD :
690
690
res , err := hlhs .Copy ().Add (hrhs )
691
691
if err != nil {
692
+ if errors .Is (err , histogram .ErrHistogramsIncompatibleSchema ) {
693
+ warnings .AddToContext (annotations .NewMixedExponentialCustomHistogramsWarning ("" , posrange.PositionRange {}), ctx )
694
+ return 0 , nil , false , nil
695
+ } else if errors .Is (err , histogram .ErrHistogramsIncompatibleBounds ) {
696
+ warnings .AddToContext (annotations .NewIncompatibleCustomBucketsHistogramsWarning ("" , posrange.PositionRange {}), ctx )
697
+ return 0 , nil , false , nil
698
+ }
692
699
return 0 , nil , false , err
693
700
}
694
701
return 0 , res .Compact (0 ), true , nil
695
702
case parser .SUB :
696
703
res , err := hlhs .Copy ().Sub (hrhs )
697
704
if err != nil {
705
+ if errors .Is (err , histogram .ErrHistogramsIncompatibleSchema ) {
706
+ warnings .AddToContext (annotations .NewMixedExponentialCustomHistogramsWarning ("" , posrange.PositionRange {}), ctx )
707
+ return 0 , nil , false , nil
708
+ } else if errors .Is (err , histogram .ErrHistogramsIncompatibleBounds ) {
709
+ warnings .AddToContext (annotations .NewIncompatibleCustomBucketsHistogramsWarning ("" , posrange.PositionRange {}), ctx )
710
+ return 0 , nil , false , nil
711
+ }
698
712
return 0 , nil , false , err
699
713
}
700
714
return 0 , res .Compact (0 ), true , nil
0 commit comments