From ebcf2c3f6854cbe2903ad8c97af18018c5b42c7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Wed, 12 Nov 2014 08:39:04 +0100 Subject: [PATCH] InfluxDB: Support for sub second resolution graphs, Closes #714, #728, #752 --- CHANGELOG.md | 3 +++ src/app/components/timeSeries.js | 4 ++-- src/app/panels/graph/module.js | 2 +- src/app/services/graphite/graphiteDatasource.js | 13 ++++++++++++- src/app/services/influxdb/influxdbDatasource.js | 1 - src/app/services/opentsdb/opentsdbDatasource.js | 2 +- src/test/specs/grafanaGraph-specs.js | 2 +- src/test/specs/graphiteDatasource-specs.js | 2 +- src/test/specs/influxdb-datasource-specs.js | 6 +++--- 9 files changed, 24 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0f409928f74..2b68728cb44 100644 --- a/CHANGELOG.md +++ b/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 diff --git a/src/app/components/timeSeries.js b/src/app/components/timeSeries.js index f845965c59e..6d54239a0bc 100644 --- a/src/app/components/timeSeries.js +++ b/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; } diff --git a/src/app/panels/graph/module.js b/src/app/panels/graph/module.js index adcb822b2de..9af80bcf7e2 100644 --- a/src/app/panels/graph/module.js +++ b/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; diff --git a/src/app/services/graphite/graphiteDatasource.js b/src/app/services/graphite/graphiteDatasource.js index 20ef5cbfa3a..10d3e0dae7f 100644 --- a/src/app/services/graphite/graphiteDatasource.js +++ b/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) { diff --git a/src/app/services/influxdb/influxdbDatasource.js b/src/app/services/influxdb/influxdbDatasource.js index 287e2286f07..43e245bfc4c 100644 --- a/src/app/services/influxdb/influxdbDatasource.js +++ b/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', }); }; diff --git a/src/app/services/opentsdb/opentsdbDatasource.js b/src/app/services/opentsdb/opentsdbDatasource.js index 17232d54047..96784cbc992 100644 --- a/src/app/services/opentsdb/opentsdbDatasource.js +++ b/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 }; diff --git a/src/test/specs/grafanaGraph-specs.js b/src/test/specs/grafanaGraph-specs.js index c61cddf9059..5344917ab31 100644 --- a/src/test/specs/grafanaGraph-specs.js +++ b/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); }); }); diff --git a/src/test/specs/graphiteDatasource-specs.js b/src/test/specs/graphiteDatasource-specs.js index 99270867266..f112492aebc 100644 --- a/src/test/specs/graphiteDatasource-specs.js +++ b/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; diff --git a/src/test/specs/influxdb-datasource-specs.js b/src/test/specs/influxdb-datasource-specs.js index 3851b0cd898..c0d25e1e81f 100644 --- a/src/test/specs/influxdb-datasource-specs.js +++ b/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' };