From fb163450a5a980cc3344edd103d55ae9620f7953 Mon Sep 17 00:00:00 2001 From: Ivan Babrou Date: Fri, 14 Apr 2017 05:51:22 -0700 Subject: [PATCH] Change prometheus semantics from step to min step (#8073) Previously `Step` parameter would set a hard value for any zoom level. Now it's renamed to `Min step` and sets the minimal value of `step` parameter to Prometheus query. User would usually want to set it to the scraping interval of the target metric to avoid having shap cliffs on graphs and extra load on Prometheus. Actual `step` value is calculated as the minimum of automatically selected step (based on zoom level) and user provided minimal step. If user did not provide the step, then automatic value is used as is. Example bahavior for `60s` scrape intervals: * `5s` automatic interval, no user specified min step: * Before: `step=5` * After: `step=5` * `5s` automatic interval, `1m` user specified min step: * Before: `step=5` * After: `step=60` * `5m` automatic interval, `1m` user specified min step: * Before: `step=60` (not really visible, too dense) * After: `step=300` (automatic value is picked) See: * https://github.com/grafana/grafana/issues/8065 * https://github.com/prometheus/prometheus/issues/2564 --- CHANGELOG.md | 1 + .../plugins/datasource/prometheus/datasource.ts | 14 +++++++++----- .../prometheus/partials/query.editor.html | 2 +- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5c32dcdba40..128abbb1662 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ ## Minor Enchancements * **Prometheus**: Make Prometheus query field a textarea [#7663](https://github.com/grafana/grafana/issues/7663), thx [@hagen1778](https://github.com/hagen1778) +* **Prometheus**: Step parameter changed semantics to min step to reduce the load on Prometheus and rendering in browser [#8073](https://github.com/grafana/grafana/pull/8073), thx [@bobrik](https://github.com/bobrik) * **Templating**: Should not be possible to create self-referencing (recursive) template variable definitions [#7614](https://github.com/grafana/grafana/issues/7614) thx [@thuck](https://github.com/thuck) * **Cloudwatch**: Correctly obtain IAM roles within ECS container tasks [#7892](https://github.com/grafana/grafana/issues/7892) thx [@gomlgs](https://github.com/gomlgs) * **Units**: New number format: Scientific notation [#7781](https://github.com/grafana/grafana/issues/7781) thx [@cadnce](https://github.com/cadnce) diff --git a/public/app/plugins/datasource/prometheus/datasource.ts b/public/app/plugins/datasource/prometheus/datasource.ts index f883b40e5ee..3cd065719c7 100644 --- a/public/app/plugins/datasource/prometheus/datasource.ts +++ b/public/app/plugins/datasource/prometheus/datasource.ts @@ -89,7 +89,7 @@ export function PrometheusDatasource(instanceSettings, $q, backendSrv, templateS var intervalFactor = target.intervalFactor || 1; target.step = query.step = this.calculateInterval(interval, intervalFactor); var range = Math.ceil(end - start); - target.step = query.step = this.adjustStep(query.step, range); + target.step = query.step = this.adjustStep(query.step, this.intervalSeconds(options.interval), range); queries.push(query); }); @@ -122,13 +122,13 @@ export function PrometheusDatasource(instanceSettings, $q, backendSrv, templateS }); }; - this.adjustStep = function(step, range) { + this.adjustStep = function(step, autoStep, range) { // Prometheus drop query if range/step > 11000 // calibrate step if it is too big if (step !== 0 && range / step > 11000) { return Math.ceil(range / 11000); } - return step; + return Math.max(step, autoStep); }; this.performTimeSeriesQuery = function(query, start, end) { @@ -189,7 +189,7 @@ export function PrometheusDatasource(instanceSettings, $q, backendSrv, templateS var end = this.getPrometheusTime(options.range.to, true); var query = { expr: interpolated, - step: this.adjustStep(kbn.interval_to_seconds(step), Math.ceil(end - start)) + 's' + step: this.adjustStep(kbn.interval_to_seconds(step), 0, Math.ceil(end - start)) + 's' }; var self = this; @@ -229,6 +229,10 @@ export function PrometheusDatasource(instanceSettings, $q, backendSrv, templateS }; this.calculateInterval = function(interval, intervalFactor) { + return Math.ceil(this.intervalSeconds(interval) * intervalFactor); + }; + + this.intervalSeconds = function(interval) { var m = interval.match(durationSplitRegexp); var dur = moment.duration(parseInt(m[1]), m[2]); var sec = dur.asSeconds(); @@ -236,7 +240,7 @@ export function PrometheusDatasource(instanceSettings, $q, backendSrv, templateS sec = 1; } - return Math.ceil(sec * intervalFactor); + return sec; }; this.transformMetricData = function(md, options, start, end) { diff --git a/public/app/plugins/datasource/prometheus/partials/query.editor.html b/public/app/plugins/datasource/prometheus/partials/query.editor.html index 1840f74bd74..98bb359a093 100644 --- a/public/app/plugins/datasource/prometheus/partials/query.editor.html +++ b/public/app/plugins/datasource/prometheus/partials/query.editor.html @@ -14,7 +14,7 @@
- +