diff --git a/x-pack/plugins/upgrade_assistant/common/types.ts b/x-pack/plugins/upgrade_assistant/common/types.ts index 88fa103bace894..a02e3a2309e77e 100644 --- a/x-pack/plugins/upgrade_assistant/common/types.ts +++ b/x-pack/plugins/upgrade_assistant/common/types.ts @@ -178,6 +178,9 @@ export interface DeprecationInfo { message: string; url: string; details?: string; + _meta?: { + [key: string]: string; + }; } export interface IndexSettingsDeprecationInfo { diff --git a/x-pack/plugins/upgrade_assistant/server/lib/__fixtures__/fake_deprecations.json b/x-pack/plugins/upgrade_assistant/server/lib/__fixtures__/fake_deprecations.json index 2b8519d75cb2ff..ef724e3bf892e2 100644 --- a/x-pack/plugins/upgrade_assistant/server/lib/__fixtures__/fake_deprecations.json +++ b/x-pack/plugins/upgrade_assistant/server/lib/__fixtures__/fake_deprecations.json @@ -24,7 +24,11 @@ "level": "critical", "message": "model snapshot [1] for job [deprecation_check_job] needs to be deleted or upgraded", "url": "", - "details": "details" + "details": "details", + "_meta": { + "snapshot_id": "1", + "job_id": "deprecation_check_job" + } } ], "node_settings": [ diff --git a/x-pack/plugins/upgrade_assistant/server/lib/es_migration_apis.ts b/x-pack/plugins/upgrade_assistant/server/lib/es_migration_apis.ts index 85cde9069d60f5..d5c112125ccce0 100644 --- a/x-pack/plugins/upgrade_assistant/server/lib/es_migration_apis.ts +++ b/x-pack/plugins/upgrade_assistant/server/lib/es_migration_apis.ts @@ -76,14 +76,15 @@ const getClusterDeprecations = (deprecations: DeprecationAPIResponse) => { .concat(deprecations.node_settings); return combinedDeprecations.map((deprecation) => { + const { _meta: metadata, ...deprecationInfo } = deprecation; return { - ...deprecation, - correctiveAction: getCorrectiveAction(deprecation.message), + ...deprecationInfo, + correctiveAction: getCorrectiveAction(deprecation.message, metadata), }; }) as EnrichedDeprecationInfo[]; }; -const getCorrectiveAction = (message: string) => { +const getCorrectiveAction = (message: string, metadata?: { [key: string]: string }) => { const indexSettingDeprecation = Object.values(indexSettingDeprecations).find( ({ deprecationMessage }) => deprecationMessage === message ); @@ -105,19 +106,12 @@ const getCorrectiveAction = (message: string) => { } if (requiresMlAction) { - // This logic is brittle, as we are expecting the message to be in a particular format to extract the snapshot ID and job ID - // Implementing https://github.com/elastic/elasticsearch/issues/73089 in ES should address this concern - const regex = /(?<=\[).*?(?=\])/g; - const matches = message.match(regex); - - if (matches?.length === 2) { - return { - type: 'mlSnapshot', - snapshotId: matches[0], - jobId: matches[1], - }; - } - } + const { snapshot_id: snapshotId, job_id: jobId } = metadata!; - return undefined; + return { + type: 'mlSnapshot', + snapshotId, + jobId, + }; + } };