Просмотр исходного кода

InfluxDB: Support for sub second resolution graphs, Closes #714, #728, #752

Torkel Ödegaard 11 лет назад
Родитель
Сommit
ebcf2c3f68

+ 3 - 0
CHANGELOG.md

@@ -25,6 +25,9 @@
 - [Issue #930](https://github.com/grafana/grafana/issues/930). OpenTSDB: Adding counter max and counter reset value to open tsdb query editor, thx @rsimiciuc
 - [Issue #917](https://github.com/grafana/grafana/issues/917). OpenTSDB: Templating support for OpenTSDB series name and tags, thx @mchataigner
 
+**InfluxDB**
+- [Issue #714](https://github.com/grafana/grafana/issues/714). InfluxDB: Support for sub second resolution graphs
+
 **Fixes**
 - [Issue #925](https://github.com/grafana/grafana/issues/925). Graph: bar width calculation fix for some edge cases (bars would render on top of each other)
 - [Issue #505](https://github.com/grafana/grafana/issues/505). Graph: fix for second y axis tick unit labels wrapping on the next line

+ 2 - 2
src/app/components/timeSeries.js

@@ -99,11 +99,11 @@ function (_, kbn) {
         this.stats.min = currentValue;
       }
 
-      result.push([currentTime * 1000, currentValue]);
+      result.push([currentTime, currentValue]);
     }
 
     if (this.datapoints.length >= 2) {
-      this.stats.timeStep = (this.datapoints[1][1] - this.datapoints[0][1]) * 1000;
+      this.stats.timeStep = this.datapoints[1][1] - this.datapoints[0][1];
     }
 
     if (this.stats.max === Number.MIN_VALUE) { this.stats.max = null; }

+ 1 - 1
src/app/panels/graph/module.js

@@ -189,7 +189,7 @@ function (angular, app, $, _, kbn, moment, TimeSeries, PanelMeta) {
       });
 
       if (datapoints && datapoints.length > 0) {
-        var last = moment.utc(datapoints[datapoints.length - 1][1] * 1000);
+        var last = moment.utc(datapoints[datapoints.length - 1][1]);
         var from = moment.utc($scope.range.from);
         if (last - from < -10000) {
           $scope.datapointsOutside = true;

+ 12 - 1
src/app/services/graphite/graphiteDatasource.js

@@ -53,13 +53,24 @@ function (angular, _, $, config, kbn, moment) {
           httpOptions.headers = { 'Content-Type': 'application/x-www-form-urlencoded' };
         }
 
-        return this.doGraphiteRequest(httpOptions);
+        return this.doGraphiteRequest(httpOptions).then(this.convertDataPointsToMs);
       }
       catch(err) {
         return $q.reject(err);
       }
     };
 
+    GraphiteDatasource.prototype.convertDataPointsToMs = function(result) {
+      if (!result || !result.data) { return []; }
+      for (var i = 0; i < result.data.length; i++) {
+        var series = result.data[i];
+        for (var y = 0; y < series.datapoints.length; y++) {
+          series.datapoints[y][1] *= 1000;
+        }
+      }
+      return result;
+    };
+
     GraphiteDatasource.prototype.annotationQuery = function(annotation, rangeUnparsed) {
       // Graphite metric as annotation
       if (annotation.target) {

+ 0 - 1
src/app/services/influxdb/influxdbDatasource.js

@@ -146,7 +146,6 @@ function (angular, _, kbn, InfluxSeries, InfluxQueryBuilder) {
     InfluxDatasource.prototype._seriesQuery = function(query) {
       return this._influxRequest('GET', '/series', {
         q: query,
-        time_precision: 's',
       });
     };
 

+ 1 - 1
src/app/services/opentsdb/opentsdbDatasource.js

@@ -100,7 +100,7 @@ function (angular, _, kbn) {
       // TSDB returns datapoints has a hash of ts => value.
       // Can't use _.pairs(invert()) because it stringifies keys/values
       _.each(md.dps, function (v, k) {
-        dps.push([v, k]);
+        dps.push([v, k * 1000]);
       });
 
       return { target: metricLabel, datapoints: dps };

+ 1 - 1
src/test/specs/grafanaGraph-specs.js

@@ -136,7 +136,7 @@ define([
       });
 
       it('should set barWidth', function() {
-        expect(ctx.plotOptions.series.bars.barWidth).to.be(10000/1.5);
+        expect(ctx.plotOptions.series.bars.barWidth).to.be(10/1.5);
       });
     });
 

+ 1 - 1
src/test/specs/graphiteDatasource-specs.js

@@ -21,7 +21,7 @@ define([
         maxDataPoints: 500,
       };
 
-      var response = [{ target: 'prod1.count', points: [[10, 1], [12,1]], }];
+      var response = [{ target: 'prod1.count', datapoints: [[10, 1], [12,1]], }];
       var results;
       var request;
 

+ 3 - 3
src/test/specs/influxdb-datasource-specs.js

@@ -17,7 +17,7 @@ define([
     describe('When querying influxdb with one target using query editor target spec', function() {
       var results;
       var urlExpected = "/series?p=mupp&q=select+mean(value)+from+%22test%22"+
-                        "+where+time+%3E+now()+-+1h+group+by+time(1s)+order+asc&time_precision=s";
+                        "+where+time+%3E+now()+-+1h+group+by+time(1s)+order+asc";
       var query = {
         range: { from: 'now-1h', to: 'now' },
         targets: [{ series: 'test', column: 'value', function: 'mean' }],
@@ -50,7 +50,7 @@ define([
     describe('When querying influxdb with one raw query', function() {
       var results;
       var urlExpected = "/series?p=mupp&q=select+value+from+series"+
-                        "+where+time+%3E+now()+-+1h&time_precision=s";
+                        "+where+time+%3E+now()+-+1h";
       var query = {
         range: { from: 'now-1h', to: 'now' },
         targets: [{ query: "select value from series where $timeFilter", rawQuery: true }]
@@ -73,7 +73,7 @@ define([
     describe('When issuing annotation query', function() {
       var results;
       var urlExpected = "/series?p=mupp&q=select+title+from+events.backend_01"+
-                        "+where+time+%3E+now()+-+1h&time_precision=s";
+                        "+where+time+%3E+now()+-+1h";
 
       var range = { from: 'now-1h', to: 'now' };
       var annotation = { query: 'select title from events.$server where $timeFilter' };