diff --git a/src/app/partials/influxdb/annotation_editor.html b/src/app/partials/influxdb/annotation_editor.html index e6573baa917..9bc2bdbca21 100644 --- a/src/app/partials/influxdb/annotation_editor.html +++ b/src/app/partials/influxdb/annotation_editor.html @@ -1,7 +1,29 @@
-
- - +
+
InfluxDB Query Example: select text from events where [[timeFilter]]
+
+ +
+
+
+ +
+
+
Column mappings If your influxdb query returns more than one column you need to specify the column names bellow. An annotation event is composed of a title, tags, and an additional text field.
+
+ + +
+ +
+ + +
+ +
+ + +
diff --git a/src/app/services/annotationsSrv.js b/src/app/services/annotationsSrv.js index bd27ad4b56a..7c51f45fdb1 100644 --- a/src/app/services/annotationsSrv.js +++ b/src/app/services/annotationsSrv.js @@ -142,8 +142,8 @@ define([ tooltip += '' + moment(options.time).format('YYYY-MM-DD HH:mm:ss') + '
'; - if (options.data) { - tooltip += options.data.replace(/\n/g, '
'); + if (options.text) { + tooltip += options.text.replace(/\n/g, '
'); } tooltip += ""; diff --git a/src/app/services/influxdb/influxSeries.js b/src/app/services/influxdb/influxSeries.js index 17c7bb10085..91466755673 100644 --- a/src/app/services/influxdb/influxSeries.js +++ b/src/app/services/influxdb/influxSeries.js @@ -71,27 +71,27 @@ function (_) { var self = this; _.each(this.seriesList, function (series) { - var titleCol = 0; - var tagsCol = 0; + var titleCol = null; + var timeCol = null; + var tagsCol = null; + var textCol = null; _.each(series.columns, function(column, index) { - if (column === 'time' || column === 'sequence_number') { - return; - } - - if (!titleCol && column !== 'tags') { - titleCol = index; - } - else { - tagsCol = index; - } + if (column === 'time') { timeCol = index; return; } + if (column === 'sequence_number') { return; } + if (!titleCol) { titleCol = index; } + if (column === self.annotation.titleColumn) { titleCol = index; return; } + if (column === self.annotation.tagsColumn) { tagsCol = index; return; } + if (column === self.annotation.textColumn) { textCol = index; return; } }); _.each(series.points, function (point) { var data = { annotation: self.annotation, - time: point[0] * 1000, - title: point[titleCol] + time: point[timeCol] * 1000, + title: point[titleCol], + tags: point[tagsCol], + text: point[textCol] }; if (tagsCol) { diff --git a/src/test/specs/influxSeries-specs.js b/src/test/specs/influxSeries-specs.js index 0787a834e37..591e8a9d8f4 100644 --- a/src/test/specs/influxSeries-specs.js +++ b/src/test/specs/influxSeries-specs.js @@ -140,33 +140,56 @@ define([ }); describe("when creating annotations from influxdb response", function() { - describe('given two series', function() { + describe('given column mapping for all columns', function() { + var series = new InfluxSeries({ + seriesList: [ + { + columns: ['time', 'text', 'sequence_number', 'title', 'tags'], + name: 'events1', + points: [[1402596000, 'some text', 1, 'Hello', 'B'], [1402596001, 'asd', 2, 'Hello2', 'B']] + } + ], + annotation: { + query: 'select', + titleColumn: 'title', + tagsColumn: 'tags', + textColumn: 'text', + } + }); + + var result = series.getAnnotations(); + + it(' should generate 2 annnotations ', function() { + expect(result.length).to.be(2); + expect(result[0].annotation.query).to.be('select'); + expect(result[0].title).to.be('Hello'); + expect(result[0].time).to.be(1402596000000); + expect(result[0].tags).to.be('B'); + expect(result[0].text).to.be('some text'); + }); + + }); + + describe('given no column mapping', function() { var series = new InfluxSeries({ seriesList: [ { columns: ['time', 'text', 'sequence_number'], name: 'events1', - points: [[1402596000, 'some text', 1], [1402596001, 'asd', 2]] - }, - { - columns: ['time', 'tags', 'text'], - name: 'events2', - points: [[1402596000, 'tag1, tag2', 'mu']] + points: [[1402596000, 'some text', 1]] } ], - annotation: {query: 'select'} + annotation: { query: 'select' } }); var result = series.getAnnotations(); - it(' should generate 4 annnotations ', function() { - expect(result.length).to.be(3); - expect(result[0].annotation.query).to.be('select'); + it('should generate 1 annnotation', function() { + expect(result.length).to.be(1); expect(result[0].title).to.be('some text'); expect(result[0].time).to.be(1402596000000); - expect(result[1].title).to.be('asd'); - //expect(result[2].tags).to.be('tag1, tag2'); - //expect(result[2].title).to.be('mu'); + expect(result[0].tags).to.be(undefined); + expect(result[0].text).to.be(undefined); }); });