Commit 0a0a0776 by Torkel Ödegaard

Merge pull request #3088 from utkarshcmu/suggest-opentsdb

Tag suggestions fixed for v2.1.1 & above by using Suggest Api.
parents 59d199a1 a27186e3
......@@ -40,8 +40,10 @@ Grafana's OpenTSDB data source now supports template variable values queries. Th
When using OpenTSDB with a template variable of `query` type you can use following syntax for lookup.
metrics() // returns metric names
metrics(prefix) // returns metric names with specific prefix (can be empty)
tag_names(cpu) // return tag names (i.e. keys) for a specific cpu metric
tag_values(cpu, hostname) // return tag values for metric cpu and tag key hostname
suggest_tagk(prefix) // return tag names (i.e. keys) for all metrics with specific prefix (can be empty)
suggest_tagv(prefix) // return tag values for all metrics with specific prefix (can be empty)
For details on opentsdb metric queries checkout the official [OpenTSDB documentation](http://opentsdb.net/docs/build/html/index.html)
\ No newline at end of file
For details on opentsdb metric queries checkout the official [OpenTSDB documentation](http://opentsdb.net/docs/build/html/index.html)
......@@ -80,8 +80,8 @@ function (angular, _, dateMath) {
return backendSrv.datasourceRequest(options);
};
OpenTSDBDatasource.prototype._performSuggestQuery = function(query) {
return this._get('/api/suggest', {type: 'metrics', q: query, max: 1000}).then(function(result) {
OpenTSDBDatasource.prototype._performSuggestQuery = function(query, type) {
return this._get('/api/suggest', {type: type, q: query, max: 1000}).then(function(result) {
return result.data;
});
};
......@@ -150,10 +150,12 @@ function (angular, _, dateMath) {
var metrics_regex = /metrics\((.*)\)/;
var tag_names_regex = /tag_names\((.*)\)/;
var tag_values_regex = /tag_values\((.*),\s?(.*)\)/;
var tag_names_suggest_regex = /suggest_tagk\((.*)\)/;
var tag_values_suggest_regex = /suggest_tagv\((.*)\)/;
var metrics_query = interpolated.match(metrics_regex);
if (metrics_query) {
return this._performSuggestQuery(metrics_query[1]).then(responseTransform);
return this._performSuggestQuery(metrics_query[1], 'metrics').then(responseTransform);
}
var tag_names_query = interpolated.match(tag_names_regex);
......@@ -166,6 +168,16 @@ function (angular, _, dateMath) {
return this._performMetricKeyValueLookup(tag_values_query[1], tag_values_query[2]).then(responseTransform);
}
var tag_names_suggest_query = interpolated.match(tag_names_suggest_regex);
if (tag_names_suggest_query) {
return this._performSuggestQuery(tag_names_suggest_query[1], 'tagk').then(responseTransform);
}
var tag_values_suggest_query = interpolated.match(tag_values_suggest_regex);
if (tag_values_suggest_query) {
return this._performSuggestQuery(tag_values_suggest_query[1], 'tagv').then(responseTransform);
}
return $q.when([]);
};
......
......@@ -48,13 +48,13 @@ function (angular, _, kbn) {
};
$scope.suggestTagKeys = function(query, callback) {
$scope.datasource.metricFindQuery('tag_names(' + $scope.target.metric + ')')
$scope.datasource.metricFindQuery('suggest_tagk(' + query + ')')
.then($scope.getTextValues)
.then(callback);
};
$scope.suggestTagValues = function(query, callback) {
$scope.datasource.metricFindQuery('tag_values(' + $scope.target.metric + ',' + $scope.target.currentTagKey + ')')
$scope.datasource.metricFindQuery('suggest_tagv(' + query + ')')
.then($scope.getTextValues)
.then(callback);
};
......
......@@ -27,9 +27,11 @@ define([
});
it('metrics() should generate api suggest query', function() {
ctx.ds.metricFindQuery('metrics()').then(function(data) { results = data; });
ctx.ds.metricFindQuery('metrics(pew)').then(function(data) { results = data; });
ctx.$rootScope.$apply();
expect(requestOptions.url).to.be('/api/suggest');
expect(requestOptions.params.type).to.be('metrics');
expect(requestOptions.params.q).to.be('pew');
});
it('tag_names(cpu) should generate looku query', function() {
......@@ -46,6 +48,22 @@ define([
expect(requestOptions.params.m).to.be('cpu{hostname=*}');
});
it('suggest_tagk() should generate api suggest query', function() {
ctx.ds.metricFindQuery('suggest_tagk(foo)').then(function(data) { results = data; });
ctx.$rootScope.$apply();
expect(requestOptions.url).to.be('/api/suggest');
expect(requestOptions.params.type).to.be('tagk');
expect(requestOptions.params.q).to.be('foo');
});
it('suggest_tagv() should generate api suggest query', function() {
ctx.ds.metricFindQuery('suggest_tagv(bar)').then(function(data) { results = data; });
ctx.$rootScope.$apply();
expect(requestOptions.url).to.be('/api/suggest');
expect(requestOptions.params.type).to.be('tagv');
expect(requestOptions.params.q).to.be('bar');
});
});
});
});
......
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