Skip to content

Commit ade5796

Browse files
yeya24jnyi
authored andcommitted
Only increment ruler warning eval metric for non PromQL warnings (thanos-io#7592)
1 parent b60b55b commit ade5796

File tree

2 files changed

+84
-7
lines changed

2 files changed

+84
-7
lines changed

cmd/thanos/rule.go

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ import (
4040
"github.com/prometheus/prometheus/tsdb"
4141
"github.com/prometheus/prometheus/tsdb/agent"
4242
"github.com/prometheus/prometheus/tsdb/wlog"
43+
"gopkg.in/yaml.v2"
4344

4445
"github.com/thanos-io/objstore"
4546
"github.com/thanos-io/objstore/client"
4647
objstoretracing "github.com/thanos-io/objstore/tracing/opentracing"
4748
"github.com/thanos-io/promql-engine/execution/parse"
48-
"gopkg.in/yaml.v2"
4949

5050
"github.com/thanos-io/thanos/pkg/alert"
5151
v1 "github.com/thanos-io/thanos/pkg/api/rule"
@@ -54,6 +54,7 @@ import (
5454
"github.com/thanos-io/thanos/pkg/component"
5555
"github.com/thanos-io/thanos/pkg/discovery/dns"
5656
"github.com/thanos-io/thanos/pkg/errutil"
57+
"github.com/thanos-io/thanos/pkg/extannotations"
5758
"github.com/thanos-io/thanos/pkg/extgrpc"
5859
"github.com/thanos-io/thanos/pkg/extkingpin"
5960
"github.com/thanos-io/thanos/pkg/extprom"
@@ -292,7 +293,7 @@ func newRuleMetrics(reg *prometheus.Registry) *RuleMetrics {
292293
m.ruleEvalWarnings = factory.NewCounterVec(
293294
prometheus.CounterOpts{
294295
Name: "thanos_rule_evaluation_with_warnings_total",
295-
Help: "The total number of rule evaluation that were successful but had warnings which can indicate partial error.",
296+
Help: "The total number of rule evaluation that were successful but had non PromQL warnings which can indicate partial error.",
296297
}, []string{"strategy"},
297298
)
298299
m.ruleEvalWarnings.WithLabelValues(strings.ToLower(storepb.PartialResponseStrategy_ABORT.String()))
@@ -940,6 +941,8 @@ func queryFuncCreator(
940941
level.Error(logger).Log("err", err, "query", qs)
941942
continue
942943
}
944+
945+
warns = filterOutPromQLWarnings(warns, logger, qs)
943946
if len(warns) > 0 {
944947
ruleEvalWarnings.WithLabelValues(strings.ToLower(partialResponseStrategy.String())).Inc()
945948
// TODO(bwplotka): Propagate those to UI, probably requires changing rule manager code ):
@@ -971,12 +974,13 @@ func queryFuncCreator(
971974
continue
972975
}
973976

974-
if len(result.Warnings) > 0 {
977+
warnings := make([]string, 0, len(result.Warnings))
978+
for _, warn := range result.Warnings {
979+
warnings = append(warnings, warn.Error())
980+
}
981+
warnings = filterOutPromQLWarnings(warnings, logger, qs)
982+
if len(warnings) > 0 {
975983
ruleEvalWarnings.WithLabelValues(strings.ToLower(partialResponseStrategy.String())).Inc()
976-
warnings := make([]string, 0, len(result.Warnings))
977-
for _, w := range result.Warnings {
978-
warnings = append(warnings, w.Error())
979-
}
980984
level.Warn(logger).Log("warnings", strings.Join(warnings, ", "), "query", qs)
981985
}
982986

@@ -1082,3 +1086,16 @@ func validateTemplate(tmplStr string) error {
10821086
}
10831087
return nil
10841088
}
1089+
1090+
// Filter out PromQL related warnings from warning response and keep store related warnings only.
1091+
func filterOutPromQLWarnings(warns []string, logger log.Logger, query string) []string {
1092+
storeWarnings := make([]string, 0, len(warns))
1093+
for _, warn := range warns {
1094+
if extannotations.IsPromQLAnnotation(warn) {
1095+
level.Warn(logger).Log("warning", warn, "query", query)
1096+
continue
1097+
}
1098+
storeWarnings = append(storeWarnings, warn)
1099+
}
1100+
return storeWarnings
1101+
}

cmd/thanos/rule_test.go

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ import (
77
"testing"
88

99
"github.com/efficientgo/core/testutil"
10+
"github.com/go-kit/log"
11+
"github.com/prometheus/prometheus/util/annotations"
12+
13+
"github.com/thanos-io/thanos/pkg/extpromql"
1014
)
1115

1216
func Test_parseFlagLabels(t *testing.T) {
@@ -110,3 +114,59 @@ func Test_tableLinkForExpression(t *testing.T) {
110114
testutil.Equals(t, resStr, td.expectStr)
111115
}
112116
}
117+
118+
func TestFilterOutPromQLWarnings(t *testing.T) {
119+
logger := log.NewNopLogger()
120+
query := "foo"
121+
expr, err := extpromql.ParseExpr(`rate(prometheus_build_info[5m])`)
122+
testutil.Ok(t, err)
123+
possibleCounterInfo := annotations.NewPossibleNonCounterInfo("foo", expr.PositionRange())
124+
badBucketLabelWarning := annotations.NewBadBucketLabelWarning("foo", "0.99", expr.PositionRange())
125+
for _, tc := range []struct {
126+
name string
127+
warnings []string
128+
expected []string
129+
}{
130+
{
131+
name: "nil warning",
132+
expected: make([]string, 0),
133+
},
134+
{
135+
name: "empty warning",
136+
warnings: make([]string, 0),
137+
expected: make([]string, 0),
138+
},
139+
{
140+
name: "no PromQL warning",
141+
warnings: []string{
142+
"some_warning_message",
143+
},
144+
expected: []string{
145+
"some_warning_message",
146+
},
147+
},
148+
{
149+
name: "PromQL warning",
150+
warnings: []string{
151+
possibleCounterInfo.Error(),
152+
},
153+
expected: make([]string, 0),
154+
},
155+
{
156+
name: "filter out all PromQL warnings",
157+
warnings: []string{
158+
possibleCounterInfo.Error(),
159+
badBucketLabelWarning.Error(),
160+
"some_warning_message",
161+
},
162+
expected: []string{
163+
"some_warning_message",
164+
},
165+
},
166+
} {
167+
t.Run(tc.name, func(t *testing.T) {
168+
output := filterOutPromQLWarnings(tc.warnings, logger, query)
169+
testutil.Equals(t, tc.expected, output)
170+
})
171+
}
172+
}

0 commit comments

Comments
 (0)