Commit f632b3b0 by Torkel Ödegaard

feat(elasticsearch): added new templating all format and muli format named ,…

feat(elasticsearch): added new templating all format and muli format named , also added automatic setting of correct all and multi format depending on data source, closes #2696
parent b37f9a7d
...@@ -36,6 +36,17 @@ function (angular, _) { ...@@ -36,6 +36,17 @@ function (angular, _) {
$scope.reset(); $scope.reset();
} }
}); });
$scope.$watch('current.datasource', function(val) {
if ($scope.mode === 'new') {
datasourceSrv.get(val).then(function(ds) {
if (ds.meta.defaultMatchFormat) {
$scope.current.allFormat = ds.meta.defaultMatchFormat;
$scope.current.multiFormat = ds.meta.defaultMatchFormat;
}
});
}
});
}; };
$scope.add = function() { $scope.add = function() {
......
...@@ -186,7 +186,7 @@ ...@@ -186,7 +186,7 @@
All format All format
</li> </li>
<li ng-show="current.includeAll"> <li ng-show="current.includeAll">
<select class="input-medium tight-form-input last" ng-model="current.allFormat" ng-change="runQuery()" ng-options="f for f in ['glob', 'wildcard', 'regex wildcard', 'regex values']"></select> <select class="input-medium tight-form-input last" ng-model="current.allFormat" ng-change="runQuery()" ng-options="f for f in ['glob', 'wildcard', 'regex wildcard', 'regex values', 'lucene']"></select>
</li> </li>
</ul> </ul>
<div class="clearfix"></div> <div class="clearfix"></div>
...@@ -217,7 +217,7 @@ ...@@ -217,7 +217,7 @@
Multi format Multi format
</li> </li>
<li ng-show="current.multi"> <li ng-show="current.multi">
<select class="input-medium tight-form-input last" ng-model="current.multiFormat" ng-change="runQuery()" ng-options="f for f in ['glob', 'regex values']"></select> <select class="input-medium tight-form-input last" ng-model="current.multiFormat" ng-change="runQuery()" ng-options="f for f in ['glob', 'regex values', 'lucene']"></select>
</li> </li>
</ul> </ul>
<div class="clearfix"></div> <div class="clearfix"></div>
......
...@@ -39,10 +39,17 @@ function (angular, _) { ...@@ -39,10 +39,17 @@ function (angular, _) {
if (_.isString(value)) { if (_.isString(value)) {
return value; return value;
} else { } else {
if (variable.multiFormat === 'regex values') { switch(variable.multiFormat) {
return '(' + value.join('|') + ')'; case "regex values": {
return '(' + value.join('|') + ')';
}
case "lucene": {
return '(' + value.join(' OR ') + ')';
}
default: {
return '{' + value.join(',') + '}';
}
} }
return '{' + value.join(',') + '}';
} }
}; };
......
...@@ -253,21 +253,29 @@ function (angular, _, kbn) { ...@@ -253,21 +253,29 @@ function (angular, _, kbn) {
this.addAllOption = function(variable) { this.addAllOption = function(variable) {
var allValue = ''; var allValue = '';
switch(variable.allFormat) { switch(variable.allFormat) {
case 'wildcard': case 'wildcard': {
allValue = '*'; allValue = '*';
break; break;
case 'regex wildcard': }
allValue = '.*'; case 'regex wildcard': {
break; allValue = '.*';
case 'regex values': break;
allValue = '(' + _.map(variable.options, function(option) { }
return self.regexEscape(option.text); case 'lucene': {
}).join('|') + ')'; allValue = '(' + _.pluck(variable.options, 'text').join(' OR ') + ')';
break; break;
default: }
allValue = '{'; case 'regex values': {
allValue += _.pluck(variable.options, 'text').join(','); allValue = '(' + _.map(variable.options, function(option) {
allValue += '}'; return self.regexEscape(option.text);
}).join('|') + ')';
break;
}
default: {
allValue = '{';
allValue += _.pluck(variable.options, 'text').join(',');
allValue += '}';
}
} }
variable.options.unshift({text: 'All', value: allValue}); variable.options.unshift({text: 'All', value: allValue});
......
...@@ -233,6 +233,9 @@ function (angular, _, moment, kbn, ElasticQueryBuilder, IndexPattern, ElasticRes ...@@ -233,6 +233,9 @@ function (angular, _, moment, kbn, ElasticQueryBuilder, IndexPattern, ElasticRes
ElasticDatasource.prototype.metricFindQuery = function(query) { ElasticDatasource.prototype.metricFindQuery = function(query) {
query = templateSrv.replace(query); query = templateSrv.replace(query);
query = angular.fromJson(query); query = angular.fromJson(query);
if (!query) {
return $q.when([]);
}
if (query.find === 'fields') { if (query.find === 'fields') {
return this.getFields(query); return this.getFields(query);
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
"annotations": "app/plugins/datasource/elasticsearch/partials/annotations.editor.html" "annotations": "app/plugins/datasource/elasticsearch/partials/annotations.editor.html"
}, },
"defaultMatchFormat": "lucene",
"annotations": true, "annotations": true,
"metrics": true "metrics": true
} }
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
"config": "app/plugins/datasource/graphite/partials/config.html" "config": "app/plugins/datasource/graphite/partials/config.html"
}, },
"defaultMatchFormat": "glob",
"metrics": true, "metrics": true,
"annotations": true "annotations": true
} }
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
"config": "app/plugins/datasource/influxdb/partials/config.html" "config": "app/plugins/datasource/influxdb/partials/config.html"
}, },
"defaultMatchFormat": "regex values",
"metrics": true, "metrics": true,
"annotations": true "annotations": true
} }
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
"config": "app/plugins/datasource/influxdb_08/partials/config.html" "config": "app/plugins/datasource/influxdb_08/partials/config.html"
}, },
"defaultMatchFormat": "regex values",
"metrics": true, "metrics": true,
"annotations": true "annotations": true
} }
...@@ -61,6 +61,16 @@ define([ ...@@ -61,6 +61,16 @@ define([
expect(result).to.be('{test,test2}'); expect(result).to.be('{test,test2}');
}); });
it('multi value and lucene should render as lucene expr', function() {
var result = _templateSrv.renderVariableValue({
multiFormat: 'lucene',
current: {
value: ['test','test2'],
}
});
expect(result).to.be('(test OR test2)');
});
it('multi value and regex format should render regex string', function() { it('multi value and regex format should render regex string', function() {
var result = _templateSrv.renderVariableValue({ var result = _templateSrv.renderVariableValue({
multiFormat: 'regex values', multiFormat: 'regex values',
......
...@@ -314,6 +314,17 @@ define([ ...@@ -314,6 +314,17 @@ define([
}); });
}); });
describeUpdateVariable('with include all lucene and values', function(scenario) {
scenario.setup(function() {
scenario.variable = { type: 'query', query: 'apps.*', name: 'test', includeAll: true, allFormat: 'lucene' };
scenario.queryResult = [{text: 'backend1'}, { text: 'backend2'}];
});
it('should add lucene glob', function() {
expect(scenario.variable.options[0].value).to.be('(backend1 OR backend2)');
});
});
describeUpdateVariable('with include all regex all values', function(scenario) { describeUpdateVariable('with include all regex all values', function(scenario) {
scenario.setup(function() { scenario.setup(function() {
scenario.variable = { type: 'query', query: 'apps.*', name: 'test', includeAll: true, allFormat: 'regex values' }; scenario.variable = { type: 'query', query: 'apps.*', name: 'test', includeAll: true, allFormat: 'regex values' };
......
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