mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Merge branch 'time-independent-prometheus-metrics' of https://github.com/arthurdandrea/grafana into arthurdandrea-time-independent-prometheus-metrics
This commit is contained in:
@@ -148,20 +148,13 @@ function (angular, _, moment, dateMath) {
|
||||
});
|
||||
});
|
||||
} else {
|
||||
var metric_query = 'count(' + label_values_query[1] + ') by (' +
|
||||
label_values_query[2] + ')';
|
||||
url = '/api/v1/query?query=' + encodeURIComponent(metric_query) +
|
||||
'&time=' + (moment().valueOf() / 1000);
|
||||
url = '/api/v1/series?match[]=' + encodeURIComponent(label_values_query[1]);
|
||||
|
||||
return this._request('GET', url)
|
||||
.then(function(result) {
|
||||
if (result.data.data.result.length === 0 ||
|
||||
_.keys(result.data.data.result[0].metric).length === 0) {
|
||||
return [];
|
||||
}
|
||||
return _.map(result.data.data.result, function(metricValue) {
|
||||
return _.map(result.data.data, function(metric) {
|
||||
return {
|
||||
text: metricValue.metric[label_values_query[2]],
|
||||
text: metric[label_values_query[2]],
|
||||
expandable: true
|
||||
};
|
||||
});
|
||||
@@ -190,14 +183,13 @@ function (angular, _, moment, dateMath) {
|
||||
});
|
||||
} else {
|
||||
// if query contains full metric name, return metric name and label list
|
||||
url = '/api/v1/query?query=' + encodeURIComponent(interpolated) +
|
||||
'&time=' + (moment().valueOf() / 1000);
|
||||
url = '/api/v1/series?match[]=' + encodeURIComponent(interpolated);
|
||||
|
||||
return this._request('GET', url)
|
||||
.then(function(result) {
|
||||
return _.map(result.data.data.result, function(metricData) {
|
||||
return _.map(result.data.data, function(metric) {
|
||||
return {
|
||||
text: getOriginalMetricName(metricData.metric),
|
||||
text: getOriginalMetricName(metric),
|
||||
expandable: true
|
||||
};
|
||||
});
|
||||
|
||||
@@ -59,19 +59,16 @@ describe('PrometheusDatasource', function() {
|
||||
ctx.$rootScope.$apply();
|
||||
expect(results.length).to.be(3);
|
||||
});
|
||||
it('label_values(metric, resource) should generate count metric query', function() {
|
||||
it('label_values(metric, resource) should generate series query', function() {
|
||||
response = {
|
||||
status: "success",
|
||||
data: {
|
||||
resultType: "vector",
|
||||
result: [
|
||||
{metric: {resource: "value1"}, value: []},
|
||||
{metric: {resource: "value2"}, value: []},
|
||||
{metric: {resource: "value3"}, value: []}
|
||||
]
|
||||
}
|
||||
data: [
|
||||
{__name__: "metric", resource: "value1"},
|
||||
{__name__: "metric", resource: "value2"},
|
||||
{__name__: "metric", resource: "value3"}
|
||||
]
|
||||
};
|
||||
ctx.$httpBackend.expect('GET', /proxied\/api\/v1\/query\?query=count\(metric\)%20by%20\(resource\)&time=.*/).respond(response);
|
||||
ctx.$httpBackend.expect('GET', 'proxied/api/v1/series?match[]=metric').respond(response);
|
||||
ctx.ds.metricFindQuery('label_values(metric, resource)').then(function(data) { results = data; });
|
||||
ctx.$httpBackend.flush();
|
||||
ctx.$rootScope.$apply();
|
||||
@@ -90,4 +87,3 @@ describe('PrometheusDatasource', function() {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user