From ac5ce13374338f2d7e7991911c64ba3333b184ed Mon Sep 17 00:00:00 2001 From: Gerard Soldevila Date: Fri, 27 Sep 2024 11:24:35 +0200 Subject: [PATCH] [Migrations] Upgrade integration tests - follow up work (#194151) ## Summary * Fix issue with `docVersion` on link (prevent future failure) * Add a package to `actions.test.ts` (some of the actions targeted a pre-existing index). * Addresses https://github.com/elastic/kibana/issues/166190 * Addresses https://github.com/elastic/kibana/issues/166199 * Fix flakiness in `fail_on_rollback.test.ts` * Addresses https://github.com/elastic/kibana/issues/193756 --- .../migrations/group1/v2_migration.test.ts | 5 ++- .../migrations/group3/actions/actions.test.ts | 9 +++-- .../group3/fail_on_rollback.test.ts | 37 +++++-------------- 3 files changed, 18 insertions(+), 33 deletions(-) diff --git a/src/core/server/integration_tests/saved_objects/migrations/group1/v2_migration.test.ts b/src/core/server/integration_tests/saved_objects/migrations/group1/v2_migration.test.ts index b6ee91ceffbb19e..2236b6adcc62aa2 100644 --- a/src/core/server/integration_tests/saved_objects/migrations/group1/v2_migration.test.ts +++ b/src/core/server/integration_tests/saved_objects/migrations/group1/v2_migration.test.ts @@ -34,10 +34,11 @@ import { getReindexingMigratorTestKit, getUpToDateMigratorTestKit, } from '../kibana_migrator_test_kit.fixtures'; -import { delay } from '../test_utils'; +import { delay, getDocVersion } from '../test_utils'; import { expectDocumentsMigratedToHighestVersion } from '../kibana_migrator_test_kit.expect'; const logFilePath = join(__dirname, 'v2_migration.log'); +const docVersion = getDocVersion(); describe('v2 migration', () => { let esServer: TestElasticsearchUtils; @@ -127,7 +128,7 @@ describe('v2 migration', () => { await expect(unknownTypesKit.runMigrations()).rejects.toThrowErrorMatchingInlineSnapshot(` "Unable to complete saved object migrations for the [.kibana_migrator] index: Migration failed because some documents were found which use unknown saved object types: deprecated To proceed with the migration you can configure Kibana to discard unknown saved objects for this migration. - Please refer to https://www.elastic.co/guide/en/kibana/master/resolve-migrations-failures.html for more information." + Please refer to https://www.elastic.co/guide/en/kibana/${docVersion}/resolve-migrations-failures.html for more information." `); logs = await readLog(logFilePath); expect(logs).toMatch( diff --git a/src/core/server/integration_tests/saved_objects/migrations/group3/actions/actions.test.ts b/src/core/server/integration_tests/saved_objects/migrations/group3/actions/actions.test.ts index 6341c12aaddcbe1..deecbda117c7e2f 100644 --- a/src/core/server/integration_tests/saved_objects/migrations/group3/actions/actions.test.ts +++ b/src/core/server/integration_tests/saved_objects/migrations/group3/actions/actions.test.ts @@ -46,11 +46,14 @@ import { createBulkIndexOperationTuple, checkClusterRoutingAllocationEnabled, } from '@kbn/core-saved-objects-migration-server-internal'; +import { BASELINE_TEST_ARCHIVE_1K } from '../../kibana_migrator_archive_utils'; +import { defaultKibanaIndex } from '../../kibana_migrator_test_kit'; const { startES } = createTestServers({ adjustTimeout: (t: number) => jest.setTimeout(t), settings: { es: { + dataArchive: BASELINE_TEST_ARCHIVE_1K, license: 'basic', esArgs: ['http.max_content_length=10Kb'], }, @@ -1090,13 +1093,13 @@ describe.skip('migration actions', () => { it('resolves left wait_for_task_completion_timeout when the task does not finish within the timeout', async () => { await waitForIndexStatus({ client, - index: '.kibana_1', + index: defaultKibanaIndex, status: 'yellow', })(); const res = (await reindex({ client, - sourceIndex: '.kibana_1', + sourceIndex: defaultKibanaIndex, targetIndex: 'reindex_target', reindexScript: Option.none, requireAlias: false, @@ -1433,7 +1436,7 @@ describe.skip('migration actions', () => { it('resolves left wait_for_task_completion_timeout when the task does not complete within the timeout', async () => { const res = (await pickupUpdatedMappings( client, - '.kibana_1', + defaultKibanaIndex, 1000 )()) as Either.Right; diff --git a/src/core/server/integration_tests/saved_objects/migrations/group3/fail_on_rollback.test.ts b/src/core/server/integration_tests/saved_objects/migrations/group3/fail_on_rollback.test.ts index bc98dc2b0eecdfe..6edee15ba132c22 100644 --- a/src/core/server/integration_tests/saved_objects/migrations/group3/fail_on_rollback.test.ts +++ b/src/core/server/integration_tests/saved_objects/migrations/group3/fail_on_rollback.test.ts @@ -7,52 +7,36 @@ * License v3.0 only", or the "Server Side Public License, v 1". */ -import Path from 'path'; import type { TestElasticsearchUtils } from '@kbn/core-test-helpers-kbn-server'; import { - clearLog, startElasticsearch, - getKibanaMigratorTestKit, nextMinor, defaultKibanaIndex, defaultKibanaTaskIndex, + currentVersion, } from '../kibana_migrator_test_kit'; import '../jest_matchers'; -import { delay, parseLogFile } from '../test_utils'; -import { baselineTypes as types } from '../kibana_migrator_test_kit.fixtures'; - -export const logFilePath = Path.join(__dirname, 'fail_on_rollback.test.log'); +import { delay } from '../test_utils'; +import { getUpToDateMigratorTestKit } from '../kibana_migrator_test_kit.fixtures'; +import { BASELINE_TEST_ARCHIVE_1K } from '../kibana_migrator_archive_utils'; // Failing: See https://github.com/elastic/kibana/issues/193756 describe.skip('when rolling back to an older version', () => { let esServer: TestElasticsearchUtils['es']; beforeAll(async () => { - esServer = await startElasticsearch(); + esServer = await startElasticsearch({ dataArchive: BASELINE_TEST_ARCHIVE_1K }); }); - beforeEach(async () => {}); - it('kibana should detect that a later version alias exists, and abort', async () => { - // create a current version baseline - const { runMigrations: createBaseline } = await getKibanaMigratorTestKit({ - types, - logFilePath, - }); - await createBaseline(); - // migrate to next minor - const { runMigrations: upgrade } = await getKibanaMigratorTestKit({ - kibanaVersion: nextMinor, - types, - logFilePath, - }); + const { runMigrations: upgrade } = await getUpToDateMigratorTestKit(); await upgrade(); // run migrations for the current version again (simulate rollback) - const { runMigrations: rollback } = await getKibanaMigratorTestKit({ types, logFilePath }); - - await clearLog(logFilePath); + const { runMigrations: rollback } = await getUpToDateMigratorTestKit({ + kibanaVersion: currentVersion, + }); try { await rollback(); @@ -63,9 +47,6 @@ describe.skip('when rolling back to an older version', () => { `Unable to complete saved object migrations for the [${defaultKibanaTaskIndex}] index: The ${defaultKibanaTaskIndex}_${nextMinor} alias refers to a newer version of Kibana: v${nextMinor}`, ]).toContain(error.message); } - - const logs = await parseLogFile(logFilePath); - expect(logs).toContainLogEntry(`[${defaultKibanaIndex}] INIT -> FATAL.`); }); afterAll(async () => {