mirror of
https://github.com/grafana/grafana.git
synced 2025-01-28 17:24:59 -06:00
Slight refactoring, #1525
This commit is contained in:
parent
7a41ecb63f
commit
05d725d0b8
@ -14,6 +14,16 @@ function (_) {
|
||||
return this.target.rawQuery ? this._modifyRawQuery() : this._buildQuery();
|
||||
};
|
||||
|
||||
p.showTagsQuery = function() {
|
||||
var query = 'SHOW TAG KEYS';
|
||||
|
||||
if (this.target.measurement) {
|
||||
query += ' FROM "' + this.target.measurement + '"';
|
||||
}
|
||||
|
||||
return query;
|
||||
};
|
||||
|
||||
p._buildQuery = function() {
|
||||
var target = this.target;
|
||||
|
||||
@ -27,7 +37,7 @@ function (_) {
|
||||
var measurement = target.measurement;
|
||||
var aggregationFunc = target.function || 'mean';
|
||||
|
||||
if(!measurement.match('^/.*/') && !measurement.match(/^merge\(.*\)/)) {
|
||||
if (!measurement.match('^/.*/') && !measurement.match(/^merge\(.*\)/)) {
|
||||
measurement = '"' + measurement+ '"';
|
||||
}
|
||||
|
||||
|
@ -1,8 +1,9 @@
|
||||
define([
|
||||
'angular',
|
||||
'lodash'
|
||||
'lodash',
|
||||
'./queryBuilder',
|
||||
],
|
||||
function (angular, _) {
|
||||
function (angular, _, InfluxQueryBuilder) {
|
||||
'use strict';
|
||||
|
||||
var module = angular.module('grafana.controllers');
|
||||
@ -24,6 +25,8 @@ function (angular, _) {
|
||||
target.tags = target.tags || [];
|
||||
target.groupByTags = target.groupByTags || [];
|
||||
|
||||
$scope.queryBuilder = new InfluxQueryBuilder(target);
|
||||
|
||||
if (!target.measurement) {
|
||||
$scope.measurementSegment = MetricSegment.newSelectMeasurement();
|
||||
} else {
|
||||
@ -129,21 +132,11 @@ function (angular, _) {
|
||||
return segments;
|
||||
};
|
||||
|
||||
$scope.buildTagKeysQuery = function(target) {
|
||||
var query = 'SHOW TAG KEYS';
|
||||
|
||||
if (target.measurement) {
|
||||
query += ' FROM "' + target.measurement + '"';
|
||||
}
|
||||
|
||||
return query;
|
||||
};
|
||||
|
||||
$scope.getTagsOrValues = function(segment, index) {
|
||||
var query, queryType;
|
||||
if (segment.type === 'key' || segment.type === 'plus-button') {
|
||||
queryType = 'TAG_KEYS';
|
||||
query = $scope.buildTagKeysQuery($scope.target, segment);
|
||||
query = $scope.queryBuilder.showTagsQuery();
|
||||
} else if (segment.type === 'value') {
|
||||
queryType = 'TAG_VALUES';
|
||||
query = 'SHOW TAG VALUES FROM "' + $scope.target.measurement + '" WITH KEY = ' + $scope.tagSegments[index-2].value;
|
||||
|
@ -62,6 +62,34 @@ define([
|
||||
});
|
||||
});
|
||||
|
||||
describe('when building tag keys query', function() {
|
||||
|
||||
describe('given picked measurement', function() {
|
||||
it('build query with measurement filter', function() {
|
||||
var builder = new InfluxQueryBuilder({ measurement: 'cpu', tags: [] });
|
||||
var query = builder.showTagsQuery();
|
||||
expect(query).to.be('SHOW TAG KEYS FROM "cpu"');
|
||||
});
|
||||
});
|
||||
|
||||
describe('given no picked measurement', function() {
|
||||
it('build query without filter', function() {
|
||||
var builder = new InfluxQueryBuilder({ measurement: '', tags: [] });
|
||||
var query = builder.showTagsQuery();
|
||||
expect(query).to.be('SHOW TAG KEYS');
|
||||
});
|
||||
});
|
||||
|
||||
describe('given an existing tag', function() {
|
||||
it('build query with filter', function() {
|
||||
var builder = new InfluxQueryBuilder({ measurement: '', tags: [{key: 'host', value: 'se1'}] });
|
||||
var query = builder.showTagsQuery();
|
||||
expect(query).to.be('SHOW TAG KEYS');
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -198,23 +198,6 @@ define([
|
||||
});
|
||||
});
|
||||
|
||||
describe('when building tag keys query', function() {
|
||||
|
||||
describe('given picked measurement', function() {
|
||||
it('build query with measurement filter', function() {
|
||||
var query = ctx.scope.buildTagKeysQuery({ measurement: 'cpu', tags: [] }, {type: 'key'});
|
||||
expect(query).to.be('SHOW TAG KEYS FROM "cpu"');
|
||||
});
|
||||
});
|
||||
|
||||
describe('given no picked measurement', function() {
|
||||
it('build query without filter', function() {
|
||||
var query = ctx.scope.buildTagKeysQuery({ measurement: '', tags: [] }, {type: 'key'});
|
||||
expect(query).to.be('SHOW TAG KEYS');
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user