Commit e8a6af7b by Mitsuhiro Tanda Committed by Torkel Ödegaard

fix templating undefined error (#10004)

parent d6d64c53
...@@ -67,8 +67,8 @@ export default class PrometheusMetricFindQuery { ...@@ -67,8 +67,8 @@ export default class PrometheusMetricFindQuery {
return this.datasource._request("GET", url).then(function(result) { return this.datasource._request("GET", url).then(function(result) {
var _labels = _.map(result.data.data, function(metric) { var _labels = _.map(result.data.data, function(metric) {
return metric[label]; return metric[label] || '';
}); }).filter(function(label) { return label !== ''; });
return _.uniq(_labels).map(function(metric) { return _.uniq(_labels).map(function(metric) {
return { return {
......
...@@ -76,6 +76,24 @@ describe('PrometheusMetricFindQuery', function() { ...@@ -76,6 +76,24 @@ describe('PrometheusMetricFindQuery', function() {
ctx.$rootScope.$apply(); ctx.$rootScope.$apply();
expect(results.length).to.be(3); expect(results.length).to.be(3);
}); });
it('label_values(metric, resource) result should not contain empty string', function() {
response = {
status: "success",
data: [
{__name__: "metric", resource: "value1"},
{__name__: "metric", resource: "value2"},
{__name__: "metric", resource: ""}
]
};
ctx.$httpBackend.expect('GET', /proxied\/api\/v1\/series\?match\[\]=metric&start=.*&end=.*/).respond(response);
var pm = new PrometheusMetricFindQuery(ctx.ds, 'label_values(metric, resource)', ctx.timeSrv);
pm.process().then(function(data) { results = data; });
ctx.$httpBackend.flush();
ctx.$rootScope.$apply();
expect(results.length).to.be(2);
expect(results[0].text).to.be("value1");
expect(results[1].text).to.be("value2");
});
it('metrics(metric.*) should generate metric name query', function() { it('metrics(metric.*) should generate metric name query', function() {
response = { response = {
status: "success", 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