소스 검색

Annotations: fixed InfluxDB annotation query, added unit test for annotation query, Fixes #802

Torkel Ödegaard 11 년 전
부모
커밋
15f2b2cf9a
3개의 변경된 파일32개의 추가작업 그리고 3개의 파일을 삭제
  1. 6 1
      CHANGELOG.md
  2. 1 1
      src/app/services/influxdb/influxdbDatasource.js
  3. 25 1
      src/test/specs/influxdb-datasource-specs.js

+ 6 - 1
CHANGELOG.md

@@ -1,4 +1,9 @@
-# 1.8.0 (unreleased)
+# 1.8.0 (2014-09-12)
+
+**Fixes**
+- [Issue #802](https://github.com/grafana/grafana/issues/802). Annotations: Fix when using InfluxDB datasource
+
+# 1.8.0-RC1 (2014-09-12)
 
 **UI polish / changes**
 - [Issue #725](https://github.com/grafana/grafana/issues/725). UI: All modal editors are removed and replaced by an edit pane under menu. The look of editors is also updated and polished. Search dropdown is also shown as pane under menu and has seen some UI polish.

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

@@ -64,7 +64,7 @@ function (angular, _, kbn, InfluxSeries, InfluxQueryBuilder) {
     InfluxDatasource.prototype.annotationQuery = function(annotation, rangeUnparsed) {
       var timeFilter = getTimeFilter({ range: rangeUnparsed });
       var query = annotation.query.replace('$timeFilter', timeFilter);
-      query = templateSrv.replace(annotation.query);
+      query = templateSrv.replace(query);
 
       return this._seriesQuery(query).then(function(results) {
         return new InfluxSeries({ seriesList: results, annotation: annotation }).getAnnotations();

+ 25 - 1
src/test/specs/influxdb-datasource-specs.js

@@ -8,7 +8,7 @@ define([
     var ctx = new helpers.ServiceTestContext();
 
     beforeEach(module('grafana.services'));
-    beforeEach(ctx.providePhase());
+    beforeEach(ctx.providePhase(['templateSrv']));
     beforeEach(ctx.createService('InfluxDatasource'));
     beforeEach(function() {
       ctx.ds = new ctx.service({ urls: [''], user: 'test', password: 'mupp' });
@@ -70,6 +70,30 @@ 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";
+
+      var range = { from: 'now-1h', to: 'now' };
+      var annotation = { query: 'select title from events.$server where $timeFilter' };
+      var response = [];
+
+      beforeEach(function() {
+        ctx.templateSrv.replace = function(str) {
+          return str.replace('$server', 'backend_01');
+        };
+        ctx.$httpBackend.expect('GET', urlExpected).respond(response);
+        ctx.ds.annotationQuery(annotation, range).then(function(data) { results = data; });
+        ctx.$httpBackend.flush();
+      });
+
+      it('should generate the correct query', function() {
+        ctx.$httpBackend.verifyNoOutstandingExpectation();
+      });
+
+    });
+
   });
 
 });