From ab40050ecfca1e53b0b74fbb94a44ab34f26058c Mon Sep 17 00:00:00 2001 From: Josh Dover <1813008+joshdover@users.noreply.github.com> Date: Tue, 13 Jul 2021 13:41:18 +0200 Subject: [PATCH 1/2] Parameterize migration test for kibana version --- .../migration_7_13_0_unknown_types.test.ts | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/src/core/server/saved_objects/migrationsv2/integration_tests/migration_7_13_0_unknown_types.test.ts b/src/core/server/saved_objects/migrationsv2/integration_tests/migration_7_13_0_unknown_types.test.ts index a30b3d291e7ec..52a40bbd9f8d5 100644 --- a/src/core/server/saved_objects/migrationsv2/integration_tests/migration_7_13_0_unknown_types.test.ts +++ b/src/core/server/saved_objects/migrationsv2/integration_tests/migration_7_13_0_unknown_types.test.ts @@ -13,7 +13,11 @@ import * as kbnTestServer from '../../../../test_helpers/kbn_server'; import { Root } from '../../../root'; import JSON5 from 'json5'; import { ElasticsearchClient } from '../../../elasticsearch'; +import { Env } from '@kbn/config'; +import { REPO_ROOT } from '@kbn/utils'; +import { getEnvOptions } from '@kbn/config/target/mocks'; +const kibanaVersion = Env.createDefault(REPO_ROOT, getEnvOptions()).packageInfo.version; const logFilePath = Path.join(__dirname, '7_13_unknown_types_test.log'); async function removeLogFile() { @@ -76,7 +80,7 @@ describe('migration v2', () => { unknownDocsWarningLog.message.startsWith( '[.kibana] CHECK_UNKNOWN_DOCUMENTS Upgrades will fail for 8.0+ because documents were found for unknown saved ' + 'object types. To ensure that upgrades will succeed in the future, either re-enable plugins or delete ' + - 'these documents from the ".kibana_8.0.0_001" index after the current upgrade completes.' + `these documents from the ".kibana_${kibanaVersion}_001" index after the current upgrade completes.` ) ).toBeTruthy(); @@ -100,14 +104,16 @@ describe('migration v2', () => { }); const client: ElasticsearchClient = esServer.es.getClient(); - const { body: response } = await client.indices.getSettings({ index: '.kibana_8.0.0_001' }); - const settings = response['.kibana_8.0.0_001'] + const { body: response } = await client.indices.getSettings({ + index: `.kibana_${kibanaVersion}_001`, + }); + const settings = response[`.kibana_${kibanaVersion}_001`] .settings as estypes.IndicesIndexStatePrefixedSettings; expect(settings.index).not.toBeUndefined(); expect(settings.index!.blocks?.write).not.toEqual('true'); // Ensure that documents for unknown types were preserved in target index in an unmigrated state - const spaceDocs = await fetchDocs(client, '.kibana_8.0.0_001', 'space'); + const spaceDocs = await fetchDocs(client, `.kibana_${kibanaVersion}_001`, 'space'); expect(spaceDocs.map((s) => s.id)).toEqual( expect.arrayContaining([ 'space:default', @@ -123,7 +129,7 @@ describe('migration v2', () => { expect(d.migrationVersion.space).toEqual('6.6.0'); expect(d.coreMigrationVersion).toEqual('7.13.0'); }); - const fooDocs = await fetchDocs(client, '.kibana_8.0.0_001', 'foo'); + const fooDocs = await fetchDocs(client, `.kibana_${kibanaVersion}_001`, 'foo'); expect(fooDocs.map((f) => f.id)).toEqual( expect.arrayContaining([ 'P2SQfHkBs3dBRGh--No5', @@ -155,13 +161,13 @@ describe('migration v2', () => { namespaceType: 'agnostic', migrations: { '6.6.0': (d) => d, - '8.0.0': (d) => d, + [kibanaVersion]: (d) => d, }, }); await root.start(); const client: ElasticsearchClient = esServer.es.getClient(); - const spacesDocsMigrated = await fetchDocs(client, '.kibana_8.0.0_001', 'space'); + const spacesDocsMigrated = await fetchDocs(client, `.kibana_${kibanaVersion}_001`, 'space'); expect(spacesDocsMigrated.map((s) => s.id)).toEqual( expect.arrayContaining([ 'space:default', @@ -174,12 +180,12 @@ describe('migration v2', () => { ]) ); spacesDocsMigrated.forEach((d) => { - expect(d.migrationVersion.space).toEqual('8.0.0'); // should be migrated - expect(d.coreMigrationVersion).toEqual('8.0.0'); + expect(d.migrationVersion.space).toEqual(kibanaVersion); // should be migrated + expect(d.coreMigrationVersion).toEqual(kibanaVersion); }); // Make sure unmigrated foo docs are also still there in an unmigrated state - const fooDocsUnmigrated = await fetchDocs(client, '.kibana_8.0.0_001', 'foo'); + const fooDocsUnmigrated = await fetchDocs(client, `.kibana_${kibanaVersion}_001`, 'foo'); expect(fooDocsUnmigrated.map((f) => f.id)).toEqual( expect.arrayContaining([ 'P2SQfHkBs3dBRGh--No5', From 70d2c442f4e194aba07359144ece0e89e3cc8f6a Mon Sep 17 00:00:00 2001 From: Josh Dover <1813008+joshdover@users.noreply.github.com> Date: Fri, 16 Jul 2021 13:21:13 +0200 Subject: [PATCH 2/2] PR comments --- .../migration_7_13_0_unknown_types.test.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/core/server/saved_objects/migrationsv2/integration_tests/migration_7_13_0_unknown_types.test.ts b/src/core/server/saved_objects/migrationsv2/integration_tests/migration_7_13_0_unknown_types.test.ts index 52a40bbd9f8d5..33f7fec167f2d 100644 --- a/src/core/server/saved_objects/migrationsv2/integration_tests/migration_7_13_0_unknown_types.test.ts +++ b/src/core/server/saved_objects/migrationsv2/integration_tests/migration_7_13_0_unknown_types.test.ts @@ -18,6 +18,7 @@ import { REPO_ROOT } from '@kbn/utils'; import { getEnvOptions } from '@kbn/config/target/mocks'; const kibanaVersion = Env.createDefault(REPO_ROOT, getEnvOptions()).packageInfo.version; +const targetIndex = `.kibana_${kibanaVersion}_001`; const logFilePath = Path.join(__dirname, '7_13_unknown_types_test.log'); async function removeLogFile() { @@ -80,7 +81,7 @@ describe('migration v2', () => { unknownDocsWarningLog.message.startsWith( '[.kibana] CHECK_UNKNOWN_DOCUMENTS Upgrades will fail for 8.0+ because documents were found for unknown saved ' + 'object types. To ensure that upgrades will succeed in the future, either re-enable plugins or delete ' + - `these documents from the ".kibana_${kibanaVersion}_001" index after the current upgrade completes.` + `these documents from the "${targetIndex}" index after the current upgrade completes.` ) ).toBeTruthy(); @@ -105,15 +106,14 @@ describe('migration v2', () => { const client: ElasticsearchClient = esServer.es.getClient(); const { body: response } = await client.indices.getSettings({ - index: `.kibana_${kibanaVersion}_001`, + index: targetIndex, }); - const settings = response[`.kibana_${kibanaVersion}_001`] - .settings as estypes.IndicesIndexStatePrefixedSettings; + const settings = response[targetIndex].settings as estypes.IndicesIndexStatePrefixedSettings; expect(settings.index).not.toBeUndefined(); expect(settings.index!.blocks?.write).not.toEqual('true'); // Ensure that documents for unknown types were preserved in target index in an unmigrated state - const spaceDocs = await fetchDocs(client, `.kibana_${kibanaVersion}_001`, 'space'); + const spaceDocs = await fetchDocs(client, targetIndex, 'space'); expect(spaceDocs.map((s) => s.id)).toEqual( expect.arrayContaining([ 'space:default', @@ -129,7 +129,7 @@ describe('migration v2', () => { expect(d.migrationVersion.space).toEqual('6.6.0'); expect(d.coreMigrationVersion).toEqual('7.13.0'); }); - const fooDocs = await fetchDocs(client, `.kibana_${kibanaVersion}_001`, 'foo'); + const fooDocs = await fetchDocs(client, targetIndex, 'foo'); expect(fooDocs.map((f) => f.id)).toEqual( expect.arrayContaining([ 'P2SQfHkBs3dBRGh--No5', @@ -167,7 +167,7 @@ describe('migration v2', () => { await root.start(); const client: ElasticsearchClient = esServer.es.getClient(); - const spacesDocsMigrated = await fetchDocs(client, `.kibana_${kibanaVersion}_001`, 'space'); + const spacesDocsMigrated = await fetchDocs(client, targetIndex, 'space'); expect(spacesDocsMigrated.map((s) => s.id)).toEqual( expect.arrayContaining([ 'space:default', @@ -185,7 +185,7 @@ describe('migration v2', () => { }); // Make sure unmigrated foo docs are also still there in an unmigrated state - const fooDocsUnmigrated = await fetchDocs(client, `.kibana_${kibanaVersion}_001`, 'foo'); + const fooDocsUnmigrated = await fetchDocs(client, targetIndex, 'foo'); expect(fooDocsUnmigrated.map((f) => f.id)).toEqual( expect.arrayContaining([ 'P2SQfHkBs3dBRGh--No5',