Browse Source

prometheus: fixed unsaved changes warning when changing time range due to step option on query model was changed in datasource.query code, fixes #9675

Torkel Ödegaard 8 years ago
parent
commit
74fcb2494a

+ 4 - 3
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,

+ 2 - 3
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

+ 0 - 1
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) {

+ 0 - 1
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) {

+ 0 - 3
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);
 

+ 4 - 7
public/app/plugins/datasource/prometheus/datasource.ts

@@ -1,5 +1,3 @@
-///<reference path="../../../headers/common.d.ts" />
-
 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]);