Enable ZDT migration algorithm on serverless (#160536)

## Summary

Enable the ZDT migration algorithm on serverless deployments
This commit is contained in:
Pierre Gayvallet 2023-06-27 09:50:05 +02:00 committed by GitHub
parent 595c8f5596
commit ec962e05e6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 46 additions and 14 deletions

View file

@ -6,6 +6,15 @@ xpack.fleet.internal.fleetServerStandalone: true
xpack.fleet.internal.disableILMPolicies: true
xpack.fleet.internal.disableProxies: true
# Enable ZDT migration algorithm
migrations.algorithm: zdt
# temporarily allow to run the migration on UI nodes
# until the controller is able to spawn the migrator job/pod
migrations.zdt:
metaPickupSyncDelaySec: 5
runOnRoles: ["ui"]
# Ess plugins
xpack.ess.security.enabled: false

View file

@ -47,13 +47,14 @@ const migrationSchema = schema.object({
*/
metaPickupSyncDelaySec: schema.number({ min: 1, defaultValue: 120 }),
/**
* If set to true, the document migration phase will be run even if the
* instance does not have the `migrator` role.
* The document migration phase will be run from instances with any of the specified roles.
*
* This is mostly used for testing environments and integration tests were
* we have full control over a single node Kibana deployment.
*
* Defaults to ["migrator"]
*/
runOnNonMigratorNodes: schema.boolean({ defaultValue: false }),
runOnRoles: schema.arrayOf(schema.string(), { defaultValue: ['migrator'] }),
}),
});

View file

@ -316,7 +316,7 @@ const mockOptions = (algorithm: 'v2' | 'zdt' = 'v2') => {
retryAttempts: 20,
zdt: {
metaPickupSyncDelaySec: 120,
runOnNonMigratorNodes: false,
runOnRoles: ['migrator'],
},
},
client: mockedClient,

View file

@ -58,7 +58,7 @@ describe('migrationsStateActionMachine', () => {
retryAttempts: 5,
zdt: {
metaPickupSyncDelaySec: 120,
runOnNonMigratorNodes: false,
runOnRoles: ['migrator'],
},
},
typeRegistry,

View file

@ -148,7 +148,7 @@ const mockOptions = (): RunResilientMigratorParams => {
retryAttempts: 20,
zdt: {
metaPickupSyncDelaySec: 120,
runOnNonMigratorNodes: true,
runOnRoles: ['migrator'],
},
},
typeRegistry: savedObjectTypeRegistryMock,

View file

@ -258,7 +258,7 @@ const mockOptions = (kibanaVersion = '8.2.3'): RunV2MigrationOpts => {
retryAttempts: 20,
zdt: {
metaPickupSyncDelaySec: 120,
runOnNonMigratorNodes: true,
runOnRoles: ['migrator'],
},
},
elasticsearchClient: mockedClient,

View file

@ -24,17 +24,30 @@ describe('createInitialState', () => {
const state = createInitialState(context);
expect(state.skipDocumentMigration).toEqual(true);
});
test('`skipDocumentMigration` is `false` if the node does not have the `migrator` role but `runOnNonMigratorNodes` is true', () => {
test('`skipDocumentMigration` is `false` if runOnRoles contains one of the node role', () => {
const context = createContextMock({
migrationConfig: createMigrationConfigMock({
zdt: {
metaPickupSyncDelaySec: 120,
runOnNonMigratorNodes: true,
runOnRoles: ['ui'],
},
}),
nodeRoles: { backgroundTasks: false, ui: false, migrator: false },
nodeRoles: { backgroundTasks: true, ui: true, migrator: false },
});
const state = createInitialState(context);
expect(state.skipDocumentMigration).toEqual(false);
});
test('`skipDocumentMigration` is `true` if runOnRoles does not contain one of the node role', () => {
const context = createContextMock({
migrationConfig: createMigrationConfigMock({
zdt: {
metaPickupSyncDelaySec: 120,
runOnRoles: ['ui'],
},
}),
nodeRoles: { backgroundTasks: true, ui: false, migrator: false },
});
const state = createInitialState(context);
expect(state.skipDocumentMigration).toEqual(true);
});
});

View file

@ -6,6 +6,7 @@
* Side Public License, v 1.
*/
import type { NodeRoles } from '@kbn/core-node-server';
import type { InitState, State } from './types';
import type { MigratorContext } from '../context';
@ -13,8 +14,10 @@ import type { MigratorContext } from '../context';
* Create the initial state to be used for the ZDT migrator.
*/
export const createInitialState = (context: MigratorContext): State => {
const runDocumentMigration =
context.nodeRoles.migrator || context.migrationConfig.zdt.runOnNonMigratorNodes;
const nodeRoles = getNodeRoles(context.nodeRoles);
const enabledRoles = new Set(context.migrationConfig.zdt.runOnRoles);
const runDocumentMigration = nodeRoles.some((role) => enabledRoles.has(role));
const initialState: InitState = {
controlState: 'INIT',
logs: [],
@ -24,3 +27,9 @@ export const createInitialState = (context: MigratorContext): State => {
};
return initialState;
};
const getNodeRoles = (roles: NodeRoles): string[] => {
return Object.entries(roles)
.filter(([_, enabled]) => enabled)
.map(([key]) => key);
};

View file

@ -38,7 +38,7 @@ export const createMigrationConfigMock = (
retryAttempts: 5,
zdt: {
metaPickupSyncDelaySec: 120,
runOnNonMigratorNodes: false,
runOnRoles: ['migrator'],
},
...parts,
});

View file

@ -27,7 +27,7 @@ export const getBaseMigratorParams = ({
algorithm: migrationAlgorithm,
zdt: {
metaPickupSyncDelaySec: 5,
runOnNonMigratorNodes,
runOnRoles: runOnNonMigratorNodes ? ['ui', 'migrator'] : ['migrator'],
},
},
},