Repository navigation
[ENHANCEMENT] Prometheus: explain why $__rate_interval cannot be used as Min Step - #861
Merged
AntoineThebaud merged 1 commit intoOct 6, 2026
Conversation
… as Min Step Using $__rate_interval as the Min Step of a Prometheus query made the panel fail with "Invalid duration string '$__rate_interval'", which names neither the field nor the reason. $__interval, $__interval_ms and $__rate_interval are computed from the step, whose lower bound is the Min Step, so they cannot set it. The query now fails with: '$__rate_interval' cannot be used as Min Step, because its value depends on the Min Step. Leave Min Step empty to use the scrape interval of the datasource, or set a duration such as 30s. This is checked after the dashboard variables are resolved, so a variable whose value is one of them is caught too. The message then also names the Min Step, e.g. "Min Step '$res' resolves to '$__rate_interval', which cannot be used as Min Step, ...". Other invalid values now name the field and show the resolved value, e.g. "Invalid Min Step '$res' (resolved to 'abc'): expected a duration such as 30s or 5m". The accepted values do not change, and an empty Min Step (or a variable with an empty value) still falls back to the scrape interval of the datasource. The parsing moves to an internal helper, getMinStepSeconds, which resolves the TODO about validating the resolved value. The built-in variables section of the Prometheus docs now says that these variables cannot be used as Min Step. Closes perses/perses#2025 Signed-off-by: Raj Zalavadia <rzalavad@redhat.com>
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The focused change has regression coverage for improved errors and preserved behavior, with no unresolved findings.
Review effort: Balanced
Findings: None
What changed in this PR
Improves Prometheus Min Step errors without changing accepted values, fallback behavior, or query steps.
Changes:
- Adds an internal helper explaining unsupported built-in variables and invalid durations.
- Adds regression coverage for errors, variable resolution, and step behavior.
- Documents why step-dependent variables cannot set Min Step.
| File | Description |
|---|---|
| prometheus/src/plugins/prometheus-time-series-query/plugin.test.ts | Tests query errors and unchanged step behavior. |
| prometheus/src/plugins/prometheus-time-series-query/min-step.ts | Resolves Min Step variables and provides explicit errors. |
| prometheus/src/plugins/prometheus-time-series-query/min-step.test.ts | Tests validation messages and duration handling. |
| prometheus/src/plugins/prometheus-time-series-query/get-time-series-data.ts | Uses the new Min Step helper. |
| docs/prometheus/README.md | Explains the built-in variable restriction. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
AntoineThebaud
approved these changes
Oct 6, 2026
AntoineThebaud
left a comment
Contributor
There was a problem hiding this comment.
Thanks for addressing this long-standing issue 🙏
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Closes perses/perses#2025.
Using
$__rate_intervalas the Min Step of a Prometheus query breaks the panel withInvalid duration string '$__rate_interval', which names neither the field nor the reason. It is easy to end up there: the field accepts variables, and the Grafana migration copies theintervalof a query intominStep(migrate.cue).$__interval,$__interval_msand$__rate_intervalcannot work there: they are computed from the step, whose lower bound is the Min Step, and they are replaced only in the PromQL query. As proposed in the issue, this PR keeps the Perses behaviour and only makes the error explicit. (With$__rate_intervalas Min step, Grafana uses the rate interval itself as the step, see query.go. Perses has no such setting, so the message suggests the default of the field or a fixed duration.)A new internal helper,
getMinStepSeconds(min-step.ts, not exported from the package), resolves the dashboard variables and then checks the resolved value, which also removes theas DurationStringcast and its TODO. Each case below used to fail withInvalid duration string '<resolved value>':$__rate_intervalor${__rate_interval}'$__rate_interval' cannot be used as Min Step, because its value depends on the Min Step. Leave Min Step empty to use the scrape interval of the datasource, or set a duration such as 30s.$__interval,$__interval_ms'$__interval'or'$__interval_ms'$res, whereres=$__rate_intervalMin Step '$res' resolves to '$__rate_interval', which cannot be used as Min Step, because …(same end)30 sInvalid Min Step '30 s': expected a duration such as 30s or 5m$res, whereres=abcInvalid Min Step '$res' (resolved to 'abc'): expected a duration such as 30s or 5m0sstill sets no lower bound.get-time-series-data.ts, which [FEATURE] Prometheus: rangeQueryBatch client and getTimeSeriesDataBatch #839 also edits, only changes its imports and one statement.docs/prometheus/README.mdnow says that these built-in variables cannot be used to set the Min Step.Tests:
min-step.test.ts: each message, durations (0sgives 0), variables, the empty-variable fallback, and a check that every built-in variable of the datasource gets the message, so that a new one cannot be forgotten.plugin.test.ts, throughgetTimeSeriesData: the message for range and instant queries, with no request sent, and the unchanged step for a variable, an empty variable and0sin Min Step.Root
npm run lint,format:check,type-checkandtestpass with Node 24.19.0, with no new lint warnings, andmake checklicensepasses.Notes for reviewers:
dependsOnignores the variables used only in Min Step, so changing one of them does not re-run the query (nor does the query wait for it to load), and a Min Step error can stay on screen after the variable has changed. The fix changes the query keys, so it is left for a separate PR.get-time-series-data.tsthat parses the Min Step withgetDurationStringSeconds(replaceVariables(…) as DurationString). This PR removes thegetDurationStringSecondsandDurationStringimports from that file (replaceVariablesstays), so after a rebase that path should callgetMinStepSeconds(s.minStep, context.variableState) ?? datasourceScrapeInterval.Screenshots
No screenshot: only the error text changes (see the table above).
Checklist
[<catalog_entry>] <commit message>naming convention using one of thefollowing
catalog_entryvalues:FEATURE,ENHANCEMENT,BUGFIX,BREAKINGCHANGE,DOC,IGNORE.UI Changes