mirror of https://github.com/grafana/grafana.git
influxdb annotations working, need to figure out how to know which columns to use for title, tags, and data
This commit is contained in:
parent
2fe3b0de55
commit
cf2ef0955d
|
|
@ -49,16 +49,8 @@ define([
|
|||
};
|
||||
|
||||
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
|
||||
});
|
||||
addAnnotation(results[i]);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -143,14 +135,17 @@ define([
|
|||
}
|
||||
|
||||
function addAnnotation(options) {
|
||||
var tooltip = "<small><b>" + options.description + "</b><br/>";
|
||||
var tooltip = "<small><b>" + options.title + "</b><br/>";
|
||||
if (options.tags) {
|
||||
tooltip += (options.tags || '') + '<br/>';
|
||||
}
|
||||
|
||||
tooltip += '<i>' + moment(options.time).format('YYYY-MM-DD HH:mm:ss') + '</i><br/>';
|
||||
|
||||
if (options.data) {
|
||||
tooltip += options.data.replace(/\n/g, '<br/>');
|
||||
}
|
||||
|
||||
tooltip += "</small>";
|
||||
|
||||
list.push({
|
||||
|
|
|
|||
|
|
@ -79,7 +79,7 @@ function (angular, _, $, config, kbn, moment) {
|
|||
list.push({
|
||||
annotation: annotation,
|
||||
time: datapoint[1] * 1000,
|
||||
description: target.target
|
||||
title: target.target
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ function (_) {
|
|||
this.seriesList = options.seriesList;
|
||||
this.alias = options.alias;
|
||||
this.groupByField = options.groupByField;
|
||||
this.annotation = options.annotation;
|
||||
}
|
||||
|
||||
var p = InfluxSeries.prototype;
|
||||
|
|
@ -65,6 +66,45 @@ function (_) {
|
|||
return output;
|
||||
};
|
||||
|
||||
p.getAnnotations = function () {
|
||||
var list = [];
|
||||
var self = this;
|
||||
|
||||
_.each(this.seriesList, function (series) {
|
||||
var titleCol = 0;
|
||||
var tagsCol = 0;
|
||||
|
||||
_.each(series.columns, function(column, index) {
|
||||
if (column === 'time' || column === 'sequence_number') {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!titleCol && column !== 'tags') {
|
||||
titleCol = index;
|
||||
}
|
||||
else {
|
||||
tagsCol = index;
|
||||
}
|
||||
});
|
||||
|
||||
_.each(series.points, function (point) {
|
||||
var data = {
|
||||
annotation: self.annotation,
|
||||
time: point[0] * 1000,
|
||||
title: point[titleCol]
|
||||
};
|
||||
|
||||
if (tagsCol) {
|
||||
data.tags = point[tagsCol];
|
||||
}
|
||||
|
||||
list.push(data);
|
||||
});
|
||||
});
|
||||
|
||||
return list;
|
||||
};
|
||||
|
||||
p.createNameForSeries = function(seriesName, groupByColValue) {
|
||||
var name = this.alias
|
||||
.replace('$s', seriesName);
|
||||
|
|
@ -84,4 +124,4 @@ function (_) {
|
|||
};
|
||||
|
||||
return InfluxSeries;
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -121,46 +121,11 @@ function (angular, _, kbn, InfluxSeries) {
|
|||
|
||||
InfluxDatasource.prototype.annotationQuery = function(annotation, filterSrv, rangeUnparsed) {
|
||||
var timeFilter = getTimeFilter({ range: rangeUnparsed });
|
||||
var query = _.template(annotation.query, {
|
||||
timeFilter: timeFilter
|
||||
}, this.templateSettings);
|
||||
var query = _.template(annotation.query, { timeFilter: timeFilter }, this.templateSettings);
|
||||
|
||||
return this.doInfluxRequest(query)
|
||||
.then(function (results) {
|
||||
var list = [];
|
||||
_.each(results, function (series) {
|
||||
var descriptionCol = 0;
|
||||
var tagsCol = 0;
|
||||
_.each(series.columns, function(column, index) {
|
||||
if (column === 'time' || column === 'sequence_number') {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!descriptionCol) {
|
||||
descriptionCol = index;
|
||||
}
|
||||
else {
|
||||
tagsCol = index;
|
||||
}
|
||||
});
|
||||
|
||||
_.each(series.points, function (point) {
|
||||
var data = {
|
||||
annotation: annotation,
|
||||
time: point[0] * 1000,
|
||||
description: point[descriptionCol]
|
||||
};
|
||||
|
||||
if (tagsCol) {
|
||||
data.tags = point[tagsCol];
|
||||
}
|
||||
|
||||
list.push(data);
|
||||
});
|
||||
});
|
||||
|
||||
return list;
|
||||
});
|
||||
return this.doInfluxRequest(query).then(function(results) {
|
||||
return new InfluxSeries({ seriesList: results, annotation: annotation }).getAnnotations();
|
||||
});
|
||||
};
|
||||
|
||||
InfluxDatasource.prototype.listColumns = function(seriesName) {
|
||||
|
|
|
|||
|
|
@ -139,4 +139,38 @@ define([
|
|||
|
||||
});
|
||||
|
||||
describe("when creating annotations from influxdb response", function() {
|
||||
describe('given two series', function() {
|
||||
var series = new InfluxSeries({
|
||||
seriesList: [
|
||||
{
|
||||
columns: ['time', 'text', 'sequence_number'],
|
||||
name: 'events1',
|
||||
points: [[1402596000, 'some text', 1], [1402596001, 'asd', 2]]
|
||||
},
|
||||
{
|
||||
columns: ['time', 'tags', 'text'],
|
||||
name: 'events2',
|
||||
points: [[1402596000, 'tag1, tag2', 'mu']]
|
||||
}
|
||||
],
|
||||
annotation: {query: 'select'}
|
||||
});
|
||||
|
||||
var result = series.getAnnotations();
|
||||
|
||||
it(' should generate 4 annnotations ', function() {
|
||||
expect(result.length).to.be(3);
|
||||
expect(result[0].annotation.query).to.be('select');
|
||||
expect(result[0].title).to.be('some text');
|
||||
expect(result[0].time).to.be(1402596000000);
|
||||
expect(result[1].title).to.be('asd');
|
||||
//expect(result[2].tags).to.be('tag1, tag2');
|
||||
//expect(result[2].title).to.be('mu');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in New Issue