Skip to content

Commit

Permalink
Unit test for ruler not honoring user error
Browse files Browse the repository at this point in the history
Added new test case in TestRulerMetricsForInvalidQueriesAndNoFetchedSeries
with only the invalid query scenario where the user has entered an
invalid regex, but without selecting all chunks so the chunks limit
doesn't apply.

Since only one error happens, the error is of type errors.errorString
and not fmt.wrapError, which means the code to detect user errors and
cannot type assert to type QueryableError which in turn means it's treated
as a GRPC error, which it is not.
See https://github.com/grafana/mimir/blob/fdf381290fba868d18762c9790ebf543f49d4cc7/pkg/ruler/compat.go#L164

Signed-off-by: György Krajcsovits <gyorgy.krajcsovits@grafana.com>
  • Loading branch information
krajorama committed Mar 8, 2024
1 parent e0a86e6 commit 3ad0c9f
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion integration/ruler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -644,10 +644,14 @@ func TestRulerMetricsForInvalidQueriesAndNoFetchedSeries(t *testing.T) {
// Verify that user-failures don't increase cortex_ruler_queries_failed_total
for groupName, expression := range map[string]string{
// Syntactically correct expression (passes check in ruler), but failing because of invalid regex. This fails in PromQL engine.
"invalid_group": `label_replace(metric, "foo", "$1", "service", "[")`,
// This selects the label "nolabel" which does not exist, thus too many chunks doesn't apply.
"invalid_group": `label_replace(metric{nolabel="none"}, "foo", "$1", "service", "[")`,

// This one fails in querier code, because of limits.
"too_many_chunks_group": `sum(metric)`,

// Combine the errors above to have a componed error.
"invalid_and_too_many_chunks_group": `label_replace(metric, "foo", "$1", "service", "[")`,
} {
t.Run(groupName, func(t *testing.T) {
addNewRuleAndWait(groupName, expression, true)
Expand Down

0 comments on commit 3ad0c9f

Please sign in to comment.