mirror of
https://github.com/grafana/grafana.git
synced 2024-11-30 20:54:22 -06:00
Merge branch 'v3.0.x'
This commit is contained in:
commit
93665f49b1
@ -42,6 +42,16 @@ function (angular, _) {
|
|||||||
return value.replace(/([\!\*\+\-\=<>\s\&\|\(\)\[\]\{\}\^\~\?\:\\/"])/g, "\\$1");
|
return value.replace(/([\!\*\+\-\=<>\s\&\|\(\)\[\]\{\}\^\~\?\:\\/"])/g, "\\$1");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.luceneFormat = function(value) {
|
||||||
|
if (typeof value === 'string') {
|
||||||
|
return luceneEscape(value);
|
||||||
|
}
|
||||||
|
var quotedValues = _.map(value, function(val) {
|
||||||
|
return '\"' + luceneEscape(val) + '\"';
|
||||||
|
});
|
||||||
|
return '(' + quotedValues.join(' OR ') + ')';
|
||||||
|
};
|
||||||
|
|
||||||
this.formatValue = function(value, format, variable) {
|
this.formatValue = function(value, format, variable) {
|
||||||
// for some scopedVars there is no variable
|
// for some scopedVars there is no variable
|
||||||
variable = variable || {};
|
variable = variable || {};
|
||||||
@ -60,13 +70,7 @@ function (angular, _) {
|
|||||||
return '(' + escapedValues.join('|') + ')';
|
return '(' + escapedValues.join('|') + ')';
|
||||||
}
|
}
|
||||||
case "lucene": {
|
case "lucene": {
|
||||||
if (typeof value === 'string') {
|
return this.luceneFormat(value, format, variable);
|
||||||
return luceneEscape(value);
|
|
||||||
}
|
|
||||||
var quotedValues = _.map(value, function(val) {
|
|
||||||
return '\"' + luceneEscape(val) + '\"';
|
|
||||||
});
|
|
||||||
return '(' + quotedValues.join(' OR ') + ')';
|
|
||||||
}
|
}
|
||||||
case "pipe": {
|
case "pipe": {
|
||||||
if (typeof value === 'string') {
|
if (typeof value === 'string') {
|
||||||
|
@ -78,7 +78,7 @@ function (angular, _, moment, kbn, ElasticQueryBuilder, IndexPattern, ElasticRes
|
|||||||
range[timeField]["format"] = "epoch_millis";
|
range[timeField]["format"] = "epoch_millis";
|
||||||
}
|
}
|
||||||
|
|
||||||
var queryInterpolated = templateSrv.replace(queryString);
|
var queryInterpolated = templateSrv.replace(queryString, {}, 'lucene');
|
||||||
var filter = { "bool": { "must": [{ "range": range }] } };
|
var filter = { "bool": { "must": [{ "range": range }] } };
|
||||||
var query = { "bool": { "should": [{ "query_string": { "query": queryInterpolated } }] } };
|
var query = { "bool": { "should": [{ "query_string": { "query": queryInterpolated } }] } };
|
||||||
var data = {
|
var data = {
|
||||||
@ -204,6 +204,14 @@ function (angular, _, moment, kbn, ElasticQueryBuilder, IndexPattern, ElasticRes
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function escapeForJson(value) {
|
||||||
|
return value.replace(/\"/g, '\\"');
|
||||||
|
}
|
||||||
|
|
||||||
|
function luceneThenJsonFormat(value) {
|
||||||
|
return escapeForJson(templateSrv.luceneFormat(value));
|
||||||
|
}
|
||||||
|
|
||||||
this.getFields = function(query) {
|
this.getFields = function(query) {
|
||||||
return this._get('/_mapping').then(function(res) {
|
return this._get('/_mapping').then(function(res) {
|
||||||
var fields = {};
|
var fields = {};
|
||||||
@ -246,7 +254,7 @@ function (angular, _, moment, kbn, ElasticQueryBuilder, IndexPattern, ElasticRes
|
|||||||
var header = this.getQueryHeader('count', range.from, range.to);
|
var header = this.getQueryHeader('count', range.from, range.to);
|
||||||
var esQuery = angular.toJson(this.queryBuilder.getTermsQuery(queryDef));
|
var esQuery = angular.toJson(this.queryBuilder.getTermsQuery(queryDef));
|
||||||
|
|
||||||
esQuery = esQuery.replace("$lucene_query", queryDef.query || '*');
|
esQuery = esQuery.replace("$lucene_query", escapeForJson(queryDef.query || '*'));
|
||||||
esQuery = esQuery.replace(/\$timeFrom/g, range.from.valueOf());
|
esQuery = esQuery.replace(/\$timeFrom/g, range.from.valueOf());
|
||||||
esQuery = esQuery.replace(/\$timeTo/g, range.to.valueOf());
|
esQuery = esQuery.replace(/\$timeTo/g, range.to.valueOf());
|
||||||
esQuery = header + '\n' + esQuery + '\n';
|
esQuery = header + '\n' + esQuery + '\n';
|
||||||
@ -260,7 +268,7 @@ function (angular, _, moment, kbn, ElasticQueryBuilder, IndexPattern, ElasticRes
|
|||||||
};
|
};
|
||||||
|
|
||||||
this.metricFindQuery = function(query) {
|
this.metricFindQuery = function(query) {
|
||||||
query = templateSrv.replace(query);
|
query = templateSrv.replace(query, {}, luceneThenJsonFormat);
|
||||||
query = angular.fromJson(query);
|
query = angular.fromJson(query);
|
||||||
if (!query) {
|
if (!query) {
|
||||||
return $q.when([]);
|
return $q.when([]);
|
||||||
|
Loading…
Reference in New Issue
Block a user