Skip to content

Commit

Permalink
adapting usages
Browse files Browse the repository at this point in the history
  • Loading branch information
pgayvallet committed May 2, 2023
1 parent 3cfb847 commit 487bc49
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,7 @@ const mockOptions = () => {
},
client: mockedClient,
docLinks: docLinksServiceMock.createSetupContract(),
nodeRoles: { backgroundTasks: true, ui: true, migrator: true },
};
return options;
};
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import { BehaviorSubject } from 'rxjs';
import Semver from 'semver';
import type { NodeRoles } from '@kbn/core-node-server';
import type { Logger } from '@kbn/logging';
import type { DocLinksServiceStart } from '@kbn/core-doc-links-server';
import type { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
Expand Down Expand Up @@ -52,6 +53,7 @@ export interface KibanaMigratorOptions {
docLinks: DocLinksServiceStart;
waitForMigrationCompletion: boolean;
defaultIndexTypesMap?: IndexTypesMap;
nodeRoles: NodeRoles;
}

/**
Expand All @@ -74,6 +76,7 @@ export class KibanaMigrator implements IKibanaMigrator {
private readonly docLinks: DocLinksServiceStart;
private readonly waitForMigrationCompletion: boolean;
private readonly defaultIndexTypesMap: IndexTypesMap;
private readonly nodeRoles: NodeRoles;
public readonly kibanaVersion: string;

/**
Expand All @@ -89,6 +92,7 @@ export class KibanaMigrator implements IKibanaMigrator {
docLinks,
defaultIndexTypesMap = DEFAULT_INDEX_TYPES_MAP,
waitForMigrationCompletion,
nodeRoles,
}: KibanaMigratorOptions) {
this.client = client;
this.kibanaIndex = kibanaIndex;
Expand All @@ -105,6 +109,7 @@ export class KibanaMigrator implements IKibanaMigrator {
log: this.log,
});
this.waitForMigrationCompletion = waitForMigrationCompletion;
this.nodeRoles = nodeRoles;
// Building the active mappings (and associated md5sums) is an expensive
// operation so we cache the result
this.activeMappings = buildActiveMappings(this.mappingProperties);
Expand Down Expand Up @@ -159,6 +164,7 @@ export class KibanaMigrator implements IKibanaMigrator {
docLinks: this.docLinks,
serializer: this.serializer,
elasticsearchClient: this.client,
nodeRoles: this.nodeRoles,
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export const createContext = ({
indexPrefix,
typeRegistry,
serializer,
nodeRoles,
}: CreateContextOps): MigratorContext => {
return {
migrationConfig,
Expand All @@ -41,5 +42,6 @@ export const createContext = ({
migrationDocLinks: docLinks.links.kibanaUpgradeSavedObjects,
deletedTypes: REMOVED_TYPES,
discardCorruptObjects: Boolean(migrationConfig.discardCorruptObjects),
nodeRoles,
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { createContext } from './context';
import { next } from './next';
import { model } from './model';
import { createInitialState } from './state';
import { NodeRoles } from "@kbn/core-node-server";

export interface MigrateIndexOptions {
kibanaVersion: string;
Expand All @@ -42,6 +43,8 @@ export interface MigrateIndexOptions {
serializer: ISavedObjectsSerializer;
/** The client to use for communications with ES */
elasticsearchClient: ElasticsearchClient;
/** The node roles of the Kibana instance*/
readonly nodeRoles: NodeRoles;
}

