Skip to content

Commit

Permalink
[7.x] Backport v2 SO migrations, disabled in FTR tests (#89297) (#89903)
Browse files Browse the repository at this point in the history
* Enable v2 so migrations, disable in FTR tests (#89297)

* Enable v2 so migrations, disable in FTR tests

* Disable v2 migrations for ui_settings integration tests

* Disable v2 migrations for reporting without serucity api integration test
# Conflicts:
#	test/common/config.js

* migrations v2: fix snapshot builds (#89541)

* migrations v2: fix snapshot builds

* Revert "Fix sharing saved objects phase 2 CI (#89056)"

This reverts commit 8263d47.

* Fix documentMigrator for snapshot releases (#89936)

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
  • Loading branch information
rudolf and kibanamachine authored Feb 9, 2021
1 parent 5c92b57 commit 735d9a9
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -206,20 +206,6 @@ describe('DocumentMigrator', () => {
);
});

it('coerces the current Kibana version if it has a hyphen', () => {
const validDefinition = {
kibanaVersion: '3.2.0-SNAPSHOT',
typeRegistry: createRegistry({
name: 'foo',
convertToMultiNamespaceTypeVersion: '3.2.0',
namespaceType: 'multiple',
}),
minimumConvertVersion: '0.0.0',
log: mockLogger,
};
expect(() => new DocumentMigrator(validDefinition)).not.toThrowError();
});

it('validates convertToMultiNamespaceTypeVersion is not used on a patch version', () => {
const invalidDefinition = {
kibanaVersion: '3.2.3',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,10 @@ export class DocumentMigrator implements VersionedTransformer {
*/
constructor({
typeRegistry,
kibanaVersion: rawKibanaVersion,
kibanaVersion,
minimumConvertVersion = DEFAULT_MINIMUM_CONVERT_VERSION,
log,
}: DocumentMigratorOptions) {
const kibanaVersion = rawKibanaVersion.split('-')[0]; // coerce a semver-like string (x.y.z-SNAPSHOT) or prerelease version (x.y.z-alpha) to a regular semver (x.y.z)
validateMigrationDefinition(typeRegistry, kibanaVersion, minimumConvertVersion);

this.documentMigratorOptions = { typeRegistry, kibanaVersion, log };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ import { loggingSystemMock } from '../../../logging/logging_system.mock';
import { SavedObjectTypeRegistry } from '../../saved_objects_type_registry';
import { SavedObjectsType } from '../../types';
import { errors as esErrors } from '@elastic/elasticsearch';
import { DocumentMigrator } from '../core/document_migrator';
jest.mock('../core/document_migrator', () => {
return {
// Create a mock for spying on the constructor
DocumentMigrator: jest.fn().mockImplementation((...args) => {
const { DocumentMigrator: RealDocMigrator } = jest.requireActual('../core/document_migrator');
return new RealDocMigrator(args[0]);
}),
};
});

const createRegistry = (types: Array<Partial<SavedObjectsType>>) => {
const registry = new SavedObjectTypeRegistry();
Expand All @@ -31,6 +41,18 @@ const createRegistry = (types: Array<Partial<SavedObjectsType>>) => {
};

describe('KibanaMigrator', () => {
beforeEach(() => {
(DocumentMigrator as jest.Mock).mockClear();
});
describe('constructor', () => {
it('coerces the current Kibana version if it has a hyphen', () => {
const options = mockOptions();
options.kibanaVersion = '3.2.1-SNAPSHOT';
const migrator = new KibanaMigrator(options);
expect(migrator.kibanaVersion).toEqual('3.2.1');
expect((DocumentMigrator as jest.Mock).mock.calls[0][0].kibanaVersion).toEqual('3.2.1');
});
});
describe('getActiveMappings', () => {
it('returns full index mappings w/ core properties', () => {
const options = mockOptions();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,14 @@ export class KibanaMigrator {
}: KibanaMigratorOptions) {
this.client = client;
this.kibanaConfig = kibanaConfig;
this.kibanaVersion = kibanaVersion;
this.savedObjectsConfig = savedObjectsConfig;
this.typeRegistry = typeRegistry;
this.serializer = new SavedObjectsSerializer(this.typeRegistry);
this.mappingProperties = mergeTypes(this.typeRegistry.getAllTypes());
this.log = logger;
this.kibanaVersion = kibanaVersion;
this.kibanaVersion = kibanaVersion.split('-')[0]; // coerce a semver-like string (x.y.z-SNAPSHOT) or prerelease version (x.y.z-alpha) to a regular semver (x.y.z);
this.documentMigrator = new DocumentMigrator({
kibanaVersion,
kibanaVersion: this.kibanaVersion,
typeRegistry,
log: this.log,
});
Expand Down
2 changes: 1 addition & 1 deletion src/core/server/saved_objects/saved_objects_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const savedObjectsMigrationConfig = {
pollInterval: schema.number({ defaultValue: 1500 }),
skip: schema.boolean({ defaultValue: false }),
// TODO migrationsV2: remove/deprecate once we release migrations v2
enableV2: schema.boolean({ defaultValue: false }),
enableV2: schema.boolean({ defaultValue: true }),
}),
};

Expand Down
3 changes: 3 additions & 0 deletions src/core/server/ui_settings/integration_tests/lib/servers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ export async function startServers() {
adjustTimeout: (t) => jest.setTimeout(t),
settings: {
kbn: {
migrations: {
enableV2: false,
},
uiSettings: {
overrides: {
foo: 'bar',
Expand Down
2 changes: 2 additions & 0 deletions test/common/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ export default function () {
`--plugin-path=${path.join(__dirname, 'fixtures', 'plugins', 'newsfeed')}`,
`--newsfeed.service.urlRoot=${servers.kibana.protocol}://${servers.kibana.hostname}:${servers.kibana.port}`,
`--newsfeed.service.pathTemplate=/api/_newsfeed-FTS-external-service-simulators/kibana/v{VERSION}.json`,
// Disable v2 migrations in tests for now
'--migrations.enableV2=false',
],
},
services,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export default async function ({ readConfigFile }: FtrConfigProviderContext) {
kbnTestServer: {
...apiConfig.get('kbnTestServer'),
serverArgs: [
`--migrations.enableV2=false`,
`--elasticsearch.hosts=${formatUrl(esTestConfig.getUrlParts())}`,
`--logging.json=false`,
`--server.maxPayloadBytes=1679958`,
Expand Down

0 comments on commit 735d9a9

Please sign in to comment.