mirror of
https://github.com/grafana/grafana.git
synced 2025-02-14 17:43:35 -06:00
Review feedback.
This commit is contained in:
parent
e62c083cf0
commit
bf8840255c
@ -264,7 +264,7 @@ export class PromCompleter {
|
||||
return Promise.resolve([]);
|
||||
}
|
||||
|
||||
getLabelNameAndValueForExpression(expr, type) {
|
||||
getLabelNameAndValueForExpression(expr: string, type: string): Promise<any> {
|
||||
if (this.labelQueryCache[expr]) {
|
||||
return Promise.resolve(this.labelQueryCache[expr]);
|
||||
}
|
||||
@ -276,8 +276,8 @@ export class PromCompleter {
|
||||
}
|
||||
query = '{__name__' + op + '"' + expr + '"}';
|
||||
}
|
||||
let range = this.datasource.getTimeRange();
|
||||
let url = '/api/v1/series?match[]=' + encodeURIComponent(query) + '&start=' + range.from + '&end=' + range.to;
|
||||
const { start, end } = this.datasource.getTimeRange();
|
||||
const url = '/api/v1/series?match[]=' + encodeURIComponent(query) + '&start=' + start + '&end=' + end;
|
||||
return this.datasource.metadataRequest(url).then(response => {
|
||||
this.labelQueryCache[expr] = response.data.data;
|
||||
return response.data.data;
|
||||
|
@ -629,11 +629,11 @@ export class PrometheusDatasource {
|
||||
return Math.ceil(date.valueOf() / 1000);
|
||||
}
|
||||
|
||||
getTimeRange() {
|
||||
getTimeRange(): { start: number; end: number } {
|
||||
let range = this.timeSrv.timeRange();
|
||||
return {
|
||||
from: this.getPrometheusTime(range.from, false),
|
||||
to: this.getPrometheusTime(range.to, true)
|
||||
start: this.getPrometheusTime(range.from, false),
|
||||
end: this.getPrometheusTime(range.to, true),
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -4,7 +4,7 @@ import { BackendSrv } from 'app/core/services/backend_srv';
|
||||
jest.mock('../datasource');
|
||||
jest.mock('app/core/services/backend_srv');
|
||||
|
||||
describe('Prometheus editor completer', function () {
|
||||
describe('Prometheus editor completer', function() {
|
||||
function getSessionStub(data) {
|
||||
return {
|
||||
getTokenAt: jest.fn(() => data.currentToken),
|
||||
@ -19,8 +19,11 @@ describe('Prometheus editor completer', function () {
|
||||
const datasourceStub = new PrometheusDatasource({}, {}, backendSrv, {}, {});
|
||||
|
||||
datasourceStub.metadataRequest = jest.fn(() =>
|
||||
Promise.resolve({ data: { data: [{ metric: { job: 'node', instance: 'localhost:9100', }, },], }, }));
|
||||
datasourceStub.getTimeRange = jest.fn(() => { return { from: 1514732400, to: 1514818800 }; });
|
||||
Promise.resolve({ data: { data: [{ metric: { job: 'node', instance: 'localhost:9100' } }] } })
|
||||
);
|
||||
datasourceStub.getTimeRange = jest.fn(() => {
|
||||
return { start: 1514732400, end: 1514818800 };
|
||||
});
|
||||
datasourceStub.performSuggestQuery = jest.fn(() => Promise.resolve(['node_cpu']));
|
||||
|
||||
const templateSrv = {
|
||||
|
Loading…
Reference in New Issue
Block a user