Просмотр исходного кода

(prometheus) adjust annotation step (#7768)

* (prometheus) adjust annotation step

* (prometheus) add step option
Mitsuhiro Tanda 8 лет назад
Родитель
Сommit
be123a07c5

+ 19 - 10
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 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 = {
       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;
-
     return this.performTimeSeriesQuery(query, start, end).then(function(results) {
       var eventList = [];
       tagKeys = tagKeys.split(',');

+ 5 - 2
public/app/plugins/datasource/prometheus/partials/annotations.editor.html

@@ -1,9 +1,12 @@
-
-<h5 class="section-heading">Search expression</h6>
 <div class="gf-form-group">
 	<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>
 	</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 class="gf-form-group">