Commit 6fd0d5e2 by Torkel Ödegaard

Merge pull request #4178 from mtanda/prometheus_template_label

(prometheus) fix label_values() templating
parents b9e0fcdf 3125177e
......@@ -11,16 +11,16 @@ function (_, moment) {
}
PrometheusMetricFindQuery.prototype.process = function() {
var label_values_regex = /^label_values\(([^,]+)(?:,\s*(.+))?\)$/;
var label_values_regex = /^label_values\((?:(.+),\s*)?([a-zA-Z_][a-zA-Z0-9_]+)\)$/;
var metric_names_regex = /^metrics\((.+)\)$/;
var query_result_regex = /^query_result\((.+)\)$/;
var label_values_query = this.query.match(label_values_regex);
if (label_values_query) {
if (label_values_query[2]) {
if (label_values_query[1]) {
return this.labelValuesQuery(label_values_query[2], label_values_query[1]);
} else {
return this.labelValuesQuery(label_values_query[1], null);
return this.labelValuesQuery(label_values_query[2], null);
}
}
......
......@@ -48,6 +48,22 @@ describe('PrometheusMetricFindQuery', function() {
ctx.$rootScope.$apply();
expect(results.length).to.be(3);
});
it('label_values(metric{label1="foo", label2="bar", label3="baz"}, resource) should generate series query', function() {
response = {
status: "success",
data: [
{__name__: "metric", resource: "value1"},
{__name__: "metric", resource: "value2"},
{__name__: "metric", resource: "value3"}
]
};
ctx.$httpBackend.expect('GET', 'proxied/api/v1/series?match[]=metric').respond(response);
var pm = new PrometheusMetricFindQuery(ctx.ds, 'label_values(metric, resource)');
pm.process().then(function(data) { results = data; });
ctx.$httpBackend.flush();
ctx.$rootScope.$apply();
expect(results.length).to.be(3);
});
it('metrics(metric.*) should generate metric name query', function() {
response = {
status: "success",
......
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