Skip to content

Commit 2ef26ce

Browse files
authored
Fix use of old PromQL parser in rules lint (#55)
In #49, I introduced a bug that referenced the old PromQL parser. The legacy one is not compatible with the current one and thus fails to parse any of our current rules files.
1 parent fb550fa commit 2ef26ce

File tree

14 files changed

+11
-6762
lines changed

14 files changed

+11
-6762
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## unreleased / master
44

5+
* [BUGFIX] Fix usage of the old PromQL parser in `prepare lint`.
6+
57
## v0.2.1 / 2020-06-08
68

79
* [FEATURE] Add `rules check` command. It runs various [best practice](https://prometheus.io/docs/practices/rules/) checks against rules.

pkg/rules/rules.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"fmt"
55
"strings"
66

7-
promql "github.com/cortexproject/cortex/pkg/configs/legacy_promql"
87
rulefmt "github.com/cortexproject/cortex/pkg/ruler/legacy_rulefmt"
98
"github.com/prometheus/prometheus/promql/parser"
109
log "github.com/sirupsen/logrus"
@@ -30,7 +29,7 @@ func (r RuleNamespace) LintPromQLExpressions() (int, int, error) {
3029
for i, group := range r.Groups {
3130
for j, rule := range group.Rules {
3231
log.WithFields(log.Fields{"rule": getRuleName(rule)}).Debugf("linting PromQL")
33-
exp, err := promql.ParseExpr(rule.Expr)
32+
exp, err := parser.ParseExpr(rule.Expr)
3433
if err != nil {
3534
return count, mod, err
3635
}

pkg/rules/rules_test.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,12 +137,19 @@ func TestLintPromQLExpressions(t *testing.T) {
137137
count: 1, modified: 0,
138138
err: "",
139139
},
140+
{
141+
name: "with a complex expression",
142+
expr: `sum by(cluster, namespace) (sum_over_time((rate(loki_distributor_bytes_received_total{job=~".*/distributor"}[1m]) * 60)[1h:1m])) / 1e+09 / 5 * 1 > (sum by(cluster, namespace) (memcached_limit_bytes{job=~".+/memcached"}) / 1e+09)`,
143+
expected: `sum by(cluster, namespace) (sum_over_time((rate(loki_distributor_bytes_received_total{job=~".*/distributor"}[1m]) * 60)[1h:1m])) / 1e+09 / 5 * 1 > (sum by(cluster, namespace) (memcached_limit_bytes{job=~".+/memcached"}) / 1e+09)`,
144+
count: 1, modified: 0,
145+
err: "",
146+
},
140147
{
141148
name: "with an invalid expression",
142149
expr: "it fails",
143150
expected: "it fails",
144151
count: 0, modified: 0,
145-
err: "parse error at char 4: could not parse remaining input \"fails\"...",
152+
err: "1:4: parse error: unexpected identifier \"fails\"",
146153
},
147154
}
148155

vendor/github.com/cortexproject/cortex/pkg/configs/legacy_promql/ast.go

Lines changed: 0 additions & 341 deletions
This file was deleted.

0 commit comments

Comments
 (0)