mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Loki: Re-introduce running of instant queries (#27213)
* Run instant queries for loki * Add catch for instant query errors, update test
This commit is contained in:
@@ -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))
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user