diff --git a/x-pack/plugins/task_manager/server/lib/create_managed_configuration.test.ts b/x-pack/plugins/task_manager/server/lib/create_managed_configuration.test.ts index 5e0a5ed4f2e67..1da1bb11d1c5d 100644 --- a/x-pack/plugins/task_manager/server/lib/create_managed_configuration.test.ts +++ b/x-pack/plugins/task_manager/server/lib/create_managed_configuration.test.ts @@ -185,6 +185,17 @@ describe('createManagedConfiguration()', () => { expect(subscription).toHaveBeenNthCalledWith(2, 8); }); + test('should decrease configuration at the next interval when a 500 error is emitted', async () => { + const { subscription, errors$ } = setupScenario(10); + errors$.next(SavedObjectsErrorHelpers.decorateGeneralError(new Error('a'), 'b')); + clock.tick(ADJUST_THROUGHPUT_INTERVAL - 1); + expect(subscription).toHaveBeenCalledTimes(1); + expect(subscription).toHaveBeenNthCalledWith(1, 10); + clock.tick(1); + expect(subscription).toHaveBeenCalledTimes(2); + expect(subscription).toHaveBeenNthCalledWith(2, 8); + }); + test('should decrease configuration at the next interval when a 503 error is emitted', async () => { const { subscription, errors$ } = setupScenario(10); errors$.next(SavedObjectsErrorHelpers.createGenericNotFoundEsUnavailableError('a', 'b')); @@ -247,6 +258,17 @@ describe('createManagedConfiguration()', () => { expect(subscription).toHaveBeenNthCalledWith(2, 8); }); + test('should decrease configuration at the next interval when an msearch 500 error is emitted', async () => { + const { subscription, errors$ } = setupScenario(10); + errors$.next(new MsearchError(500)); + clock.tick(ADJUST_THROUGHPUT_INTERVAL - 1); + expect(subscription).toHaveBeenCalledTimes(1); + expect(subscription).toHaveBeenNthCalledWith(1, 10); + clock.tick(1); + expect(subscription).toHaveBeenCalledTimes(2); + expect(subscription).toHaveBeenNthCalledWith(2, 8); + }); + test('should decrease configuration at the next interval when an msearch 503 error is emitted', async () => { const { subscription, errors$ } = setupScenario(10); errors$.next(new MsearchError(503)); @@ -338,6 +360,16 @@ describe('createManagedConfiguration()', () => { expect(subscription).toHaveBeenNthCalledWith(2, 120); }); + test('should increase configuration at the next interval when a 500 error is emitted', async () => { + const { subscription, errors$ } = setupScenario(100); + errors$.next(SavedObjectsErrorHelpers.decorateGeneralError(new Error('a'), 'b')); + clock.tick(ADJUST_THROUGHPUT_INTERVAL - 1); + expect(subscription).toHaveBeenCalledTimes(1); + clock.tick(1); + expect(subscription).toHaveBeenCalledTimes(2); + expect(subscription).toHaveBeenNthCalledWith(2, 120); + }); + test('should increase configuration at the next interval when a 503 error is emitted', async () => { const { subscription, errors$ } = setupScenario(100); errors$.next(SavedObjectsErrorHelpers.createGenericNotFoundEsUnavailableError('a', 'b')); diff --git a/x-pack/plugins/task_manager/server/lib/create_managed_configuration.ts b/x-pack/plugins/task_manager/server/lib/create_managed_configuration.ts index 8a76029efb8eb..d13c2511a2a2b 100644 --- a/x-pack/plugins/task_manager/server/lib/create_managed_configuration.ts +++ b/x-pack/plugins/task_manager/server/lib/create_managed_configuration.ts @@ -165,8 +165,10 @@ function countErrors(errors$: Observable, countInterval: number): Observa (e) => SavedObjectsErrorHelpers.isTooManyRequestsError(e) || SavedObjectsErrorHelpers.isEsUnavailableError(e) || + SavedObjectsErrorHelpers.isGeneralError(e) || isEsCannotExecuteScriptError(e) || getMsearchStatusCode(e) === 429 || + getMsearchStatusCode(e) === 500 || getMsearchStatusCode(e) === 503 ) )