mirror of
https://github.com/prometheus/prometheus.git
synced 2025-08-06 06:07:11 +02:00
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:
parent
19848bb445
commit
94d5e0f41c
@ -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()))
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user