Commit be123a07 by Mitsuhiro Tanda Committed by Torkel Ödegaard

(prometheus) adjust annotation step (#7768)

* (prometheus) adjust annotation step

* (prometheus) add step option
parent 588955c7
...@@ -4,6 +4,7 @@ import angular from 'angular'; ...@@ -4,6 +4,7 @@ import angular from 'angular';
import _ from 'lodash'; import _ from 'lodash';
import moment from 'moment'; import moment from 'moment';
import kbn from 'app/core/utils/kbn';
import * as dateMath from 'app/core/utils/datemath'; import * as dateMath from 'app/core/utils/datemath';
import PrometheusMetricFindQuery from './metric_find_query'; import PrometheusMetricFindQuery from './metric_find_query';
...@@ -88,12 +89,7 @@ export function PrometheusDatasource(instanceSettings, $q, backendSrv, templateS ...@@ -88,12 +89,7 @@ export function PrometheusDatasource(instanceSettings, $q, backendSrv, templateS
var intervalFactor = target.intervalFactor || 1; var intervalFactor = target.intervalFactor || 1;
target.step = query.step = this.calculateInterval(interval, intervalFactor); target.step = query.step = this.calculateInterval(interval, intervalFactor);
var range = Math.ceil(end - start); var range = Math.ceil(end - start);
// Prometheus drop query if range/step > 11000 target.step = query.step = this.adjustStep(query.step, range);
// calibrate step if it is too big
if (query.step !== 0 && range / query.step > 11000) {
target.step = query.step = Math.ceil(range / 11000);
}
queries.push(query); queries.push(query);
}); });
...@@ -126,6 +122,15 @@ export function PrometheusDatasource(instanceSettings, $q, backendSrv, templateS ...@@ -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) { this.performTimeSeriesQuery = function(query, start, end) {
if (start > end) { if (start > end) {
throw { message: 'Invalid time range' }; throw { message: 'Invalid time range' };
...@@ -175,15 +180,19 @@ export function PrometheusDatasource(instanceSettings, $q, backendSrv, templateS ...@@ -175,15 +180,19 @@ export function PrometheusDatasource(instanceSettings, $q, backendSrv, templateS
return $q.reject(err); return $q.reject(err);
} }
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 query = { var query = {
expr: interpolated, expr: interpolated,
step: '60s' step: this.adjustStep(kbn.interval_to_seconds(step), Math.ceil(end - start)) + 's'
}; };
var start = this.getPrometheusTime(options.range.from, false);
var end = this.getPrometheusTime(options.range.to, true);
var self = this; var self = this;
return this.performTimeSeriesQuery(query, start, end).then(function(results) { return this.performTimeSeriesQuery(query, start, end).then(function(results) {
var eventList = []; var eventList = [];
tagKeys = tagKeys.split(','); tagKeys = tagKeys.split(',');
......
<h5 class="section-heading">Search expression</h6>
<div class="gf-form-group"> <div class="gf-form-group">
<div class="gf-form"> <div class="gf-form">
<span class="gf-form-label width-10">Search expression</span>
<input type="text" class="gf-form-input" ng-model='ctrl.annotation.expr' placeholder="ALERTS"></input> <input type="text" class="gf-form-input" ng-model='ctrl.annotation.expr' placeholder="ALERTS"></input>
</div> </div>
<div class="gf-form">
<span class="gf-form-label width-10">step</span>
<input type="text" class="gf-form-input max-width-6" ng-model='ctrl.annotation.step' placeholder="60s"></input>
</div>
</div> </div>
<div class="gf-form-group"> <div class="gf-form-group">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment