Commit bc7c2cd3 by stuart nelson

Create cacheKey at top-level

Responsibility is now to pass the cacheKey through
to `datasourceRequest` in each datasources'
implementation of `query`.
parent 18f9f6c1
...@@ -182,6 +182,10 @@ class MetricsPanelCtrl extends PanelCtrl { ...@@ -182,6 +182,10 @@ class MetricsPanelCtrl extends PanelCtrl {
cacheTimeout: this.panel.cacheTimeout cacheTimeout: this.panel.cacheTimeout
}; };
metricsQuery.targets.forEach(function(target) {
target.cacheKey = target.expr + target.refId + metricsQuery.panelId;
});
return datasource.query(metricsQuery); return datasource.query(metricsQuery);
} }
......
...@@ -25,7 +25,7 @@ export function PrometheusDatasource(instanceSettings, $q, backendSrv, templateS ...@@ -25,7 +25,7 @@ export function PrometheusDatasource(instanceSettings, $q, backendSrv, templateS
var options: any = { var options: any = {
url: this.url + url, url: this.url + url,
method: method, method: method,
cacheKey: cacheKey cacheKey: cacheKey,
}; };
if (this.basicAuth || this.withCredentials) { if (this.basicAuth || this.withCredentials) {
...@@ -76,6 +76,7 @@ export function PrometheusDatasource(instanceSettings, $q, backendSrv, templateS ...@@ -76,6 +76,7 @@ export function PrometheusDatasource(instanceSettings, $q, backendSrv, templateS
var query: any = {}; var query: any = {};
query.expr = templateSrv.replace(target.expr, options.scopedVars, self.interpolateQueryExpr); query.expr = templateSrv.replace(target.expr, options.scopedVars, self.interpolateQueryExpr);
query.cacheKey = target.cacheKey;
var interval = target.interval || options.interval; var interval = target.interval || options.interval;
var intervalFactor = target.intervalFactor || 1; var intervalFactor = target.intervalFactor || 1;
...@@ -123,7 +124,7 @@ export function PrometheusDatasource(instanceSettings, $q, backendSrv, templateS ...@@ -123,7 +124,7 @@ export function PrometheusDatasource(instanceSettings, $q, backendSrv, templateS
this.performTimeSeriesQuery = function(query, start, end) { this.performTimeSeriesQuery = function(query, start, end) {
var url = '/api/v1/query_range?query=' + encodeURIComponent(query.expr) + '&start=' + start + '&end=' + end + '&step=' + query.step; var url = '/api/v1/query_range?query=' + encodeURIComponent(query.expr) + '&start=' + start + '&end=' + end + '&step=' + query.step;
return this._request('GET', url, query.expr.toString()); return this._request('GET', url, query.cacheKey);
}; };
this.performSuggestQuery = function(query) { this.performSuggestQuery = function(query) {
......
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