Skip to content
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

Bug 1908717: Monitoring Dashboards: Add support for $__rate_interval variable #7651

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 9 additions & 8 deletions frontend/public/components/monitoring/dashboards/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,17 @@ const evaluateTemplate = (s: string, variables: VariablesMap, timespan: number):
if (_.isEmpty(s)) {
return undefined;
}
let result = s;
// Handle the special `$__interval` variable.
// https://grafana.com/docs/grafana/latest/reference/templating/#the-interval-variable

// Handle the special `$__interval` and `$__rate_interval` variables
const intervalMS = timespan / NUM_SAMPLES;
const intervalMinutes = Math.floor(intervalMS / 1000 / 60);
// Use a minimum of 5m to make sure we have enough data to perform `irate`
// calculations, which require 2 data points each. Otherwise, there could be
// gaps in the graph.
const __interval: Variable = { value: `${Math.max(intervalMinutes, 5)}m` };
_.each({ ...variables, __interval }, (v, k) => {
// Use a minimum of 5m to make sure we have enough data to perform `irate` calculations, which
// require 2 data points each. Otherwise, there could be gaps in the graph.
const interval: Variable = { value: `${Math.max(intervalMinutes, 5)}m` };

let result = s;
// eslint-disable-next-line camelcase
_.each({ ...variables, __interval: interval, __rate_interval: interval }, (v, k) => {
const re = new RegExp(`\\$${k}`, 'g');
if (result.match(re)) {
if (v.isLoading) {
Expand Down