-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bootstrap ZDT migration algorithm (#151282)
## Summary Part of #150309 Purpose of the PR is to create the skeleton of the ZDT algorithm, in order to make sure we're all aligned on the way we'll be managing our codebase between the 2 implementation (and to ease with the review of the follow-up PRs by not having the bootstrap of the algo to review at the same time) --------- Co-authored-by: kibanamachine <[email protected]>
- Loading branch information
1 parent
c164d77
commit bbbf8d1
Showing
40 changed files
with
1,151 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
...core/saved-objects/core-saved-objects-migration-server-internal/src/common/utils/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
export { logActionResponse, logStateTransition, type LogAwareState } from './logs'; |
71 changes: 71 additions & 0 deletions
71
.../core/saved-objects/core-saved-objects-migration-server-internal/src/common/utils/logs.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import type { Logger, LogMeta } from '@kbn/logging'; | ||
import { MigrationLog } from '../../types'; | ||
|
||
export interface LogAwareState { | ||
controlState: string; | ||
logs: MigrationLog[]; | ||
} | ||
|
||
interface StateTransitionLogMeta extends LogMeta { | ||
kibana: { | ||
migrations: { | ||
state: LogAwareState; | ||
duration: number; | ||
}; | ||
}; | ||
} | ||
|
||
export const logStateTransition = ( | ||
logger: Logger, | ||
logMessagePrefix: string, | ||
prevState: LogAwareState, | ||
currState: LogAwareState, | ||
tookMs: number | ||
) => { | ||
if (currState.logs.length > prevState.logs.length) { | ||
currState.logs.slice(prevState.logs.length).forEach(({ message, level }) => { | ||
switch (level) { | ||
case 'error': | ||
return logger.error(logMessagePrefix + message); | ||
case 'warning': | ||
return logger.warn(logMessagePrefix + message); | ||
case 'info': | ||
return logger.info(logMessagePrefix + message); | ||
default: | ||
throw new Error(`unexpected log level ${level}`); | ||
} | ||
}); | ||
} | ||
|
||
logger.info( | ||
logMessagePrefix + `${prevState.controlState} -> ${currState.controlState}. took: ${tookMs}ms.` | ||
); | ||
logger.debug<StateTransitionLogMeta>( | ||
logMessagePrefix + `${prevState.controlState} -> ${currState.controlState}. took: ${tookMs}ms.`, | ||
{ | ||
kibana: { | ||
migrations: { | ||
state: currState, | ||
duration: tookMs, | ||
}, | ||
}, | ||
} | ||
); | ||
}; | ||
|
||
export const logActionResponse = ( | ||
logger: Logger, | ||
logMessagePrefix: string, | ||
state: LogAwareState, | ||
res: unknown | ||
) => { | ||
logger.debug(logMessagePrefix + `${state.controlState} RESPONSE`, res as LogMeta); | ||
}; |
28 changes: 28 additions & 0 deletions
28
...ved-objects/core-saved-objects-migration-server-internal/src/core/build_types_mappings.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import type { SavedObjectsType } from '@kbn/core-saved-objects-server'; | ||
import type { SavedObjectsTypeMappingDefinitions } from '@kbn/core-saved-objects-base-server-internal'; | ||
|
||
/** | ||
* Merge mappings from all registered saved object types. | ||
*/ | ||
export const buildTypesMappings = ( | ||
types: SavedObjectsType[] | ||
): SavedObjectsTypeMappingDefinitions => { | ||
return types.reduce((acc, { name: type, mappings }) => { | ||
const duplicate = acc.hasOwnProperty(type); | ||
if (duplicate) { | ||
throw new Error(`Type ${type} is already defined.`); | ||
} | ||
return { | ||
...acc, | ||
[type]: mappings, | ||
}; | ||
}, {}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.