Loki: Re-introduce running of instant queries (#27213)

* Run instant queries for loki

* Add catch for instant query errors, update test
pull/26933/head
Ivana Huckova 5 years ago committed by GitHub
parent 262a42b249
commit 58627a0c38
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      public/app/plugins/datasource/loki/datasource.test.ts
  2. 10
      public/app/plugins/datasource/loki/datasource.ts

@ -114,7 +114,7 @@ describe('LokiDatasource', () => {
datasourceRequestMock.mockImplementation(() => Promise.resolve(testResp));
});
test('should just run range query when in logs mode', async () => {
test('should run range and instant query', async () => {
const options = getQueryOptions<LokiQuery>({
targets: [{ expr: '{job="grafana"}', refId: 'B' }],
});
@ -123,7 +123,7 @@ describe('LokiDatasource', () => {
ds.runRangeQuery = jest.fn(() => of({ data: [] }));
await ds.query(options).toPromise();
expect(ds.runInstantQuery).not.toBeCalled();
expect(ds.runInstantQuery).toBeCalled();
expect(ds.runRangeQuery).toBeCalled();
});
@ -185,7 +185,7 @@ describe('LokiDatasource', () => {
const ds = new LokiDatasource(customSettings, templateSrvMock);
datasourceRequestMock.mockImplementation(
jest.fn().mockReturnValueOnce(
jest.fn().mockReturnValue(
Promise.reject({
data: {
message: 'parse error at line 1, col 6: invalid char escape',
@ -494,7 +494,7 @@ function makeLimitTest(instanceSettings: any, datasourceRequestMock: any, templa
ds.query(options);
expect(datasourceRequestMock.mock.calls.length).toBe(1);
expect(datasourceRequestMock.mock.calls.length).toBe(2);
expect(datasourceRequestMock.mock.calls[0][0].url).toContain(`limit=${expectedLimit}`);
};
}

@ -91,7 +91,12 @@ export class LokiDatasource extends DataSourceApi<LokiQuery, LokiOptions> {
expr: this.templateSrv.replace(target.expr, options.scopedVars, this.interpolateQueryExpr),
}));
filteredTargets.forEach(target => subQueries.push(this.runRangeQuery(target, options, filteredTargets.length)));
filteredTargets.forEach(target =>
subQueries.push(
this.runInstantQuery(target, options, filteredTargets.length),
this.runRangeQuery(target, options, filteredTargets.length)
)
);
// No valid targets, return the empty result to save a round trip.
if (isEmpty(subQueries)) {
@ -133,7 +138,8 @@ export class LokiDatasource extends DataSourceApi<LokiQuery, LokiOptions> {
data: [lokiResultsToTableModel(response.data.data.result, responseListLength, target.refId, meta, true)],
key: `${target.refId}_instant`,
};
})
}),
catchError((err: any) => this.throwUnless(err, err.status === 404, target))
);
};

Loading…
Cancel
Save