From 945131ccab42a518aac2a6d2336380ab35d29e30 Mon Sep 17 00:00:00 2001 From: Kaveh Nowroozi Date: Tue, 8 Mar 2016 10:47:36 -0500 Subject: [PATCH] add annotations for opentsdb --- .../plugins/datasource/opentsdb/datasource.js | 37 ++++++++++++++++++- .../app/plugins/datasource/opentsdb/module.ts | 6 ++- .../opentsdb/partials/annotations.editor.html | 10 +++++ .../plugins/datasource/opentsdb/plugin.json | 3 +- 4 files changed, 53 insertions(+), 3 deletions(-) create mode 100644 public/app/plugins/datasource/opentsdb/partials/annotations.editor.html diff --git a/public/app/plugins/datasource/opentsdb/datasource.js b/public/app/plugins/datasource/opentsdb/datasource.js index fd5cca93bc9..32139832628 100644 --- a/public/app/plugins/datasource/opentsdb/datasource.js +++ b/public/app/plugins/datasource/opentsdb/datasource.js @@ -69,6 +69,40 @@ function (angular, _, dateMath) { }.bind(this)); }; + this.annotationQuery = function(options) { + var start = convertToTSDBTime(options.rangeRaw.from, false); + var end = convertToTSDBTime(options.rangeRaw.to, true); + var qs = []; + var eventList = []; + + qs.push({ aggregator:"sum", metric:options.annotation.target }); + + var queries = _.compact(qs); + + return this.performTimeSeriesQuery(queries, start, end).then(function(results) { + if(results.data[0]) { + var annotationObject = results.data[0].annotations; + if(options.annotation.isGlobal){ + annotationObject = results.data[0].globalAnnotations; + } + if(annotationObject) { + _.each(annotationObject, function(annotation) { + var event = { + title: annotation.description, + time: Math.floor(annotation.startTime) * 1000, + text: annotation.notes, + annotation: options.annotation + }; + + eventList.push(event); + }); + } + } + return eventList; + + }.bind(this)); + }; + this.performTimeSeriesQuery = function(queries, start, end) { var msResolution = false; if (this.tsdbResolution === 2) { @@ -77,7 +111,8 @@ function (angular, _, dateMath) { var reqBody = { start: start, queries: queries, - msResolution: msResolution + msResolution: msResolution, + globalAnnotations: true }; // Relative queries (e.g. last hour) don't include an end time diff --git a/public/app/plugins/datasource/opentsdb/module.ts b/public/app/plugins/datasource/opentsdb/module.ts index e18552ac64c..895cbe2ad8c 100644 --- a/public/app/plugins/datasource/opentsdb/module.ts +++ b/public/app/plugins/datasource/opentsdb/module.ts @@ -2,9 +2,13 @@ import {OpenTsDatasource} from './datasource'; import {OpenTsQueryCtrl} from './query_ctrl'; import {OpenTsConfigCtrl} from './config_ctrl'; +class AnnotationsQueryCtrl { + static templateUrl = 'partials/annotations.editor.html'; +} + export { OpenTsDatasource as Datasource, OpenTsQueryCtrl as QueryCtrl, OpenTsConfigCtrl as ConfigCtrl, + AnnotationsQueryCtrl as AnnotationsQueryCtrl }; - diff --git a/public/app/plugins/datasource/opentsdb/partials/annotations.editor.html b/public/app/plugins/datasource/opentsdb/partials/annotations.editor.html new file mode 100644 index 00000000000..6c5cc5450bf --- /dev/null +++ b/public/app/plugins/datasource/opentsdb/partials/annotations.editor.html @@ -0,0 +1,10 @@ +
+
+ OpenTSDB metrics query + +
+
+ Show Global Annotations? + +
+
diff --git a/public/app/plugins/datasource/opentsdb/plugin.json b/public/app/plugins/datasource/opentsdb/plugin.json index 82fe2c32062..333e9d07536 100644 --- a/public/app/plugins/datasource/opentsdb/plugin.json +++ b/public/app/plugins/datasource/opentsdb/plugin.json @@ -4,5 +4,6 @@ "id": "opentsdb", "metrics": true, - "defaultMatchFormat": "pipe" + "defaultMatchFormat": "pipe", + "annotations": true }