export const migrateIndex = async ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ describe('model', () => {
retryCount: 0,
retryDelay: 0,
logs: [],
skipDocumentMigration: false,
};

const retryableError: RetryableEsClientError = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import type { Logger } from '@kbn/logging';
import type { DocLinksServiceStart } from '@kbn/core-doc-links-server';
import type { NodeRoles } from '@kbn/core-node-server';
import type { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
import type {
ISavedObjectTypeRegistry,
Expand Down Expand Up @@ -40,6 +41,8 @@ export interface RunZeroDowntimeMigrationOpts {
serializer: ISavedObjectsSerializer;
/** The client to use for communications with ES */
elasticsearchClient: ElasticsearchClient;
/** The node roles of the Kibana instance*/
nodeRoles: NodeRoles;
}

export const runZeroDowntimeMigration = async (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,8 @@ export class SavedObjectsService
this.config.migration,
elasticsearch.client.asInternalUser,
docLinks,
waitForMigrationCompletion
waitForMigrationCompletion,
node
);

this.migrator$.next(migrator);
Expand Down Expand Up @@ -365,7 +366,8 @@ export class SavedObjectsService
soMigrationsConfig: SavedObjectsMigrationConfigType,
client: ElasticsearchClient,
docLinks: DocLinksServiceStart,
waitForMigrationCompletion: boolean
waitForMigrationCompletion: boolean,
nodeInfo: NodeInfo
): IKibanaMigrator {
return new KibanaMigrator({
typeRegistry: this.typeRegistry,
Expand All @@ -376,6 +378,7 @@ export class SavedObjectsService
client,
docLinks,
waitForMigrationCompletion,
nodeRoles: nodeInfo.roles,
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import { registerServiceConfig } from '@kbn/core-root-server-internal';
import type { ISavedObjectsRepository } from '@kbn/core-saved-objects-api-server';
import { getDocLinks, getDocLinksMeta } from '@kbn/doc-links';
import type { DocLinksServiceStart } from '@kbn/core-doc-links-server';
import type { NodeRoles } from '@kbn/core-node-server';
import { baselineDocuments, baselineTypes } from './kibana_migrator_test_kit.fixtures';
import { delay } from './test_utils';

Expand All @@ -53,6 +54,7 @@ export const currentVersion = env.packageInfo.version;
export const nextMinor = new SemVer(currentVersion).inc('minor').format();
export const currentBranch = env.packageInfo.branch;
export const defaultKibanaIndex = '.kibana_migrator_tests';
export const defaultNodeRoles: NodeRoles = { migrator: true, ui: true, backgroundTasks: true };

export interface GetEsClientParams {
settings?: Record<string, any>;
Expand All @@ -64,6 +66,7 @@ export interface KibanaMigratorTestKitParams {
kibanaIndex?: string;
kibanaVersion?: string;
kibanaBranch?: string;
nodeRoles?: NodeRoles;
settings?: Record<string, any>;
types?: Array<SavedObjectsType<any>>;
logFilePath?: string;
Expand Down Expand Up @@ -121,6 +124,7 @@ export const getKibanaMigratorTestKit = async ({
kibanaBranch = currentBranch,
types = [],
logFilePath = defaultLogFilePath,
nodeRoles = defaultNodeRoles,
}: KibanaMigratorTestKitParams = {}): Promise<KibanaMigratorTestKit> => {
let hasRun = false;
const loggingSystem = new LoggingSystem();
Expand All @@ -146,7 +150,8 @@ export const getKibanaMigratorTestKit = async ({
loggerFactory,
kibanaIndex,
kibanaVersion,
kibanaBranch
kibanaBranch,
nodeRoles
);

const runMigrations = async () => {
Expand Down Expand Up @@ -255,7 +260,8 @@ const getMigrator = async (
loggerFactory: LoggerFactory,
kibanaIndex: string,
kibanaVersion: string,
kibanaBranch: string
kibanaBranch: string,
nodeRoles: NodeRoles
) => {
const savedObjectsConf = await firstValueFrom(
configService.atPath<SavedObjectsConfigType>('savedObjects')
Expand All @@ -279,6 +285,7 @@ const getMigrator = async (
logger: loggerFactory.get('savedobjects-service'),
docLinks,
waitForMigrationCompletion: false, // ensure we have an active role in the migration
nodeRoles,
});
};

Expand Down Expand Up @@ -371,7 +378,9 @@ export const getCompatibleMappingsMigrator = async ({
filterDeprecated = false,
kibanaVersion = nextMinor,
settings = {},
}: GetMutatedMigratorParams & { filterDeprecated?: boolean } = {}) => {
}: GetMutatedMigratorParams & {
filterDeprecated?: boolean;
} = {}) => {
const types = baselineTypes
.filter((type) => !filterDeprecated || type.name !== 'deprecated')
.map<SavedObjectsType>((type) => {
Expand Down

0 comments on commit 487bc49

Please sign in to comment.