-
Notifications
You must be signed in to change notification settings - Fork 12.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prometheus: Fix $__rate_interval calculation #77234
Conversation
Additional information:
|
@gouthamve @beorn7 @davkal Can I get feedback, please? I provided a chart and tested various scenarios. I hope those will give some more insight into this proposed change. |
I still think that taking So we should re-instate the old "right" behavior, which this PR seems to do. There is the special case where |
@beorn7 If |
Hrm, I see. So we are using min step as an override for the scrape interval. While I don't think we should use the option like that, I also don't see a better alternative. Lets go ahead with this PR. Sorry for the confusion. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
We would appreciate if the author /someone familiar with the code backport this to 9.4.x ? |
The backport to
To backport manually, run these commands in your terminal: # Fetch latest updates from GitHub
git fetch
# Create a new branch
git switch --create backport-77234-to-v10.2.x origin/v10.2.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x b607a4e0a2ee2a9b368c6ebcf4021249768b347e When the conflicts are resolved, stage and commit the changes:
If you have the GitHub CLI installed: # Push the branch to GitHub:
git push --set-upstream origin backport-77234-to-v10.2.x
# Create the PR body template
PR_BODY=$(gh pr view 77234 --json body --template 'Backport b607a4e0a2ee2a9b368c6ebcf4021249768b347e from #77234{{ "\n\n---\n\n" }}{{ index . "body" }}')
# Create the PR on GitHub
echo "${PR_BODY}" | gh pr create --title "[v10.2.x] Prometheus: Fix $__rate_interval calculation" --body-file - --label "type/bug" --label "datasource/Prometheus" --label "area/backend" --label "add to changelog" --label "product-approved" --label "backport" --base v10.2.x --milestone 10.2.x --web Or, if you don't have the GitHub CLI installed (we recommend you install it!): # Push the branch to GitHub:
git push --set-upstream origin backport-77234-to-v10.2.x
# Create a pull request where the `base` branch is `v10.2.x` and the `compare`/`head` branch is `backport-77234-to-v10.2.x`.
# Remove the local backport branch
git switch main
git branch -D backport-77234-to-v10.2.x |
* Remove unused param * simple unit test * rename * rename * add some comments * Update values * refactor * rename * always calculate rate interval * fix unit tests * Fix indentation * linter fix * update test * Fixing issues with the calculation * new test * fix $__interval interpolation * fix test * add comment (cherry picked from commit b607a4e)
Prometheus: Fix $__rate_interval calculation (#77234) * Remove unused param * simple unit test * rename * rename * add some comments * Update values * refactor * rename * always calculate rate interval * fix unit tests * Fix indentation * linter fix * update test * Fixing issues with the calculation * new test * fix $__interval interpolation * fix test * add comment (cherry picked from commit b607a4e) Co-authored-by: ismail simsek <[email protected]>
Background Information
$__rate_interval
calculation is explained here in detail.Shortly it is
max($__interval + Scrape interval, 4 * Scrape interval)
where Scrape interval is the “Min step” setting (also known as query*interval, a setting per PromQL query) if any is set. Otherwise, Grafana uses the Prometheus data source’s “Scrape interval” setting.Why we need that in the first place is explained here in this beautiful blog post.
$__interval
calculation is explained here.For all data sources, we have a
Min Interval
value. The default value of this is15s
or you can set it differently in data source settings. To be able to interpolate$__interval
we also sendintervalMs
. This is always the millisecond value ofInterval
in the panel below.Last 2 Days time range
In the Prometheus query editor, we also have
Min Step
for queries.Users might want to override
Min Interval
orMin Step
.Min Interval
setting has precedence over the scrape interval as set in the data source.Min Step
setting has precedence over theMin Interval
.Backend receives that as
interval
. This can be seen inQuery Inspector
.So let's use the values below as example.
Based on the documentation let's put the values in the equation and find the
$__rate_interval
value.So this should give the value as 600s. And the
step
value we send to Prometheus should be150s => 2m30s
. Let's see it in the query inspector:As you can see something is not quite right. So this PR is fixing it. Let's switch to this branch and run our query again.
Who is this feature for?
Prometheus users
Special notes for your reviewer:
Please check that: