Przeglądaj źródła

Merge pull request #4296 from knowroozi/opentsdb_annotations

add annotations for opentsdb
Carl Bergquist 9 lat temu
rodzic
commit
ac439d83fe

+ 36 - 1
public/app/plugins/datasource/opentsdb/datasource.js

@@ -69,6 +69,40 @@ function (angular, _, dateMath) {
       }.bind(this));
       }.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) {
     this.performTimeSeriesQuery = function(queries, start, end) {
       var msResolution = false;
       var msResolution = false;
       if (this.tsdbResolution === 2) {
       if (this.tsdbResolution === 2) {
@@ -77,7 +111,8 @@ function (angular, _, dateMath) {
       var reqBody = {
       var reqBody = {
         start: start,
         start: start,
         queries: queries,
         queries: queries,
-        msResolution: msResolution
+        msResolution: msResolution,
+        globalAnnotations: true
       };
       };
 
 
       // Relative queries (e.g. last hour) don't include an end time
       // Relative queries (e.g. last hour) don't include an end time

+ 5 - 1
public/app/plugins/datasource/opentsdb/module.ts

@@ -2,9 +2,13 @@ import {OpenTsDatasource} from './datasource';
 import {OpenTsQueryCtrl} from './query_ctrl';
 import {OpenTsQueryCtrl} from './query_ctrl';
 import {OpenTsConfigCtrl} from './config_ctrl';
 import {OpenTsConfigCtrl} from './config_ctrl';
 
 
+class AnnotationsQueryCtrl {
+  static templateUrl = 'partials/annotations.editor.html';
+}
+
 export {
 export {
   OpenTsDatasource as Datasource,
   OpenTsDatasource as Datasource,
   OpenTsQueryCtrl as QueryCtrl,
   OpenTsQueryCtrl as QueryCtrl,
   OpenTsConfigCtrl as ConfigCtrl,
   OpenTsConfigCtrl as ConfigCtrl,
+  AnnotationsQueryCtrl as AnnotationsQueryCtrl
 };
 };
-

+ 10 - 0
public/app/plugins/datasource/opentsdb/partials/annotations.editor.html

@@ -0,0 +1,10 @@
+<div class="gf-form-group">
+  <div class="gf-form">
+    <span class="gf-form-label width-13">OpenTSDB metrics query</span>
+    <input type="text" class="gf-form-input" ng-model='ctrl.annotation.target' placeholder="events.eventname"></input>
+  </div>
+  <div class="gf-form">
+    <span class="gf-form-label width-13">Show Global Annotations?</span>
+    <editor-checkbox text="" model="ctrl.annotation.isGlobal"></editor-checkbox>
+  </div>
+</div>

+ 2 - 1
public/app/plugins/datasource/opentsdb/plugin.json

@@ -4,5 +4,6 @@
   "id": "opentsdb",
   "id": "opentsdb",
 
 
   "metrics": true,
   "metrics": true,
-  "defaultMatchFormat": "pipe"
+  "defaultMatchFormat": "pipe",
+  "annotations": true
 }
 }