Skip to content

Commit fd6dae6

Browse files
committed
Update metrics API to use new PromQL parser interface
1 parent e00f0dc commit fd6dae6

2 files changed

Lines changed: 4 additions & 3 deletions

File tree

api/metrics/v1/labels_enforcer.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111

1212
"github.com/prometheus-community/prom-label-proxy/injectproxy"
1313
"github.com/prometheus/prometheus/model/labels"
14-
"github.com/prometheus/prometheus/promql/parser"
1514

1615
"github.com/observatorium/api/authentication"
1716
"github.com/observatorium/api/authorization"
@@ -148,7 +147,7 @@ func enforceQueryValues(e *injectproxy.PromQLEnforcer, paramName string, request
148147

149148
matchers := requestParams[paramName]
150149
for i, rawMatcher := range matchers {
151-
expr, err := parser.ParseExpr(rawMatcher)
150+
expr, err := promQLParser.ParseExpr(rawMatcher)
152151
if err != nil {
153152
return "", true, fmt.Errorf("parse expr error: %w", err)
154153
}

api/metrics/v1/rules.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import (
1818
"github.com/observatorium/api/rules"
1919
)
2020

21+
var promQLParser = parser.NewParser(parser.Options{})
22+
2123
func enforceLabelsInRules(rawRules rules.Rules, tenantLabel, tenantID string) error {
2224
// creates new tenant label enforcer
2325
e := injectproxy.NewPromQLEnforcer(false, []*labels.Matcher{{
@@ -82,7 +84,7 @@ func enforceLabelsInRules(rawRules rules.Rules, tenantLabel, tenantID string) er
8284
}
8385

8486
func enforceLabelsInExpr(e *injectproxy.PromQLEnforcer, expr string) (string, error) {
85-
parsedExpr, err := parser.ParseExpr(expr)
87+
parsedExpr, err := promQLParser.ParseExpr(expr)
8688
if err != nil {
8789
return "", fmt.Errorf("parse expr error: %w", err)
8890
}

0 commit comments

Comments
 (0)