Shard query splitting: stop querying on failure (#96284)

Shard query splitting: stop querying on final errors
This commit is contained in:
Matias Chomicki 2024-11-12 17:46:25 +00:00 committed by GitHub
parent e9956f2345
commit 01d2376782
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 12 additions and 5 deletions

View File

@ -18,6 +18,10 @@ jest.mock('uuid', () => ({
})); }));
const originalShardingFlagState = config.featureToggles.lokiShardSplitting; const originalShardingFlagState = config.featureToggles.lokiShardSplitting;
const originalErr = console.error;
beforeEach(() => {
jest.spyOn(console, 'error').mockImplementation(() => {});
});
beforeAll(() => { beforeAll(() => {
// @ts-expect-error // @ts-expect-error
jest.spyOn(global, 'setTimeout').mockImplementation((callback) => { jest.spyOn(global, 'setTimeout').mockImplementation((callback) => {
@ -28,6 +32,7 @@ beforeAll(() => {
afterAll(() => { afterAll(() => {
jest.mocked(global.setTimeout).mockReset(); jest.mocked(global.setTimeout).mockReset();
config.featureToggles.lokiShardSplitting = originalShardingFlagState; config.featureToggles.lokiShardSplitting = originalShardingFlagState;
console.error = originalErr;
}); });
describe('runSplitQuery()', () => { describe('runSplitQuery()', () => {

View File

@ -138,9 +138,9 @@ export function isRetriableError(errorResponse: DataQueryResponse) {
: (errorResponse.error?.message ?? ''); : (errorResponse.error?.message ?? '');
if (message.includes('timeout')) { if (message.includes('timeout')) {
return true; return true;
} else if (message.includes('parse error')) { } else if (errorResponse.data.length > 0 && errorResponse.data[0].fields.length > 0) {
// If the error is a parse error, we want to signal to stop querying. // Error response but we're receiving data, continue querying.
throw new Error(message); return false;
} }
return false; throw new Error(message);
} }

View File

@ -14,6 +14,7 @@ jest.mock('uuid', () => ({
const originalLog = console.log; const originalLog = console.log;
const originalWarn = console.warn; const originalWarn = console.warn;
const originalErr = console.error;
beforeEach(() => { beforeEach(() => {
jest.spyOn(console, 'log').mockImplementation(() => {}); jest.spyOn(console, 'log').mockImplementation(() => {});
jest.spyOn(console, 'warn').mockImplementation(() => {}); jest.spyOn(console, 'warn').mockImplementation(() => {});
@ -22,6 +23,7 @@ beforeEach(() => {
afterAll(() => { afterAll(() => {
console.log = originalLog; console.log = originalLog;
console.warn = originalWarn; console.warn = originalWarn;
console.error = originalErr;
}); });
describe('runShardSplitQuery()', () => { describe('runShardSplitQuery()', () => {
@ -203,7 +205,7 @@ describe('runShardSplitQuery()', () => {
callback(); callback();
}); });
await expect(runShardSplitQuery(datasource, request)).toEmitValuesWith((response: DataQueryResponse[]) => { await expect(runShardSplitQuery(datasource, request)).toEmitValuesWith((response: DataQueryResponse[]) => {
expect(datasource.runQuery).toHaveBeenCalledTimes(2); expect(datasource.runQuery).toHaveBeenCalledTimes(1);
}); });
}); });