diff --git a/public/app/plugins/datasource/prometheus/datasource.ts b/public/app/plugins/datasource/prometheus/datasource.ts index 972fa2c7c55..f883b40e5ee 100644 --- a/public/app/plugins/datasource/prometheus/datasource.ts +++ b/public/app/plugins/datasource/prometheus/datasource.ts @@ -4,6 +4,7 @@ import angular from 'angular'; import _ from 'lodash'; import moment from 'moment'; +import kbn from 'app/core/utils/kbn'; import * as dateMath from 'app/core/utils/datemath'; import PrometheusMetricFindQuery from './metric_find_query'; @@ -88,12 +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); - // Prometheus drop query if range/step > 11000 - // calibrate step if it is too big - if (query.step !== 0 && range / query.step > 11000) { - target.step = query.step = Math.ceil(range / 11000); - } - + target.step = query.step = this.adjustStep(query.step, range); queries.push(query); }); @@ -126,6 +122,15 @@ export function PrometheusDatasource(instanceSettings, $q, backendSrv, templateS }); }; + this.adjustStep = function(step, 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; + }; + this.performTimeSeriesQuery = function(query, start, end) { if (start > end) { throw { message: 'Invalid time range' }; @@ -175,15 +180,19 @@ export function PrometheusDatasource(instanceSettings, $q, backendSrv, templateS return $q.reject(err); } - var query = { - expr: interpolated, - step: '60s' - }; + var step = '60s'; + if (annotation.step) { + step = templateSrv.replace(annotation.step); + } var start = this.getPrometheusTime(options.range.from, false); var end = this.getPrometheusTime(options.range.to, true); - var self = this; + var query = { + expr: interpolated, + step: this.adjustStep(kbn.interval_to_seconds(step), Math.ceil(end - start)) + 's' + }; + var self = this; return this.performTimeSeriesQuery(query, start, end).then(function(results) { var eventList = []; tagKeys = tagKeys.split(','); diff --git a/public/app/plugins/datasource/prometheus/partials/annotations.editor.html b/public/app/plugins/datasource/prometheus/partials/annotations.editor.html index 818aa42e886..09ee52bda45 100644 --- a/public/app/plugins/datasource/prometheus/partials/annotations.editor.html +++ b/public/app/plugins/datasource/prometheus/partials/annotations.editor.html @@ -1,9 +1,12 @@ - -