Commit ac439d83 by Carl Bergquist

Merge pull request #4296 from knowroozi/opentsdb_annotations

add annotations for opentsdb
parents c0b92eb5 945131cc
......@@ -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
......
......@@ -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
};
<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>
......@@ -4,5 +4,6 @@
"id": "opentsdb",
"metrics": true,
"defaultMatchFormat": "pipe"
"defaultMatchFormat": "pipe",
"annotations": true
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment