-
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.
bootstrapping the ZDT migration algorithm
- Loading branch information
1 parent
fe78c05
commit b28424a
Showing
30 changed files
with
810 additions
and
88 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'; |
72 changes: 72 additions & 0 deletions
72
.../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,72 @@ | ||
/* | ||
* 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
38 changes: 38 additions & 0 deletions
38
.../core/saved-objects/core-saved-objects-migration-server-internal/src/zdt/actions/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,38 @@ | ||
/* | ||
* 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 { | ||
IncompatibleClusterRoutingAllocation, | ||
RetryableEsClientError, | ||
WaitForTaskCompletionTimeout, | ||
IndexNotFound, | ||
} from '../../actions'; | ||
|
||
export { | ||
initAction as init, | ||
type InitActionParams, | ||
type IncompatibleClusterRoutingAllocation, | ||
type RetryableEsClientError, | ||
type WaitForTaskCompletionTimeout, | ||
type IndexNotFound, | ||
} from '../../actions'; | ||
|
||
export interface ActionErrorTypeMap { | ||
wait_for_task_completion_timeout: WaitForTaskCompletionTimeout; | ||
incompatible_cluster_routing_allocation: IncompatibleClusterRoutingAllocation; | ||
retryable_es_client_error: RetryableEsClientError; | ||
index_not_found_exception: IndexNotFound; | ||
} | ||
|
||
/** Type guard for narrowing the type of a left */ | ||
export function isTypeof<T extends keyof ActionErrorTypeMap>( | ||
res: any, | ||
typeString: T | ||
): res is ActionErrorTypeMap[T] { | ||
return res.type === typeString; | ||
} |
Oops, something went wrong.