Skip to content

Commit

Permalink
Addresses some optional review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
TinaHeiligers committed May 31, 2021
1 parent 5bc0a9b commit e64b120
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe('actions', () => {

describe('fetchIndices', () => {
it('calls catchRetryableEsClientErrors when the promise rejects', async () => {
const task = Actions.fetchIndices({ client, indicesToFetch: ['my_index'] });
const task = Actions.fetchIndices({ client, indices: ['my_index'] });
try {
await task();
} catch (e) {
Expand Down
10 changes: 5 additions & 5 deletions src/core/server/saved_objects/migrationsv2/actions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export type FetchIndexResponse = Record<
/** @internal */
export interface FetchIndicesParams {
client: ElasticsearchClient;
indicesToFetch: string[];
indices: string[];
}

/**
Expand All @@ -80,14 +80,14 @@ export interface FetchIndicesParams {
*/
export const fetchIndices = ({
client,
indicesToFetch,
indices,
}: FetchIndicesParams): TaskEither.TaskEither<RetryableEsClientError, FetchIndexResponse> =>
// @ts-expect-error @elastic/elasticsearch IndexState.alias and IndexState.mappings should be required
() => {
return client.indices
.get(
{
index: indicesToFetch,
index: indices,
ignore_unavailable: true, // Don't return an error for missing indices. Note this *will* include closed indices, the docs are misleading https://github.com/elastic/elasticsearch/issues/63607
},
{ ignore: [404], maxRetries: 0 }
Expand Down Expand Up @@ -1174,7 +1174,7 @@ export interface BulkOverwriteTransformedDocumentsParams {
client: ElasticsearchClient;
index: string;
transformedDocs: SavedObjectsRawDoc[];
refresh: estypes.Refresh;
refresh?: estypes.Refresh;
}
/**
* Write the up-to-date transformed documents to the index, overwriting any
Expand All @@ -1184,7 +1184,7 @@ export const bulkOverwriteTransformedDocuments = ({
client,
index,
transformedDocs,
refresh,
refresh = false,
}: BulkOverwriteTransformedDocumentsParams): TaskEither.TaskEither<
RetryableEsClientError,
'bulk_index_succeeded'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ describe('migration actions', () => {
describe('fetchIndices', () => {
it('resolves right empty record if no indices were found', async () => {
expect.assertions(1);
const task = fetchIndices({ client, indicesToFetch: ['no_such_index'] });
const task = fetchIndices({ client, indices: ['no_such_index'] });
await expect(task()).resolves.toMatchInlineSnapshot(`
Object {
"_tag": "Right",
Expand All @@ -128,7 +128,7 @@ describe('migration actions', () => {
expect.assertions(1);
const res = (await fetchIndices({
client,
indicesToFetch: ['no_such_index', 'existing_index_with_docs'],
indices: ['no_such_index', 'existing_index_with_docs'],
})()) as Either.Right<unknown>;

expect(res.right).toEqual(
Expand Down
5 changes: 2 additions & 3 deletions src/core/server/saved_objects/migrationsv2/next.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export type ResponseType<ControlState extends AllActionStates> = UnwrapPromise<
export const nextActionMap = (client: ElasticsearchClient, transformRawDocs: TransformRawDocs) => {
return {
INIT: (state: InitState) =>
Actions.fetchIndices({ client, indicesToFetch: [state.currentAlias, state.versionAlias] }),
Actions.fetchIndices({ client, indices: [state.currentAlias, state.versionAlias] }),
WAIT_FOR_YELLOW_SOURCE: (state: WaitForYellowSourceState) =>
Actions.waitForIndexStatusYellow({ client, index: state.sourceIndex.value }),
SET_SOURCE_WRITE_BLOCK: (state: SetSourceWriteBlockState) =>
Expand Down Expand Up @@ -154,12 +154,11 @@ export const nextActionMap = (client: ElasticsearchClient, transformRawDocs: Tra
* before we reach out to the MARK_VERSION_INDEX_READY step.
* Right now, it's performed during OUTDATED_DOCUMENTS_REFRESH step.
*/
refresh: false,
}),
MARK_VERSION_INDEX_READY: (state: MarkVersionIndexReady) =>
Actions.updateAliases({ client, aliasActions: state.versionIndexReadyActions.value }),
MARK_VERSION_INDEX_READY_CONFLICT: (state: MarkVersionIndexReadyConflict) =>
Actions.fetchIndices({ client, indicesToFetch: [state.currentAlias, state.versionAlias] }),
Actions.fetchIndices({ client, indices: [state.currentAlias, state.versionAlias] }),
LEGACY_SET_WRITE_BLOCK: (state: LegacySetWriteBlockState) =>
Actions.setWriteBlock({ client, index: state.legacyIndex }),
LEGACY_CREATE_REINDEX_TARGET: (state: LegacyCreateReindexTargetState) =>
Expand Down

0 comments on commit e64b120

Please sign in to comment.