Skip to content

Commit 03f8c97

Browse files
feat: support experimental PromQL features (#297)
Signed-off-by: Simon Pasquier <[email protected]>
1 parent 88fdd42 commit 03f8c97

File tree

2 files changed

+25
-16
lines changed

2 files changed

+25
-16
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
## Unreleased
22

3-
* [ENHANCEMENT] Add the `-enable-label-matchers-for-rules-api` flag to filter rules using label matchers. #xxx
3+
* [ENHANCEMENT] Add the `-enable-promql-duration-expression-parsing` flag to support arithmetic for durations in PromQL expressions. #297
4+
* [ENHANCEMENT] Add the `-enable-promql-experimental-functions` flag to support experimental functions in PromQL expressions. #297
5+
* [ENHANCEMENT] Add the `-enable-label-matchers-for-rules-api` flag to filter rules using label matchers. #295
46

57
## 0.11.1 / 2025-05-12
68

main.go

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131
"github.com/oklog/run"
3232
"github.com/prometheus/client_golang/prometheus"
3333
"github.com/prometheus/client_golang/prometheus/collectors"
34+
"github.com/prometheus/prometheus/promql/parser"
3435

3536
"github.com/prometheus-community/prom-label-proxy/injectproxy"
3637
)
@@ -55,20 +56,22 @@ func (i *arrayFlags) Set(value string) error {
5556

5657
func main() {
5758
var (
58-
insecureListenAddress string
59-
internalListenAddress string
60-
upstream string
61-
queryParam string
62-
headerName string
63-
label string
64-
labelValues arrayFlags
65-
enableLabelAPIs bool
66-
unsafePassthroughPaths string // Comma-delimited string.
67-
errorOnReplace bool
68-
regexMatch bool
69-
headerUsesListSyntax bool
70-
rulesWithActiveAlerts bool
71-
labelMatchersForRulesAPI bool
59+
insecureListenAddress string
60+
internalListenAddress string
61+
upstream string
62+
queryParam string
63+
headerName string
64+
label string
65+
labelValues arrayFlags
66+
enableLabelAPIs bool
67+
unsafePassthroughPaths string // Comma-delimited string.
68+
errorOnReplace bool
69+
regexMatch bool
70+
headerUsesListSyntax bool
71+
rulesWithActiveAlerts bool
72+
labelMatchersForRulesAPI bool
73+
promQLDurationExpressionParsing bool
74+
promQLExperimentalFunctions bool
7275
)
7376

7477
flagset := flag.NewFlagSet(os.Args[0], flag.ExitOnError)
@@ -90,6 +93,8 @@ func main() {
9093
flagset.BoolVar(&headerUsesListSyntax, "header-uses-list-syntax", false, "When specified, the header line value will be parsed as a comma-separated list. This allows a single tenant header line to specify multiple tenant names.")
9194
flagset.BoolVar(&rulesWithActiveAlerts, "rules-with-active-alerts", false, "When true, the proxy will return alerting rules with active alerts matching the tenant label even when the tenant label isn't present in the rule's labels.")
9295
flagset.BoolVar(&labelMatchersForRulesAPI, "enable-label-matchers-for-rules-api", false, "When true, the proxy uses label matchers when querying the /api/v1/rules endpoint. NOTE: Enable with care because filtering by label matcher is not implemented in older versions of Prometheus (>= 2.54.0 required) and Thanos (>= v0.25.0 required). If not implemented by upstream, the response will not be filtered accordingly.")
96+
flagset.BoolVar(&promQLDurationExpressionParsing, "enable-promql-duration-expression-parsing", false, "When true, the proxy supports arithmetic for durations in PromQL expressions.")
97+
flagset.BoolVar(&promQLExperimentalFunctions, "enable-promql-experimental-functions", false, "When true, the proxy supports experimental functions in PromQL expressions.")
9398

9499
//nolint: errcheck // Parse() will exit on error.
95100
flagset.Parse(os.Args[1:])
@@ -176,8 +181,10 @@ func main() {
176181
extractLabeler = injectproxy.HTTPHeaderEnforcer{Name: http.CanonicalHeaderKey(headerName), ParseListSyntax: headerUsesListSyntax}
177182
}
178183

179-
var g run.Group
184+
parser.ExperimentalDurationExpr = promQLDurationExpressionParsing
185+
parser.EnableExperimentalFunctions = promQLExperimentalFunctions
180186

187+
var g run.Group
181188
{
182189
// Run the insecure HTTP server.
183190
routes, err := injectproxy.NewRoutes(upstreamURL, label, extractLabeler, opts...)

0 commit comments

Comments
 (0)