Commit 9eb9bd84 by Torkel Ödegaard

moved annotations graphite query to graphite datasource

parent 7d6eafb2
...@@ -31,10 +31,16 @@ define([ ...@@ -31,10 +31,16 @@ define([
return promiseCached; return promiseCached;
} }
var graphiteMetrics = this.getGraphiteMetrics(filterSrv, rangeUnparsed); var annotations = _.where(annotationPanel.annotations, { enable: true });
var graphiteEvents = this.getGraphiteEvents(rangeUnparsed);
promiseCached = $q.all(graphiteMetrics.concat(graphiteEvents)) var promises = _.map(annotations, function(annotation) {
var datasource = datasourceSrv.get(annotation.datasource);
return datasource.annotationQuery(annotation, filterSrv, rangeUnparsed)
.then(this.receiveAnnotationResults)
.then(null, errorHandler);
}, this);
promiseCached = $q.all(promises)
.then(function() { .then(function() {
return list; return list;
}); });
...@@ -42,6 +48,20 @@ define([ ...@@ -42,6 +48,20 @@ define([
return promiseCached; return promiseCached;
}; };
this.receiveAnnotationResults = function(results) {
console.log('Annotation result!', results);
for (var i = 0; i < results.length; i++) {
var data = results[i];
addAnnotation({
annotation: data.annotation,
time: data.time,
description: data.description,
tags: data.tags,
data: data.text
});
}
};
this.getGraphiteEvents = function(rangeUnparsed) { this.getGraphiteEvents = function(rangeUnparsed) {
var annotations = this.getAnnotationsByType('graphite events'); var annotations = this.getAnnotationsByType('graphite events');
if (annotations.length === 0) { if (annotations.length === 0) {
......
...@@ -57,6 +57,37 @@ function (angular, _, $, config, kbn, moment) { ...@@ -57,6 +57,37 @@ function (angular, _, $, config, kbn, moment) {
} }
}; };
GraphiteDatasource.prototype.annotationQuery = function(annotation, filterSrv, rangeUnparsed) {
var graphiteQuery = {
range: rangeUnparsed,
targets: [{ target: annotation.target }],
format: 'json',
maxDataPoints: 100
};
return this.query(filterSrv, graphiteQuery)
.then(function(result) {
var list = [];
for (var i = 0; i < result.data.length; i++) {
var target = result.data[i];
for (var y = 0; y < target.datapoints.length; y++) {
var datapoint = target.datapoints[y];
if (!datapoint[0]) { continue; }
list.push({
annotation: annotation,
time: datapoint[1] * 1000,
description: target.target
});
}
}
return list;
});
};
GraphiteDatasource.prototype.events = function(options) { GraphiteDatasource.prototype.events = function(options) {
try { try {
var tags = ''; var tags = '';
......
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