From 74fcb2494a32507e5ab1a7ba2b6733daca8a1955 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Thu, 26 Oct 2017 11:46:33 +0200 Subject: [PATCH] prometheus: fixed unsaved changes warning when changing time range due to step option on query model was changed in datasource.query code, fixes #9675 --- public/app/core/directives/diff-view.ts | 7 ++++--- public/app/core/services/timer.ts | 5 ++--- public/app/features/dashboard/model.ts | 1 - public/app/features/dashboard/unsavedChangesSrv.js | 1 - public/app/features/dashboard/viewStateSrv.js | 3 --- .../app/plugins/datasource/prometheus/datasource.ts | 11 ++++------- 6 files changed, 10 insertions(+), 18 deletions(-) diff --git a/public/app/core/directives/diff-view.ts b/public/app/core/directives/diff-view.ts index b82b23951b7..db76681498c 100644 --- a/public/app/core/directives/diff-view.ts +++ b/public/app/core/directives/diff-view.ts @@ -7,14 +7,15 @@ export class DeltaCtrl { observer: any; /** @ngInject */ - constructor($rootScope) { - const waitForCompile = function(mutations) { + constructor(private $rootScope) { + + const waitForCompile = (mutations) => { if (mutations.length === 1) { this.$rootScope.appEvent('json-diff-ready'); } }; - this.observer = new MutationObserver(waitForCompile.bind(this)); + this.observer = new MutationObserver(waitForCompile); const observerConfig = { attributes: true, diff --git a/public/app/core/services/timer.ts b/public/app/core/services/timer.ts index c7f7aeb961d..191ea63af83 100644 --- a/public/app/core/services/timer.ts +++ b/public/app/core/services/timer.ts @@ -1,6 +1,8 @@ import _ from 'lodash'; import coreModule from 'app/core/core_module'; +// This service really just tracks a list of $timeout promises to give us a +// method for cancelling them all when we need to export class Timer { timers = []; @@ -14,7 +16,6 @@ export class Timer { } cancel(promise) { - console.log(promise); this.timers = _.without(this.timers, promise); this.$timeout.cancel(promise); } @@ -28,5 +29,3 @@ export class Timer { } coreModule.service('timer', Timer); -// This service really just tracks a list of $timeout promises to give us a -// method for cancelling them all when we need to diff --git a/public/app/features/dashboard/model.ts b/public/app/features/dashboard/model.ts index 7c4cdfac59e..cd48cd1ef00 100644 --- a/public/app/features/dashboard/model.ts +++ b/public/app/features/dashboard/model.ts @@ -35,7 +35,6 @@ export class DashboardModel { gnetId: any; meta: any; events: any; - editMode: boolean; constructor(data, meta?) { if (!data) { diff --git a/public/app/features/dashboard/unsavedChangesSrv.js b/public/app/features/dashboard/unsavedChangesSrv.js index 766ebce0b59..b00a0d02f1b 100644 --- a/public/app/features/dashboard/unsavedChangesSrv.js +++ b/public/app/features/dashboard/unsavedChangesSrv.js @@ -73,7 +73,6 @@ function(angular, _) { dash.time = 0; dash.refresh = 0; dash.schemaVersion = 0; - dash.editMode = false; // filter row and panels properties that should be ignored dash.rows = _.filter(dash.rows, function(row) { diff --git a/public/app/features/dashboard/viewStateSrv.js b/public/app/features/dashboard/viewStateSrv.js index 00b5b5bcdf9..9c58400b362 100644 --- a/public/app/features/dashboard/viewStateSrv.js +++ b/public/app/features/dashboard/viewStateSrv.js @@ -155,7 +155,6 @@ function (angular, _, $, config) { ctrl.editMode = false; ctrl.fullscreen = false; - ctrl.dashboard.editMode = this.oldDashboardEditMode; this.$scope.appEvent('panel-fullscreen-exit', {panelId: ctrl.panel.id}); @@ -177,10 +176,8 @@ function (angular, _, $, config) { ctrl.editMode = this.state.edit && this.dashboard.meta.canEdit; ctrl.fullscreen = true; - this.oldDashboardEditMode = this.dashboard.editMode; this.oldTimeRange = ctrl.range; this.fullscreenPanel = panelScope; - this.dashboard.editMode = false; $(window).scrollTop(0); diff --git a/public/app/plugins/datasource/prometheus/datasource.ts b/public/app/plugins/datasource/prometheus/datasource.ts index 98776f37962..c4939b5b2fa 100644 --- a/public/app/plugins/datasource/prometheus/datasource.ts +++ b/public/app/plugins/datasource/prometheus/datasource.ts @@ -1,5 +1,3 @@ -/// - import _ from 'lodash'; import kbn from 'app/core/utils/kbn'; @@ -122,7 +120,7 @@ export class PrometheusDatasource { } else { for (let metricData of response.data.data.result) { if (response.data.data.resultType === 'matrix') { - result.push(self.transformMetricData(metricData, activeTargets[index], start, end)); + result.push(self.transformMetricData(metricData, activeTargets[index], start, end, queries[index].step)); } else if (response.data.data.resultType === 'vector') { result.push(self.transformInstantMetricData(metricData, activeTargets[index])); } @@ -144,7 +142,6 @@ export class PrometheusDatasource { var intervalFactor = target.intervalFactor || 1; // Adjust the interval to take into account any specified minimum and interval factor plus Prometheus limits var adjustedInterval = this.adjustInterval(interval, minInterval, range, intervalFactor); - var scopedVars = options.scopedVars; // If the interval was adjusted, make a shallow copy of scopedVars with updated interval vars if (interval !== adjustedInterval) { @@ -154,7 +151,7 @@ export class PrometheusDatasource { "__interval_ms": {text: interval * 1000, value: interval * 1000}, }); } - target.step = query.step = interval; + query.step = interval; // Only replace vars in expression after having (possibly) updated interval vars query.expr = this.templateSrv.replace(target.expr, scopedVars, this.interpolateQueryExpr); @@ -272,13 +269,13 @@ export class PrometheusDatasource { }); } - transformMetricData(md, options, start, end) { + transformMetricData(md, options, start, end, step) { var dps = [], metricLabel = null; metricLabel = this.createMetricLabel(md.metric, options); - var stepMs = parseInt(options.step) * 1000; + var stepMs = step * 1000; var baseTimestamp = start * 1000; for (let value of md.values) { var dp_value = parseFloat(value[1]);