Progress on InfluxDB 0.9 support, but will take a break, it is impossible to work on this, cannot get any queries that use tags to work with InfluxDB 0.9rc15, just empty response, #1525

This commit is contained in:
Torkel Ödegaard 2015-03-26 13:51:29 +01:00
parent fcac4c057c
commit b04c50537d
6 changed files with 70 additions and 23 deletions

View File

@ -36,13 +36,14 @@ function (angular, _, kbn, InfluxSeries, InfluxQueryBuilder) {
var timeFilter = getTimeFilter(options);
var promises = _.map(options.targets, function(target) {
if (target.hide || !target.query) {
if (target.hide) {
return [];
}
// build query
var queryBuilder = new InfluxQueryBuilder(target);
var query = queryBuilder.build();
console.log('query builder result:' + query);
// replace grafana variables
query = query.replace('$timeFilter', timeFilter);

View File

@ -53,9 +53,6 @@
</ul>
<ul class="tight-form-list">
<li class="tight-form-item" style="min-width: 15px; text-align: center">
{{targetLetters[$index]}}
</li>
<li>
<a class="tight-form-item"
ng-click="target.hide = !target.hide; get_data();"

View File

@ -1,6 +1,7 @@
define([
'lodash'
],
function () {
function (_) {
'use strict';
function InfluxQueryBuilder(target) {
@ -15,36 +16,36 @@ function () {
p._buildQuery = function() {
var target = this.target;
var query = 'select ';
var seriesName = target.series;
if(!seriesName.match('^/.*/') && !seriesName.match(/^merge\(.*\)/)) {
seriesName = '"' + seriesName+ '"';
console.log('Build Query: target = ', target);
if (!target.measurement) {
throw "Metric measurement is missing";
}
if (target.groupby_field) {
query += target.groupby_field + ', ';
var query = 'SELECT ';
var measurement = target.measurement;
var aggregationFunc = target.function || 'mean';
if(!measurement.match('^/.*/') && !measurement.match(/^merge\(.*\)/)) {
measurement = '"' + measurement+ '"';
}
query += target.function + '(' + target.column + ')';
query += ' from ' + seriesName + ' where $timeFilter';
query += aggregationFunc + '(value)';
query += ' FROM ' + measurement + ' WHERE ';
query += _.map(target.tags, function(value, key) {
return key + ' = ' + "'" + value + "' AND ";
});
if (target.condition) {
query += ' and ' + target.condition;
}
query += '$timeFilter';
query += ' group by time($interval)';
if (target.groupby_field) {
query += ', ' + target.groupby_field;
this.groupByField = target.groupby_field;
}
query += ' GROUP BY time($interval)';
if (target.fill) {
query += ' fill(' + target.fill + ')';
}
query += " order asc";
query += " ORDER BY asc";
target.query = query;
return query;

View File

@ -93,6 +93,15 @@ function (angular, _) {
return;
}
$scope.target.measurement = '';
$scope.target.tags = {};
$scope.target.measurement = $scope.segments[0].value;
for (var i = 1; i+1 < $scope.segments.length; i += 2) {
var key = $scope.segments[i].value;
$scope.target.tags[key] = $scope.segments[i+1].value;
}
$scope.$parent.get_data();
};

View File

@ -0,0 +1,38 @@
define([
'plugins/datasource/influxdb/queryBuilder'
], function(InfluxQueryBuilder) {
'use strict';
describe('InfluxQueryBuilder', function() {
describe('series with mesurement only', function() {
var builder = new InfluxQueryBuilder({
measurement: 'cpu',
});
var query = builder.build();
it('should generate correct query', function() {
expect(query).to.be('SELECT mean(value) FROM "cpu" WHERE $timeFilter GROUP BY time($interval) ORDER BY asc');
});
});
describe('series with tags only', function() {
var builder = new InfluxQueryBuilder({
measurement: 'cpu',
tags: {'hostname': 'server1'}
});
var query = builder.build();
it('should generate correct query', function() {
expect(query).to.be('SELECT mean(value) FROM "cpu" WHERE hostname = \'server1\'' +
' AND $timeFilter GROUP BY time($interval) ORDER BY asc');
});
});
});
});

View File

@ -126,6 +126,7 @@ require([
'specs/graphiteDatasource-specs',
'specs/influxSeries-specs',
'specs/influxQueryBuilder-specs',
'specs/influx09-querybuilder-specs',
'specs/influxdb-datasource-specs',
'specs/graph-ctrl-specs',
'specs/graph-specs',