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

View File

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

View File

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