From 1ef361bc45efc93aafa99a1b6f2aa1ee9a448082 Mon Sep 17 00:00:00 2001 From: Arthur Silva Sens Date: Thu, 29 May 2025 15:26:34 -0300 Subject: [PATCH] Address comments Signed-off-by: Arthur Silva Sens --- promql/engine.go | 4 ++-- promql/engine_test.go | 4 ++-- util/annotations/annotations.go | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/promql/engine.go b/promql/engine.go index c2ab025ab5..1e01f21db6 100644 --- a/promql/engine.go +++ b/promql/engine.go @@ -1901,8 +1901,8 @@ func (ev *evaluator) eval(ctx context.Context, expr parser.Expr) (parser.Value, if ev.enableTypeAndUnitLabels { // When type-and-unit-labels feature is enabled, check __type__ label typeLabel := inMatrix[0].Metric.Get("__type__") - if typeLabel != "counter" { - warnings.Add(annotations.NewPossibleNonCounterLabelInfo(metricName, e.Args[0].PositionRange())) + if typeLabel != string(model.MetricTypeCounter) { + warnings.Add(annotations.NewPossibleNonCounterLabelInfo(metricName, typeLabel, e.Args[0].PositionRange())) } } else if !strings.HasSuffix(metricName, "_total") || !strings.HasSuffix(metricName, "_sum") || diff --git a/promql/engine_test.go b/promql/engine_test.go index 0c882bfa8d..cbb1cbcecc 100644 --- a/promql/engine_test.go +++ b/promql/engine_test.go @@ -3503,7 +3503,7 @@ func TestRateAnnotations(t *testing.T) { expr: "rate(series[1m1s])", typeAndUnitLabelsEnabled: true, expectedInfoAnnotations: []string{ - `PromQL info: metric might not be a counter, __type__ label is not set to "counter": "series" (1:6)`, + `PromQL info: metric might not be a counter, __type__ label is not set to "counter", got "": "series" (1:6)`, }, expectedWarningAnnotations: []string{}, }, @@ -3514,7 +3514,7 @@ func TestRateAnnotations(t *testing.T) { expr: "increase(series[1m1s])", typeAndUnitLabelsEnabled: true, expectedInfoAnnotations: []string{ - `PromQL info: metric might not be a counter, __type__ label is not set to "counter": "series" (1:10)`, + `PromQL info: metric might not be a counter, __type__ label is not set to "counter", got "": "series" (1:10)`, }, expectedWarningAnnotations: []string{}, }, diff --git a/util/annotations/annotations.go b/util/annotations/annotations.go index d35edf4500..1b3f9e2ff2 100644 --- a/util/annotations/annotations.go +++ b/util/annotations/annotations.go @@ -147,7 +147,7 @@ var ( IncompatibleBucketLayoutInBinOpWarning = fmt.Errorf("%w: incompatible bucket layout encountered for binary operator", PromQLWarning) PossibleNonCounterInfo = fmt.Errorf("%w: metric might not be a counter, name does not end in _total/_sum/_count/_bucket:", PromQLInfo) - PossibleNonCounterLabelInfo = fmt.Errorf("%w: metric might not be a counter, __type__ label is not set to %q:", PromQLInfo, "counter") + PossibleNonCounterLabelInfo = fmt.Errorf("%w: metric might not be a counter, __type__ label is not set to %q", PromQLInfo, model.MetricTypeCounter) 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) IncompatibleTypesInBinOpInfo = fmt.Errorf("%w: incompatible sample types encountered for binary operator", PromQLInfo) HistogramIgnoredInAggregationInfo = fmt.Errorf("%w: ignored histogram in", PromQLInfo) @@ -273,10 +273,10 @@ func NewPossibleNonCounterInfo(metricName string, pos posrange.PositionRange) er // NewPossibleNonCounterLabelInfo is used when a named counter metric with only float samples does not // have the __type__ label set to "counter". -func NewPossibleNonCounterLabelInfo(metricName string, pos posrange.PositionRange) error { +func NewPossibleNonCounterLabelInfo(metricName, typeLabel string, pos posrange.PositionRange) error { return annoErr{ PositionRange: pos, - Err: fmt.Errorf("%w %q", PossibleNonCounterLabelInfo, metricName), + Err: fmt.Errorf("%w, got %q: %q", PossibleNonCounterLabelInfo, typeLabel, metricName), } }