mirror of
https://github.com/grafana/grafana.git
synced 2025-09-27 07:33:57 +08:00
fix templating undefined error (#10004)
This commit is contained in:

committed by
Torkel Ödegaard

parent
d6d64c53cd
commit
e8a6af7b22
@ -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() {
|
|||||||
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",
|
||||||
|
Reference in New Issue
Block a user