Skip to content

Commit

Permalink
[8.8] [Migrations] Systematically wait for newly created indices to t…
Browse files Browse the repository at this point in the history
…urn green (#157973) (#157993)

# Backport

This will backport the following commits from `main` to `8.8`:
- [[Migrations] Systematically wait for newly created indices to turn
green (#157973)](#157973)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Gerard
Soldevila","email":"[email protected]"},"sourceCommit":{"committedDate":"2023-05-17T13:34:51Z","message":"[Migrations]
Systematically wait for newly created indices to turn green
(#157973)\n\nTackles
https://github.com/elastic/kibana/issues/157968\r\n\r\nWhen creating new
indices during SO migrations, we used to rely on
the\r\n`res.acknowledged && res.shardsAcknowledged` of
the\r\n`esClient.indices.create(...)` to determine that the indices are
ready\r\nto use.\r\n\r\nHowever, we believe that due to certain race
conditions, this can cause\r\nKibana migrations to fail (refer to the
[related\r\nissue](https://github.com/elastic/kibana/issues/157968)).\r\n\r\nThis
PR aims at fixing recent CI failures by adding a
systematic\r\n`waitForIndexStatus` after creating an
index.","sha":"71125b192e86ddc3d6747c5b14b92e669eba360f","branchLabelMapping":{"^v8.9.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["bug","Team:Core","release_note:skip","Feature:Migrations","backport:prev-minor","v8.8.0","v8.9.0","v8.8.1"],"number":157973,"url":"https://github.com/elastic/kibana/pull/157973","mergeCommit":{"message":"[Migrations]
Systematically wait for newly created indices to turn green
(#157973)\n\nTackles
https://github.com/elastic/kibana/issues/157968\r\n\r\nWhen creating new
indices during SO migrations, we used to rely on
the\r\n`res.acknowledged && res.shardsAcknowledged` of
the\r\n`esClient.indices.create(...)` to determine that the indices are
ready\r\nto use.\r\n\r\nHowever, we believe that due to certain race
conditions, this can cause\r\nKibana migrations to fail (refer to the
[related\r\nissue](https://github.com/elastic/kibana/issues/157968)).\r\n\r\nThis
PR aims at fixing recent CI failures by adding a
systematic\r\n`waitForIndexStatus` after creating an
index.","sha":"71125b192e86ddc3d6747c5b14b92e669eba360f"}},"sourceBranch":"main","suggestedTargetBranches":["8.8"],"targetPullRequestStates":[{"branch":"8.8","label":"v8.8.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.9.0","labelRegex":"^v8.9.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/157973","number":157973,"mergeCommit":{"message":"[Migrations]
Systematically wait for newly created indices to turn green
(#157973)\n\nTackles
https://github.com/elastic/kibana/issues/157968\r\n\r\nWhen creating new
indices during SO migrations, we used to rely on
the\r\n`res.acknowledged && res.shardsAcknowledged` of
the\r\n`esClient.indices.create(...)` to determine that the indices are
ready\r\nto use.\r\n\r\nHowever, we believe that due to certain race
conditions, this can cause\r\nKibana migrations to fail (refer to the
[related\r\nissue](https://github.com/elastic/kibana/issues/157968)).\r\n\r\nThis
PR aims at fixing recent CI failures by adding a
systematic\r\n`waitForIndexStatus` after creating an
index.","sha":"71125b192e86ddc3d6747c5b14b92e669eba360f"}}]}]
BACKPORT-->

Co-authored-by: Gerard Soldevila <[email protected]>
  • Loading branch information
kibanamachine and gsoldevila authored May 17, 2023
1 parent d11b6af commit f8b1a48
Showing 1 changed file with 15 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,25 +146,21 @@ export const createIndex = ({
AcknowledgeResponse,
'create_index_succeeded'
>((res) => {
if (res.acknowledged && res.shardsAcknowledged) {
// If the cluster state was updated and all shards started we're done
return TaskEither.right('create_index_succeeded');
} else {
// Otherwise, wait until the target index has a 'green' status meaning
// the primary (and on multi node clusters) the replica has been started
return pipe(
waitForIndexStatus({
client,
index: indexName,
timeout: DEFAULT_TIMEOUT,
status: 'green',
}),
TaskEither.map(() => {
/** When the index status is 'green' we know that all shards were started */
return 'create_index_succeeded';
})
);
}
// Systematicaly wait until the target index has a 'green' status meaning
// the primary (and on multi node clusters) the replica has been started
// see https://github.com/elastic/kibana/issues/157968
return pipe(
waitForIndexStatus({
client,
index: indexName,
timeout: DEFAULT_TIMEOUT,
status: 'green',
}),
TaskEither.map(() => {
/** When the index status is 'green' we know that all shards were started */
return 'create_index_succeeded';
})
);
})
);
};

0 comments on commit f8b1a48

Please sign in to comment.