-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
make
isInlineScriptingEnabled
resilient to ES errors (#170208)
## Summary Fix #163787 Change the way `isInlineScriptingEnabled` function to retry retryable errors from ES (similar to how the valid connection or migration ES calls do)
- Loading branch information
1 parent
d26b373
commit 8868d08
Showing
7 changed files
with
220 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
...e/elasticsearch/core-elasticsearch-server-internal/src/is_scripting_enabled.test.mocks.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
export const isRetryableEsClientErrorMock = jest.fn(); | ||
|
||
jest.doMock('./retryable_es_client_errors', () => { | ||
return { | ||
isRetryableEsClientError: isRetryableEsClientErrorMock, | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
...e/elasticsearch/core-elasticsearch-server-internal/src/retryable_es_client_errors.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { errors as esErrors } from '@elastic/elasticsearch'; | ||
import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks'; | ||
import { isRetryableEsClientError } from './retryable_es_client_errors'; | ||
|
||
describe('isRetryableEsClientError', () => { | ||
describe('returns `false` for', () => { | ||
test('non-retryable response errors', async () => { | ||
const error = new esErrors.ResponseError( | ||
elasticsearchClientMock.createApiResponse({ | ||
body: { error: { type: 'cluster_block_exception' } }, | ||
statusCode: 400, | ||
}) | ||
); | ||
|
||
expect(isRetryableEsClientError(error)).toEqual(false); | ||
}); | ||
}); | ||
|
||
describe('returns `true` for', () => { | ||
it('NoLivingConnectionsError', () => { | ||
const error = new esErrors.NoLivingConnectionsError( | ||
'reason', | ||
elasticsearchClientMock.createApiResponse() | ||
); | ||
|
||
expect(isRetryableEsClientError(error)).toEqual(true); | ||
}); | ||
|
||
it('ConnectionError', () => { | ||
const error = new esErrors.ConnectionError( | ||
'reason', | ||
elasticsearchClientMock.createApiResponse() | ||
); | ||
expect(isRetryableEsClientError(error)).toEqual(true); | ||
}); | ||
|
||
it('TimeoutError', () => { | ||
const error = new esErrors.TimeoutError( | ||
'reason', | ||
elasticsearchClientMock.createApiResponse() | ||
); | ||
expect(isRetryableEsClientError(error)).toEqual(true); | ||
}); | ||
|
||
it('ResponseError of type snapshot_in_progress_exception', () => { | ||
const error = new esErrors.ResponseError( | ||
elasticsearchClientMock.createApiResponse({ | ||
body: { error: { type: 'snapshot_in_progress_exception' } }, | ||
}) | ||
); | ||
expect(isRetryableEsClientError(error)).toEqual(true); | ||
}); | ||
|
||
it.each([503, 401, 403, 408, 410, 429])('ResponseError with %p status code', (statusCode) => { | ||
const error = new esErrors.ResponseError( | ||
elasticsearchClientMock.createApiResponse({ | ||
statusCode, | ||
body: { error: { type: 'reason' } }, | ||
}) | ||
); | ||
|
||
expect(isRetryableEsClientError(error)).toEqual(true); | ||
}); | ||
}); | ||
}); |
40 changes: 40 additions & 0 deletions
40
...s/core/elasticsearch/core-elasticsearch-server-internal/src/retryable_es_client_errors.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { errors as EsErrors } from '@elastic/elasticsearch'; | ||
|
||
const retryResponseStatuses = [ | ||
503, // ServiceUnavailable | ||
401, // AuthorizationException | ||
403, // AuthenticationException | ||
408, // RequestTimeout | ||
410, // Gone | ||
429, // TooManyRequests -> ES circuit breaker | ||
]; | ||
|
||
/** | ||
* Returns true if the given elasticsearch error should be retried | ||
* by retry-based resiliency systems such as the SO migration, false otherwise. | ||
*/ | ||
export const isRetryableEsClientError = (e: EsErrors.ElasticsearchClientError): boolean => { | ||
if ( | ||
e instanceof EsErrors.NoLivingConnectionsError || | ||
e instanceof EsErrors.ConnectionError || | ||
e instanceof EsErrors.TimeoutError || | ||
(e instanceof EsErrors.ResponseError && | ||
(retryResponseStatuses.includes(e?.statusCode!) || | ||
// ES returns a 400 Bad Request when trying to close or delete an | ||
// index while snapshots are in progress. This should have been a 503 | ||
// so once https://github.com/elastic/elasticsearch/issues/65883 is | ||
// fixed we can remove this. | ||
e?.body?.error?.type === 'snapshot_in_progress_exception')) | ||
) { | ||
return true; | ||
} | ||
return false; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters