moved annotations graphite query to graphite datasource

This commit is contained in:
Torkel Ödegaard 2014-07-14 18:19:41 +02:00
parent 7d6eafb2f2
commit 9eb9bd8488
2 changed files with 54 additions and 3 deletions

View File

@ -31,10 +31,16 @@ define([
return promiseCached;
}
var graphiteMetrics = this.getGraphiteMetrics(filterSrv, rangeUnparsed);
var graphiteEvents = this.getGraphiteEvents(rangeUnparsed);
var annotations = _.where(annotationPanel.annotations, { enable: true });
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() {
return list;
});
@ -42,6 +48,20 @@ define([
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) {
var annotations = this.getAnnotationsByType('graphite events');
if (annotations.length === 0) {

View File

@ -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) {
try {
var tags = '';