-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Migrations: dynamically adjust batchSize when reading #157494
Merged
Merged
Changes from 19 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
019eb09
Use batchSize config for update_by_query in updateAndPickupMappings
rudolf 87bc176
Merge branch 'main' into updateAndPickupMappings-batch-size
rudolf ae9cdc9
Add batchSize to ZDT
rudolf 3e5b0e5
Merge branch 'main' into updateAndPickupMappings-batch-size
rudolf e7d328e
Migrations: dynamically adjust batchSize when reading
rudolf a570e3a
Fixes and improve logging
rudolf 7e761ac
model.test.ts unit tests
rudolf 61cdf9c
Unit tests
rudolf d972600
Merge branch 'main' into updateAndPickupMappings-batch-size
rudolf 156619f
Merge branch 'updateAndPickupMappings-batch-size' into migrations-dyn…
rudolf e3f11bc
E2E & integration tests
rudolf 701e53b
Increase dot_kibana_split test timeout to reduce flakiness
rudolf b71ab24
Fix tests
rudolf 9c241b4
Delete unecessary file
rudolf 5202b28
Merge branch 'main' into migrations-dynamic-read-batchsize
kibanamachine 532a41d
Retry when there's circuit breaker exceptions from Elasticsearch
rudolf 67562ec
Address reviews, better handling when batchSize: 1 still exceeds maxR…
rudolf 98826d4
Merge branch 'main' into migrations-dynamic-read-batchsize
rudolf c3c272f
Review feedback: increase coverage of recovering up to maxBatchSize o…
rudolf 9a41d95
Review: why match when you can test
rudolf b81deb1
Merge branch 'main' into migrations-dynamic-read-batchsize
rudolf 0efb67a
Fix outdated integration test
gsoldevila eb35b1b
Merge branch 'main' into migrations-dynamic-read-batchsize
gsoldevila File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
12 changes: 12 additions & 0 deletions
12
...-migration-server-internal/src/__snapshots__/migrations_state_action_machine.test.ts.snap
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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 | ||||
---|---|---|---|---|---|---|
|
@@ -9,13 +9,15 @@ | |||||
import * as Either from 'fp-ts/lib/Either'; | ||||||
import * as TaskEither from 'fp-ts/lib/TaskEither'; | ||||||
import * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; | ||||||
import { errors as EsErrors } from '@elastic/elasticsearch'; | ||||||
import type { ElasticsearchClient } from '@kbn/core-elasticsearch-server'; | ||||||
import type { SavedObjectsRawDoc } from '@kbn/core-saved-objects-server'; | ||||||
import { | ||||||
catchRetryableEsClientErrors, | ||||||
type RetryableEsClientError, | ||||||
} from './catch_retryable_es_client_errors'; | ||||||
import { DEFAULT_PIT_KEEP_ALIVE } from './open_pit'; | ||||||
import { EsResponseTooLargeError } from '.'; | ||||||
|
||||||
/** @internal */ | ||||||
export interface ReadWithPit { | ||||||
|
@@ -32,6 +34,7 @@ export interface ReadWithPitParams { | |||||
batchSize: number; | ||||||
searchAfter?: number[]; | ||||||
seqNoPrimaryTerm?: boolean; | ||||||
maxResponseSizeBytes?: number; | ||||||
} | ||||||
|
||||||
/* | ||||||
|
@@ -45,32 +48,39 @@ export const readWithPit = | |||||
batchSize, | ||||||
searchAfter, | ||||||
seqNoPrimaryTerm, | ||||||
}: ReadWithPitParams): TaskEither.TaskEither<RetryableEsClientError, ReadWithPit> => | ||||||
maxResponseSizeBytes, | ||||||
}: ReadWithPitParams): TaskEither.TaskEither< | ||||||
RetryableEsClientError | EsResponseTooLargeError, | ||||||
ReadWithPit | ||||||
> => | ||||||
() => { | ||||||
return client | ||||||
.search<SavedObjectsRawDoc>({ | ||||||
seq_no_primary_term: seqNoPrimaryTerm, | ||||||
// Fail if the index being searched doesn't exist or is closed | ||||||
// allow_no_indices: false, | ||||||
// By default ES returns a 200 with partial results if there are shard | ||||||
// request timeouts or shard failures which can lead to data loss for | ||||||
// migrations | ||||||
allow_partial_search_results: false, | ||||||
// Sort fields are required to use searchAfter so we sort by the | ||||||
// natural order of the index which is the most efficient option | ||||||
// as order is not important for the migration | ||||||
sort: '_shard_doc:asc', | ||||||
pit: { id: pitId, keep_alive: DEFAULT_PIT_KEEP_ALIVE }, | ||||||
size: batchSize, | ||||||
search_after: searchAfter, | ||||||
/** | ||||||
* We want to know how many documents we need to process so we can log the progress. | ||||||
* But we also want to increase the performance of these requests, | ||||||
* so we ask ES to report the total count only on the first request (when searchAfter does not exist) | ||||||
*/ | ||||||
track_total_hits: typeof searchAfter === 'undefined', | ||||||
query, | ||||||
}) | ||||||
.search<SavedObjectsRawDoc>( | ||||||
{ | ||||||
seq_no_primary_term: seqNoPrimaryTerm, | ||||||
// Fail if the index being searched doesn't exist or is closed | ||||||
// allow_no_indices: false, | ||||||
// By default ES returns a 200 with partial results if there are shard | ||||||
// request timeouts or shard failures which can lead to data loss for | ||||||
// migrations | ||||||
allow_partial_search_results: false, | ||||||
// Sort fields are required to use searchAfter so we sort by the | ||||||
// natural order of the index which is the most efficient option | ||||||
// as order is not important for the migration | ||||||
sort: '_shard_doc:asc', | ||||||
pit: { id: pitId, keep_alive: DEFAULT_PIT_KEEP_ALIVE }, | ||||||
size: batchSize, | ||||||
search_after: searchAfter, | ||||||
/** | ||||||
* We want to know how many documents we need to process so we can log the progress. | ||||||
* But we also want to increase the performance of these requests, | ||||||
* so we ask ES to report the total count only on the first request (when searchAfter does not exist) | ||||||
*/ | ||||||
track_total_hits: typeof searchAfter === 'undefined', | ||||||
query, | ||||||
}, | ||||||
{ maxResponseSize: maxResponseSizeBytes } | ||||||
) | ||||||
.then((body) => { | ||||||
const totalHits = | ||||||
typeof body.hits.total === 'number' | ||||||
|
@@ -93,5 +103,22 @@ export const readWithPit = | |||||
totalHits, | ||||||
}); | ||||||
}) | ||||||
.catch((e) => { | ||||||
if ( | ||||||
e instanceof EsErrors.RequestAbortedError && | ||||||
e.message.match(/The content length \(\d+\) is bigger than the maximum/) != null | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit:
Suggested change
|
||||||
) { | ||||||
return Either.left({ | ||||||
type: 'es_response_too_large' as const, | ||||||
contentLength: Number.parseInt( | ||||||
e.message.match(/The content length \((\d+)\) is bigger than the maximum/)?.[1] ?? | ||||||
'-1', | ||||||
10 | ||||||
), | ||||||
}); | ||||||
} else { | ||||||
throw e; | ||||||
} | ||||||
}) | ||||||
.catch(catchRetryableEsClientErrors); | ||||||
}; |
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
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
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TIL elastic-transport-js is handling this limit:
https://github.com/elastic/elastic-transport-js/blob/main/src/connection/HttpConnection.ts#L146,L159