diff --git a/promql/engine.go b/promql/engine.go index 3ea663e2f9..2d13accddc 100644 --- a/promql/engine.go +++ b/promql/engine.go @@ -1904,9 +1904,9 @@ func (ev *evaluator) eval(ctx context.Context, expr parser.Expr) (parser.Value, 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") || - !strings.HasSuffix(metricName, "_count") || + } else if !strings.HasSuffix(metricName, "_total") && + !strings.HasSuffix(metricName, "_sum") && + !strings.HasSuffix(metricName, "_count") && !strings.HasSuffix(metricName, "_bucket") { // Fallback to name suffix checking warnings.Add(annotations.NewPossibleNonCounterInfo(metricName, e.Args[0].PositionRange())) diff --git a/promql/engine_test.go b/promql/engine_test.go index 858c02d87f..f352d5999c 100644 --- a/promql/engine_test.go +++ b/promql/engine_test.go @@ -3537,6 +3537,78 @@ func TestRateAnnotations(t *testing.T) { expectedWarningAnnotations: []string{}, expectedInfoAnnotations: []string{}, }, + "no info annotation when rate() over series with _total suffix": { + data: ` + series_total{label="a"} 1 2 3 + `, + expr: "rate(series_total[1m1s])", + typeAndUnitLabelsEnabled: false, + expectedWarningAnnotations: []string{}, + expectedInfoAnnotations: []string{}, + }, + "no info annotation when rate() over series with _sum suffix": { + data: ` + series_sum{label="a"} 1 2 3 + `, + expr: "rate(series_sum[1m1s])", + typeAndUnitLabelsEnabled: false, + expectedWarningAnnotations: []string{}, + expectedInfoAnnotations: []string{}, + }, + "no info annotation when rate() over series with _count suffix": { + data: ` + series_count{label="a"} 1 2 3 + `, + expr: "rate(series_count[1m1s])", + typeAndUnitLabelsEnabled: false, + expectedWarningAnnotations: []string{}, + expectedInfoAnnotations: []string{}, + }, + "no info annotation when rate() over series with _bucket suffix": { + data: ` + series_bucket{label="a"} 1 2 3 + `, + expr: "rate(series_bucket[1m1s])", + typeAndUnitLabelsEnabled: false, + expectedWarningAnnotations: []string{}, + expectedInfoAnnotations: []string{}, + }, + "no info annotation when increase() over series with _total suffix": { + data: ` + series_total{label="a"} 1 2 3 + `, + expr: "increase(series_total[1m1s])", + expectedWarningAnnotations: []string{}, + typeAndUnitLabelsEnabled: false, + expectedInfoAnnotations: []string{}, + }, + "no info annotation when increase() over series with _sum suffix": { + data: ` + series_sum{label="a"} 1 2 3 + `, + expr: "increase(series_sum[1m1s])", + typeAndUnitLabelsEnabled: false, + expectedWarningAnnotations: []string{}, + expectedInfoAnnotations: []string{}, + }, + "no info annotation when increase() over series with _count suffix": { + data: ` + series_count{label="a"} 1 2 3 + `, + expr: "increase(series_count[1m1s])", + typeAndUnitLabelsEnabled: false, + expectedWarningAnnotations: []string{}, + expectedInfoAnnotations: []string{}, + }, + "no info annotation when increase() over series with _bucket suffix": { + data: ` + series_bucket{label="a"} 1 2 3 + `, + expr: "increase(series_bucket[1m1s])", + typeAndUnitLabelsEnabled: false, + expectedWarningAnnotations: []string{}, + expectedInfoAnnotations: []string{}, + }, } for name, testCase := range testCases { t.Run(name, func(t *testing.T) {