mirror of
https://github.com/grafana/grafana.git
synced 2025-02-16 02:23:31 -06:00
fix templating undefined error (#10004)
This commit is contained in:
parent
d6d64c53cd
commit
e8a6af7b22
@ -67,8 +67,8 @@ export default class PrometheusMetricFindQuery {
|
||||
|
||||
return this.datasource._request("GET", url).then(function(result) {
|
||||
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 {
|
||||
|
@ -76,6 +76,24 @@ describe('PrometheusMetricFindQuery', function() {
|
||||
ctx.$rootScope.$apply();
|
||||
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() {
|
||||
response = {
|
||||
status: "success",
|
||||
|
Loading…
Reference in New Issue
Block a user