mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Merge branch 'influxdb_operators' of https://github.com/thuck/grafana into thuck-influxdb_operators
This commit is contained in:
commit
ca6476a57f
@ -10,14 +10,18 @@ function (_) {
|
||||
|
||||
function renderTagCondition (tag, index) {
|
||||
var str = "";
|
||||
var operator = (tag.operator || '=');
|
||||
if (index > 0) {
|
||||
str = (tag.condition || 'AND') + ' ';
|
||||
}
|
||||
|
||||
if (tag.value && tag.value[0] === '/' && tag.value[tag.value.length - 1] === '/') {
|
||||
return str + '"' +tag.key + '"' + ' =~ ' + tag.value;
|
||||
if (tag.value && (operator === '=~' || operator === '!~') && /^\/.*\/$/.test(tag.value)) {
|
||||
return str + '"' + tag.key + '"' + ' ' + operator + ' ' + tag.value;
|
||||
} else if (tag.value && /^\/.*\/$/.test(tag.value)) {
|
||||
return str + '"' + tag.key + '"' + ' =~ ' + tag.value;
|
||||
}
|
||||
return str + '"' + tag.key + '"' + " = '" + tag.value + "'";
|
||||
|
||||
return str + '"' + tag.key + '" ' + operator + " '" + tag.value + "'";
|
||||
}
|
||||
|
||||
var p = InfluxQueryBuilder.prototype;
|
||||
|
@ -35,7 +35,13 @@ function (angular, _, InfluxQueryBuilder) {
|
||||
$scope.tagSegments.push(MetricSegment.newCondition(tag.condition));
|
||||
}
|
||||
$scope.tagSegments.push(new MetricSegment({value: tag.key, type: 'key', cssClass: 'query-segment-key' }));
|
||||
$scope.tagSegments.push(new MetricSegment.newOperator("="));
|
||||
if (tag.operator) {
|
||||
$scope.tagSegments.push(MetricSegment.newOperator(tag.operator));
|
||||
} else if (/^\/.*\/$/.test(tag.value)) {
|
||||
$scope.tagSegments.push(MetricSegment.newOperator('=~'));
|
||||
} else {
|
||||
$scope.tagSegments.push(MetricSegment.newOperator('='));
|
||||
}
|
||||
$scope.tagSegments.push(new MetricSegment({value: tag.value, type: 'value', cssClass: 'query-segment-value'}));
|
||||
});
|
||||
|
||||
@ -150,6 +156,12 @@ function (angular, _, InfluxQueryBuilder) {
|
||||
query = $scope.queryBuilder.buildExploreQuery('TAG_VALUES', $scope.tagSegments[index-2].value);
|
||||
} else if (segment.type === 'condition') {
|
||||
return $q.when([new MetricSegment('AND'), new MetricSegment('OR')]);
|
||||
} else if (segment.type === 'operator' && /^(?!\/.*\/$)/.test($scope.tagSegments[index+1].value)) {
|
||||
return $q.when([MetricSegment.newOperator('='), MetricSegment.newOperator('<>'),
|
||||
MetricSegment.newOperator('<'), MetricSegment.newOperator('>')]);
|
||||
|
||||
} else if (segment.type === 'operator' && /^\/.*\/$/.test($scope.tagSegments[index+1].value)) {
|
||||
return $q.when([MetricSegment.newOperator('=~'), MetricSegment.newOperator('!~')]);
|
||||
}
|
||||
else {
|
||||
return $q.when([]);
|
||||
@ -238,6 +250,7 @@ function (angular, _, InfluxQueryBuilder) {
|
||||
$scope.rebuildTargetTagConditions = function() {
|
||||
var tags = [];
|
||||
var tagIndex = 0;
|
||||
var tagOperator = "";
|
||||
_.each($scope.tagSegments, function(segment2, index) {
|
||||
if (segment2.type === 'key') {
|
||||
if (tags.length === 0) {
|
||||
@ -246,25 +259,33 @@ function (angular, _, InfluxQueryBuilder) {
|
||||
tags[tagIndex].key = segment2.value;
|
||||
}
|
||||
else if (segment2.type === 'value') {
|
||||
tagOperator = $scope.getTagValueOperator(segment2.value, tags[tagIndex].operator);
|
||||
if (tagOperator) {
|
||||
$scope.tagSegments[index-1] = MetricSegment.newOperator(tagOperator);
|
||||
tags[tagIndex].operator = tagOperator;
|
||||
}
|
||||
tags[tagIndex].value = segment2.value;
|
||||
$scope.tagSegments[index-1] = $scope.getTagValueOperator(segment2.value);
|
||||
}
|
||||
else if (segment2.type === 'condition') {
|
||||
tags.push({ condition: segment2.value });
|
||||
tagIndex += 1;
|
||||
}
|
||||
else if (segment2.type === 'operator') {
|
||||
tags[tagIndex].operator = segment2.value;
|
||||
}
|
||||
});
|
||||
|
||||
$scope.target.tags = tags;
|
||||
$scope.$parent.get_data();
|
||||
};
|
||||
|
||||
$scope.getTagValueOperator = function(tagValue) {
|
||||
if (tagValue[0] === '/' && tagValue[tagValue.length - 1] === '/') {
|
||||
return MetricSegment.newOperator('=~');
|
||||
$scope.getTagValueOperator = function(tagValue, tagOperator) {
|
||||
if (tagOperator !== '=~' && tagOperator !== '!~' && /^\/.*\/$/.test(tagValue)) {
|
||||
return '=~';
|
||||
}
|
||||
else if ((tagOperator === '=~' || tagOperator === '!~') && /^(?!\/.*\/$)/.test(tagValue)) {
|
||||
return '=';
|
||||
}
|
||||
|
||||
return MetricSegment.newOperator('=');
|
||||
};
|
||||
|
||||
function MetricSegment(options) {
|
||||
|
Loading…
Reference in New Issue
Block a user