mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
(prometheus) refactor time calculation
This commit is contained in:
parent
3077f992bb
commit
d9fe41cc8d
@ -62,8 +62,8 @@ export function PrometheusDatasource(instanceSettings, $q, backendSrv, templateS
|
||||
// Called once per panel (graph)
|
||||
this.query = function(options) {
|
||||
var self = this;
|
||||
var start = getPrometheusTime(options.range.from, false);
|
||||
var end = getPrometheusTime(options.range.to, true);
|
||||
var start = this.getPrometheusTime(options.range.from, false);
|
||||
var end = this.getPrometheusTime(options.range.to, true);
|
||||
|
||||
var queries = [];
|
||||
var activeTargets = [];
|
||||
@ -172,8 +172,8 @@ export function PrometheusDatasource(instanceSettings, $q, backendSrv, templateS
|
||||
step: '60s'
|
||||
};
|
||||
|
||||
var start = getPrometheusTime(options.range.from, false);
|
||||
var end = getPrometheusTime(options.range.to, true);
|
||||
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) {
|
||||
@ -279,10 +279,10 @@ export function PrometheusDatasource(instanceSettings, $q, backendSrv, templateS
|
||||
return metricName + '{' + labelPart + '}';
|
||||
};
|
||||
|
||||
function getPrometheusTime(date, roundUp): number {
|
||||
this.getPrometheusTime = function(date, roundUp) {
|
||||
if (_.isString(date)) {
|
||||
date = dateMath.parse(date, roundUp);
|
||||
}
|
||||
return Math.ceil(date.valueOf() / 1000);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -51,9 +51,11 @@ function (_) {
|
||||
});
|
||||
});
|
||||
} else {
|
||||
var start = this.datasource.getPrometheusTime(this.range.from, false);
|
||||
var end = this.datasource.getPrometheusTime(this.range.to, true);
|
||||
url = '/api/v1/series?match[]=' + encodeURIComponent(metric)
|
||||
+ '&start=' + (this.range.from.valueOf() / 1000)
|
||||
+ '&end=' + (this.range.to.valueOf() / 1000);
|
||||
+ '&start=' + start
|
||||
+ '&end=' + end;
|
||||
|
||||
return this.datasource._request('GET', url)
|
||||
.then(function(result) {
|
||||
@ -88,7 +90,8 @@ function (_) {
|
||||
};
|
||||
|
||||
PrometheusMetricFindQuery.prototype.queryResultQuery = function(query) {
|
||||
var url = '/api/v1/query?query=' + encodeURIComponent(query) + '&time=' + (this.range.to.valueOf() / 1000);
|
||||
var end = this.datasource.getPrometheusTime(this.range.to, true);
|
||||
var url = '/api/v1/query?query=' + encodeURIComponent(query) + '&time=' + end;
|
||||
|
||||
return this.datasource._request('GET', url)
|
||||
.then(function(result) {
|
||||
@ -109,9 +112,11 @@ function (_) {
|
||||
};
|
||||
|
||||
PrometheusMetricFindQuery.prototype.metricNameAndLabelsQuery = function(query) {
|
||||
var start = this.datasource.getPrometheusTime(this.range.from, false);
|
||||
var end = this.datasource.getPrometheusTime(this.range.to, true);
|
||||
var url = '/api/v1/series?match[]=' + encodeURIComponent(query)
|
||||
+ '&start=' + (this.range.from.valueOf() / 1000)
|
||||
+ '&end=' + (this.range.to.valueOf() / 1000);
|
||||
+ '&start=' + start
|
||||
+ '&end=' + end;
|
||||
|
||||
var self = this;
|
||||
return this.datasource._request('GET', url)
|
||||
|
Loading…
Reference in New Issue
Block a user