engine: fix PossibleNonCounterInfo annotation for rate and increase. (#16718)

* Comment exposed field

Signed-off-by: Innokentii Konstantinov <innokenty.konstantinov@grafana.com>

* Remove invalid test

Signed-off-by: Innokentii Konstantinov <innokenty.konstantinov@grafana.com>

* Fix PossibleNonCounterInfo annotation.

Signed-off-by: Innokentii Konstantinov <innokenty.konstantinov@grafana.com>

* lint

Signed-off-by: Innokentii Konstantinov <innokenty.konstantinov@grafana.com>

---------

Signed-off-by: Innokentii Konstantinov <innokenty.konstantinov@grafana.com>
This commit is contained in:
Innokentii Konstantinov 2025-06-11 21:09:57 +08:00 committed by GitHub
parent 19848bb445
commit 94d5e0f41c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 75 additions and 3 deletions

View File

@ -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()))

View File

@ -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) {