From bc7c2cd3f5ce78fa91865973f6510cbefc3fd880 Mon Sep 17 00:00:00 2001 From: stuart nelson Date: Thu, 9 Jun 2016 11:36:46 +0200 Subject: [PATCH] Create cacheKey at top-level Responsibility is now to pass the cacheKey through to `datasourceRequest` in each datasources' implementation of `query`. --- public/app/features/panel/metrics_panel_ctrl.ts | 4 ++++ public/app/plugins/datasource/prometheus/datasource.ts | 5 +++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/public/app/features/panel/metrics_panel_ctrl.ts b/public/app/features/panel/metrics_panel_ctrl.ts index d3805d5f44f..e20df095d22 100644 --- a/public/app/features/panel/metrics_panel_ctrl.ts +++ b/public/app/features/panel/metrics_panel_ctrl.ts @@ -182,6 +182,10 @@ class MetricsPanelCtrl extends PanelCtrl { cacheTimeout: this.panel.cacheTimeout }; + metricsQuery.targets.forEach(function(target) { + target.cacheKey = target.expr + target.refId + metricsQuery.panelId; + }); + return datasource.query(metricsQuery); } diff --git a/public/app/plugins/datasource/prometheus/datasource.ts b/public/app/plugins/datasource/prometheus/datasource.ts index d4231c4867d..295ea05bb8f 100644 --- a/public/app/plugins/datasource/prometheus/datasource.ts +++ b/public/app/plugins/datasource/prometheus/datasource.ts @@ -25,7 +25,7 @@ export function PrometheusDatasource(instanceSettings, $q, backendSrv, templateS var options: any = { url: this.url + url, method: method, - cacheKey: cacheKey + cacheKey: cacheKey, }; if (this.basicAuth || this.withCredentials) { @@ -76,6 +76,7 @@ export function PrometheusDatasource(instanceSettings, $q, backendSrv, templateS var query: any = {}; query.expr = templateSrv.replace(target.expr, options.scopedVars, self.interpolateQueryExpr); + query.cacheKey = target.cacheKey; var interval = target.interval || options.interval; var intervalFactor = target.intervalFactor || 1; @@ -123,7 +124,7 @@ export function PrometheusDatasource(instanceSettings, $q, backendSrv, templateS this.performTimeSeriesQuery = function(query, start, end) { 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) {