From d368860f9a323bffbe71d7e0cb6976e6c25c3b98 Mon Sep 17 00:00:00 2001 From: Spencer Date: Wed, 15 Jul 2020 19:50:19 -0700 Subject: [PATCH] [esArchiver] automatically retry if alias creation fails (#71910) * [esArchiver] automatically retry if alias creation fails * print aliases to a string when logging Co-authored-by: spalger --- src/es_archiver/lib/indices/create_index_stream.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/es_archiver/lib/indices/create_index_stream.ts b/src/es_archiver/lib/indices/create_index_stream.ts index 09fcc30a9e639..a6002ec97ae30 100644 --- a/src/es_archiver/lib/indices/create_index_stream.ts +++ b/src/es_archiver/lib/indices/create_index_stream.ts @@ -18,6 +18,8 @@ */ import { Transform, Readable } from 'stream'; +import { inspect } from 'util'; + import { get, once } from 'lodash'; import { Client } from 'elasticsearch'; import { ToolingLog } from '@kbn/dev-utils'; @@ -88,6 +90,18 @@ export function createCreateIndexStream({ stats.createdIndex(index, { settings }); } catch (err) { + if ( + err?.body?.error?.reason?.includes('index exists with the same name as the alias') && + attemptNumber < 3 + ) { + const aliasStr = inspect(aliases); + log.info( + `failed to create aliases [${aliasStr}] because ES indicated an index/alias already exists, trying again` + ); + await attemptToCreate(attemptNumber + 1); + return; + } + if ( get(err, 'body.error.type') !== 'resource_already_exists_exception' || attemptNumber >= 3