Skip to content

Commit 4383499

Browse files
authored
promtool: support missing promql syntax features (prometheus#17926)
Namely promql-duration-expr and promql-extended-range-selectors. This allows promtool to e.g. check rules files using syntax gated by these features. Signed-off-by: Ian Kerins <git@isk.haus>
1 parent 1dcdb07 commit 4383499

4 files changed

Lines changed: 13 additions & 5 deletions

File tree

cmd/promtool/main.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ func main() {
314314
promQLLabelsDeleteQuery := promQLLabelsDeleteCmd.Arg("query", "PromQL query.").Required().String()
315315
promQLLabelsDeleteName := promQLLabelsDeleteCmd.Arg("name", "Name of the label to delete.").Required().String()
316316

317-
featureList := app.Flag("enable-feature", "Comma separated feature names to enable. Valid options: promql-experimental-functions, promql-delayed-name-removal. See https://prometheus.io/docs/prometheus/latest/feature_flags/ for more details").Default("").Strings()
317+
featureList := app.Flag("enable-feature", "Comma separated feature names to enable. Valid options: promql-experimental-functions, promql-delayed-name-removal, promql-duration-expr, promql-extended-range-selectors. See https://prometheus.io/docs/prometheus/latest/feature_flags/ for more details").Default("").Strings()
318318

319319
documentationCmd := app.Command("write-documentation", "Generate command line documentation. Internal use.").Hidden()
320320

@@ -351,6 +351,10 @@ func main() {
351351
parser.EnableExperimentalFunctions = true
352352
case "promql-delayed-name-removal":
353353
promqlEnableDelayedNameRemoval = true
354+
case "promql-duration-expr":
355+
parser.ExperimentalDurationExpr = true
356+
case "promql-extended-range-selectors":
357+
parser.EnableExtendedRangeSelectors = true
354358
case "":
355359
continue
356360
default:

cmd/promtool/main_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,7 @@ func TestCheckRulesWithFeatureFlag(t *testing.T) {
655655
// As opposed to TestCheckRules calling CheckRules directly we run promtool
656656
// so the feature flag parsing can be tested.
657657

658-
args := []string{"-test.main", "--enable-feature=promql-experimental-functions", "check", "rules", "testdata/features.yml"}
658+
args := []string{"-test.main", "--enable-feature=promql-experimental-functions", "--enable-feature=promql-duration-expr", "--enable-feature=promql-extended-range-selectors", "check", "rules", "testdata/features.yml"}
659659
tool := exec.Command(promtoolPath, args...)
660660
err := tool.Run()
661661
require.NoError(t, err)

cmd/promtool/testdata/features.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
groups:
22
- name: features
33
rules:
4-
- record: x
5-
# We don't expect anything from this, just want to check the function parses.
4+
# We don't expect anything from these, just want to check the syntax parses.
5+
- record: promql-experimental-functions
66
expr: sort_by_label(up, "instance")
7+
- record: promql-duration-expr
8+
expr: rate(up[1m * 2])
9+
- record: promql-extended-range-selectors
10+
expr: rate(up[1m] anchored)

docs/command-line/promtool.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Tooling for the Prometheus monitoring system.
1212
| <code class="text-nowrap">-h</code>, <code class="text-nowrap">--help</code> | Show context-sensitive help (also try --help-long and --help-man). |
1313
| <code class="text-nowrap">--version</code> | Show application version. |
1414
| <code class="text-nowrap">--experimental</code> | Enable experimental commands. |
15-
| <code class="text-nowrap">--enable-feature</code> <code class="text-nowrap">...<code class="text-nowrap"> | Comma separated feature names to enable. Valid options: promql-experimental-functions, promql-delayed-name-removal. See https://prometheus.io/docs/prometheus/latest/feature_flags/ for more details |
15+
| <code class="text-nowrap">--enable-feature</code> <code class="text-nowrap">...<code class="text-nowrap"> | Comma separated feature names to enable. Valid options: promql-experimental-functions, promql-delayed-name-removal, promql-duration-expr, promql-extended-range-selectors. See https://prometheus.io/docs/prometheus/latest/feature_flags/ for more details |
1616

1717

1818

0 commit comments

Comments
 (0)