Commit 58627a0c by Ivana Huckova Committed by GitHub

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

* Run instant queries for loki

* Add catch for instant query errors, update test
parent 262a42b2
...@@ -114,7 +114,7 @@ describe('LokiDatasource', () => { ...@@ -114,7 +114,7 @@ describe('LokiDatasource', () => {
datasourceRequestMock.mockImplementation(() => Promise.resolve(testResp)); 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>({ const options = getQueryOptions<LokiQuery>({
targets: [{ expr: '{job="grafana"}', refId: 'B' }], targets: [{ expr: '{job="grafana"}', refId: 'B' }],
}); });
...@@ -123,7 +123,7 @@ describe('LokiDatasource', () => { ...@@ -123,7 +123,7 @@ describe('LokiDatasource', () => {
ds.runRangeQuery = jest.fn(() => of({ data: [] })); ds.runRangeQuery = jest.fn(() => of({ data: [] }));
await ds.query(options).toPromise(); await ds.query(options).toPromise();
expect(ds.runInstantQuery).not.toBeCalled(); expect(ds.runInstantQuery).toBeCalled();
expect(ds.runRangeQuery).toBeCalled(); expect(ds.runRangeQuery).toBeCalled();
}); });
...@@ -185,7 +185,7 @@ describe('LokiDatasource', () => { ...@@ -185,7 +185,7 @@ describe('LokiDatasource', () => {
const ds = new LokiDatasource(customSettings, templateSrvMock); const ds = new LokiDatasource(customSettings, templateSrvMock);
datasourceRequestMock.mockImplementation( datasourceRequestMock.mockImplementation(
jest.fn().mockReturnValueOnce( jest.fn().mockReturnValue(
Promise.reject({ Promise.reject({
data: { data: {
message: 'parse error at line 1, col 6: invalid char escape', message: 'parse error at line 1, col 6: invalid char escape',
...@@ -494,7 +494,7 @@ function makeLimitTest(instanceSettings: any, datasourceRequestMock: any, templa ...@@ -494,7 +494,7 @@ function makeLimitTest(instanceSettings: any, datasourceRequestMock: any, templa
ds.query(options); 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}`); expect(datasourceRequestMock.mock.calls[0][0].url).toContain(`limit=${expectedLimit}`);
}; };
} }
......
...@@ -91,7 +91,12 @@ export class LokiDatasource extends DataSourceApi<LokiQuery, LokiOptions> { ...@@ -91,7 +91,12 @@ export class LokiDatasource extends DataSourceApi<LokiQuery, LokiOptions> {
expr: this.templateSrv.replace(target.expr, options.scopedVars, this.interpolateQueryExpr), 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. // No valid targets, return the empty result to save a round trip.
if (isEmpty(subQueries)) { if (isEmpty(subQueries)) {
...@@ -133,7 +138,8 @@ export class LokiDatasource extends DataSourceApi<LokiQuery, LokiOptions> { ...@@ -133,7 +138,8 @@ export class LokiDatasource extends DataSourceApi<LokiQuery, LokiOptions> {
data: [lokiResultsToTableModel(response.data.data.result, responseListLength, target.refId, meta, true)], data: [lokiResultsToTableModel(response.data.data.result, responseListLength, target.refId, meta, true)],
key: `${target.refId}_instant`, key: `${target.refId}_instant`,
}; };
}) }),
catchError((err: any) => this.throwUnless(err, err.status === 404, target))
); );
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment