Commit e1e6ba36 by Torkel Ödegaard

Refactoring influxdb datasource, split out response handling

parent 435a50de
define([ define([
'angular', 'angular',
'underscore', 'underscore',
'kbn' 'kbn',
'./influxSeries'
], ],
function (angular, _, kbn) { function (angular, _, kbn, InfluxSeries) {
'use strict'; 'use strict';
var module = angular.module('kibana.services'); var module = angular.module('kibana.services');
...@@ -194,57 +195,14 @@ function (angular, _, kbn) { ...@@ -194,57 +195,14 @@ function (angular, _, kbn) {
return deferred.promise; return deferred.promise;
}; };
function handleInfluxQueryResponse(alias, groupByField, data) { function handleInfluxQueryResponse(alias, groupByField, seriesList) {
var output = []; var influxSeries = new InfluxSeries({
seriesList: seriesList,
_.each(data, function(series) { alias: alias,
var seriesName; groupByField: groupByField
var timeCol = series.columns.indexOf('time');
var valueCol = 1;
var groupByCol = -1;
if (groupByField) {
groupByCol = series.columns.indexOf(groupByField);
}
// find value column
_.each(series.columns, function(column, index) {
if (column !== 'time' && column !== 'sequence_number' && column !== groupByField) {
valueCol = index;
}
});
var groups = {};
if (groupByField) {
groups = _.groupBy(series.points, function (point) {
return point[groupByCol];
});
}
else {
groups[series.columns[valueCol]] = series.points;
}
_.each(groups, function(groupPoints, key) {
var datapoints = [];
for (var i = 0; i < groupPoints.length; i++) {
var metricValue = isNaN(groupPoints[i][valueCol]) ? null : groupPoints[i][valueCol];
datapoints[i] = [metricValue, groupPoints[i][timeCol]];
}
seriesName = alias ? alias : (series.name + '.' + key);
// if mulitple groups append key to alias
if (alias && groupByField) {
seriesName += key;
}
output.push({ target: seriesName, datapoints: datapoints });
});
}); });
return output; return influxSeries.getTimeSeries();
} }
function getTimeFilter(options) { function getTimeFilter(options) {
......
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