Skip to content

Commit

Permalink
[Upgrade Assistant] Refactor ML deprecation response (elastic#106847)
Browse files Browse the repository at this point in the history
  • Loading branch information
alisonelizabeth authored and vadimkibana committed Aug 8, 2021
1 parent 0c7254f commit 90ef7be
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 18 deletions.
3 changes: 3 additions & 0 deletions x-pack/plugins/upgrade_assistant/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,9 @@ export interface DeprecationInfo {
message: string;
url: string;
details?: string;
_meta?: {
[key: string]: string;
};
}

export interface IndexSettingsDeprecationInfo {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
28 changes: 11 additions & 17 deletions x-pack/plugins/upgrade_assistant/server/lib/es_migration_apis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
Expand All @@ -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,
};
}
};

0 comments on commit 90ef7be

Please sign in to comment.