Skip to content

Commit 8be416a

Browse files
[FIX] PromQL: Updates annotation for bin op between incompatible histograms (prometheus#15895)
PromQL: Updates annotation for bin op between incompatible histograms --------- Signed-off-by: Neeraj Gartia <neerajgartia211002@gmail.com>
1 parent 130cd02 commit 8be416a

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

promql/engine.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3475,15 +3475,14 @@ func handleVectorBinopError(err error, e *parser.BinaryExpr) annotations.Annotat
34753475
if err == nil {
34763476
return nil
34773477
}
3478-
metricName := ""
3478+
op := parser.ItemTypeStr[e.Op]
34793479
pos := e.PositionRange()
34803480
if errors.Is(err, annotations.PromQLInfo) || errors.Is(err, annotations.PromQLWarning) {
34813481
return annotations.New().Add(err)
34823482
}
3483-
if errors.Is(err, histogram.ErrHistogramsIncompatibleSchema) {
3484-
return annotations.New().Add(annotations.NewMixedExponentialCustomHistogramsWarning(metricName, pos))
3485-
} else if errors.Is(err, histogram.ErrHistogramsIncompatibleBounds) {
3486-
return annotations.New().Add(annotations.NewIncompatibleCustomBucketsHistogramsWarning(metricName, pos))
3483+
// TODO(NeerajGartia21): Test the exact annotation output once the testing framework can do so.
3484+
if errors.Is(err, histogram.ErrHistogramsIncompatibleSchema) || errors.Is(err, histogram.ErrHistogramsIncompatibleBounds) {
3485+
return annotations.New().Add(annotations.NewIncompatibleBucketLayoutInBinOpWarning(op, pos))
34873486
}
34883487
return nil
34893488
}

util/annotations/annotations.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ var (
143143
NativeHistogramNotGaugeWarning = fmt.Errorf("%w: this native histogram metric is not a gauge:", PromQLWarning)
144144
MixedExponentialCustomHistogramsWarning = fmt.Errorf("%w: vector contains a mix of histograms with exponential and custom buckets schemas for metric name", PromQLWarning)
145145
IncompatibleCustomBucketsHistogramsWarning = fmt.Errorf("%w: vector contains histograms with incompatible custom buckets for metric name", PromQLWarning)
146+
IncompatibleBucketLayoutInBinOpWarning = fmt.Errorf("%w: incompatible bucket layout encountered for binary operator", PromQLWarning)
146147

147148
PossibleNonCounterInfo = fmt.Errorf("%w: metric might not be a counter, name does not end in _total/_sum/_count/_bucket:", PromQLInfo)
148149
HistogramQuantileForcedMonotonicityInfo = fmt.Errorf("%w: input to histogram_quantile needed to be fixed for monotonicity (see https://prometheus.io/docs/prometheus/latest/querying/functions/#histogram_quantile) for metric name", PromQLInfo)
@@ -295,9 +296,20 @@ func NewHistogramIgnoredInAggregationInfo(aggregation string, pos posrange.Posit
295296
}
296297
}
297298

299+
// NewHistogramIgnoredInMixedRangeInfo is used when a histogram is ignored
300+
// in a range vector which contains mix of floats and histograms.
298301
func NewHistogramIgnoredInMixedRangeInfo(metricName string, pos posrange.PositionRange) error {
299302
return annoErr{
300303
PositionRange: pos,
301304
Err: fmt.Errorf("%w %q", HistogramIgnoredInMixedRangeInfo, metricName),
302305
}
303306
}
307+
308+
// NewIncompatibleBucketLayoutInBinOpWarning is used if binary operators act on a
309+
// combination of two incompatible histograms.
310+
func NewIncompatibleBucketLayoutInBinOpWarning(operator string, pos posrange.PositionRange) error {
311+
return annoErr{
312+
PositionRange: pos,
313+
Err: fmt.Errorf("%w %s", IncompatibleBucketLayoutInBinOpWarning, operator),
314+
}
315+
}

0 commit comments

Comments
 (0)