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', () => {
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))
);
};
......
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