From 707eaf3b1f43dafb3462765ca24618584c8aa879 Mon Sep 17 00:00:00 2001 From: "Mark J. Hoy" Date: Wed, 19 Feb 2025 15:35:15 -0500 Subject: [PATCH 1/7] ensure datastream deprecations; modify config dep. --- .../server/deprecations/index.test.ts | 27 ++++++--- .../server/deprecations/index.ts | 27 ++++++--- .../pre_eight_index_deprecator.test.ts | 58 +++++++++++++++--- .../pre_eight_index_deprecator.ts | 59 +++++++++++++++---- .../plugins/enterprise_search/server/index.ts | 5 -- 5 files changed, 133 insertions(+), 43 deletions(-) diff --git a/x-pack/solutions/search/plugins/enterprise_search/server/deprecations/index.test.ts b/x-pack/solutions/search/plugins/enterprise_search/server/deprecations/index.test.ts index 6c2bb0e7910fb..c0d3893fb2f0c 100644 --- a/x-pack/solutions/search/plugins/enterprise_search/server/deprecations/index.test.ts +++ b/x-pack/solutions/search/plugins/enterprise_search/server/deprecations/index.test.ts @@ -62,9 +62,22 @@ describe('Enterprise Search node deprecation', () => { const deprecations = getEnterpriseSearchNodeDeprecation(config, notCloud, docsUrl); expect(deprecations).toHaveLength(1); const steps = deprecations[0].correctiveActions.manualSteps; - expect(steps).toHaveLength(4); + expect(steps).toHaveLength(5); const stepsStr = steps.join(', '); expect(stepsStr).toMatch("remove 'enterpriseSearch.host'"); + expect(stepsStr).toMatch("remove 'enterpriseSearch.customHeaders'"); + expect(stepsStr).toMatch('Stop all your Enterprise Search nodes'); + }); + + it('Tells you to remove the custom headers config if running self-managed without host', () => { + const config = { customHeaders: {} } as ConfigType; + const deprecations = getEnterpriseSearchNodeDeprecation(config, notCloud, docsUrl); + expect(deprecations).toHaveLength(1); + const steps = deprecations[0].correctiveActions.manualSteps; + expect(steps).toHaveLength(5); + const stepsStr = steps.join(', '); + expect(stepsStr).toMatch("remove 'enterpriseSearch.host'"); + expect(stepsStr).toMatch("remove 'enterpriseSearch.customHeaders'"); expect(stepsStr).toMatch('Stop all your Enterprise Search nodes'); }); @@ -130,13 +143,13 @@ describe('getEnterpriseSearchPre8IndexDeprecations', () => { Promise.resolve([ { name: '.ent-search-index_without_datastream', - isDatastream: false, - datastreamName: '', + hasDatastream: false, + datastreams: [], }, { name: '.ent-search-with_data_stream', - isDatastream: true, - datastreamName: 'datastream-testing', + hasDatastream: true, + datastreams: ['datastream-testing'], }, ]) ); @@ -168,8 +181,8 @@ describe('getEnterpriseSearchPre8IndexDeprecations', () => { Promise.resolve([ { name: '.ent-search-index_without_datastream', - isDatastream: false, - datastreamName: '', + hasDatastream: false, + datastreams: [''], }, ]) ); diff --git a/x-pack/solutions/search/plugins/enterprise_search/server/deprecations/index.ts b/x-pack/solutions/search/plugins/enterprise_search/server/deprecations/index.ts index f09aa8b49766e..a1363612dfaa7 100644 --- a/x-pack/solutions/search/plugins/enterprise_search/server/deprecations/index.ts +++ b/x-pack/solutions/search/plugins/enterprise_search/server/deprecations/index.ts @@ -49,7 +49,7 @@ export function getEnterpriseSearchNodeDeprecation( cloud: CloudSetup, docsUrl: string ): DeprecationsDetails[] { - if (config.host) { + if (config.host || config.customHeaders) { const steps = []; let addendum: string = ''; const isCloud = !!cloud?.cloudId; @@ -96,6 +96,10 @@ export function getEnterpriseSearchNodeDeprecation( i18n.translate('xpack.enterpriseSearch.deprecations.entsearchhost.removeconfig', { defaultMessage: "Edit 'kibana.yml' to remove 'enterpriseSearch.host'", }), + i18n.translate('xpack.enterpriseSearch.deprecations.entsearchhost.removecustomconfig', { + defaultMessage: + "Edit 'kibana.yml' to remove 'enterpriseSearch.customHeaders' if it exists", + }), i18n.translate('xpack.enterpriseSearch.deprecations.entsearchhost.restart', { defaultMessage: 'Restart Kibana', }), @@ -107,7 +111,7 @@ export function getEnterpriseSearchNodeDeprecation( level: 'critical', deprecationType: 'feature', title: i18n.translate('xpack.enterpriseSearch.deprecations.entsearchhost.title', { - defaultMessage: 'Enterprise Search host(s) must be removed', + defaultMessage: 'Enterprise Search host(s) and configuration must be removed', }), message: { type: 'markdown', @@ -120,6 +124,7 @@ export function getEnterpriseSearchNodeDeprecation( 'Enterprise Search is not supported in versions >= 9.x.\n\n' + 'Please note the following:\n' + '- You must remove any Enterprise Search nodes from your deployment to proceed with the upgrade.\n' + + '- You must also remove any Enterprise Search configuration elements in your Kibana config.\n' + '- If you are currently using App Search, Workplace Search, or the Elastic Web Crawler, these features will ' + 'cease to function if you remove Enterprise Search from your deployment. Therefore, it is critical to ' + 'first [migrate your Enterprise Search use cases]({migration_link}) before decommissioning your ' + @@ -291,8 +296,12 @@ export async function getEnterpriseSearchPre8IndexDeprecations( let indicesList = ''; let datastreamsList = ''; for (const index of entSearchIndices) { - if (index.isDatastream) { - datastreamsList += `${index.name}\n`; + if (index.hasDatastream) { + indicesList += `${index.name}\n`; + for (const datastream of index.datastreams) { + if (datastream === '') continue; + datastreamsList += `${datastream}\n`; + } } else { indicesList += `${index.name}\n`; } @@ -305,8 +314,8 @@ export async function getEnterpriseSearchPre8IndexDeprecations( 'The following indices are found to be incompatible for upgrade:\n\n' + '```\n' + `${indicesList}` + - '\n```\n\n' + - 'These indices must be either set to read-only or deleted before upgrading. '; + '\n```\n' + + 'These indices must be either set to read-only or deleted before upgrading.\n'; } if (datastreamsList.length > 0) { @@ -314,7 +323,7 @@ export async function getEnterpriseSearchPre8IndexDeprecations( '\nThe following data streams are found to be incompatible for upgrade:\n\n' + '```\n' + `${datastreamsList}` + - '\n```\n\n' + + '\n```\n' + 'Using the "quick resolve" button below will roll over any datastreams and set all incompatible indices to read-only.\n\n' + 'Alternatively, manually deleting these indices and data streams will also unblock your upgrade.'; } else { @@ -347,13 +356,13 @@ export async function getEnterpriseSearchPre8IndexDeprecations( i18n.translate( 'xpack.enterpriseSearch.deprecations.incompatibleEnterpriseSearchIndexes.deleteIndices', { - defaultMessage: 'Set all incompatible indices to read only, or', + defaultMessage: 'Set all incompatible indices and data streams to read only, or', } ), i18n.translate( 'xpack.enterpriseSearch.deprecations.incompatibleEnterpriseSearchIndexes.deleteIndices', { - defaultMessage: 'Delete all incompatible indices', + defaultMessage: 'Delete all incompatible indices and data streams', } ), ], diff --git a/x-pack/solutions/search/plugins/enterprise_search/server/deprecations/pre_eight_index_deprecator.test.ts b/x-pack/solutions/search/plugins/enterprise_search/server/deprecations/pre_eight_index_deprecator.test.ts index 81e17bb1b5ebe..5603bc844411c 100644 --- a/x-pack/solutions/search/plugins/enterprise_search/server/deprecations/pre_eight_index_deprecator.test.ts +++ b/x-pack/solutions/search/plugins/enterprise_search/server/deprecations/pre_eight_index_deprecator.test.ts @@ -86,6 +86,15 @@ const testIndices = { }, }; +const additionalDatastreams = { + 'logs-app_search.testdatastream': { + indices: [ + { index_name: 'non-existingindex' }, + { index_name: '.ent-search-with_same_data_stream' }, + ], + }, +}; + const testIndicesWithoutDatastream = { '.ent-search-already_read_only': { settings: { @@ -137,11 +146,38 @@ function getMockIndicesFxn(values: any) { }); } +function getMockDatastreamsFxn(values: any) { + return jest.fn((params) => { + const prefixes = []; + const names = params.name.split(','); + for (const name of names) { + if (name.endsWith('*')) { + prefixes.push(name.slice(0, -1)); + } else { + prefixes.push(name); + } + } + + const ret: any = {}; + for (const [datastream, datastreamData] of Object.entries(values)) { + for (const prefix of prefixes) { + if (datastream.startsWith(prefix)) { + ret[datastream] = datastreamData; + break; + } + } + return Promise.resolve(ret); + } + }); +} + describe('getPreEightEnterpriseSearchIndices', () => { const getIndicesMock = getMockIndicesFxn(testIndices); + const getDatastreamsMock = getMockDatastreamsFxn(additionalDatastreams); const esClientMock = { indices: { get: getIndicesMock, + getDataStream: getDatastreamsMock, }, } as unknown as ElasticsearchClient; @@ -150,23 +186,23 @@ describe('getPreEightEnterpriseSearchIndices', () => { expect(indices).toEqual([ { name: '.ent-search-index_without_datastream', - isDatastream: false, - datastreamName: '', + hasDatastream: false, + datastreams: [''], }, { name: '.ent-search-with_data_stream', - isDatastream: true, - datastreamName: 'datastream-testing', + hasDatastream: true, + datastreams: ['datastream-testing'], }, { name: '.ent-search-with_another_data_stream', - isDatastream: true, - datastreamName: 'datastream-testing-another', + hasDatastream: true, + datastreams: ['datastream-testing-another'], }, { name: '.ent-search-with_same_data_stream', - isDatastream: true, - datastreamName: 'datastream-testing', + hasDatastream: true, + datastreams: ['datastream-testing', 'logs-app_search.testdatastream'], }, ]); }); @@ -175,11 +211,13 @@ describe('getPreEightEnterpriseSearchIndices', () => { describe('setPreEightEnterpriseSearchIndicesReadOnly', () => { it('does not rollover datastreams if there are none', async () => { const getIndicesMock = getMockIndicesFxn(testIndicesWithoutDatastream); + const getDatastreamsMock = jest.fn(() => Promise.resolve({})); const rolloverMock = jest.fn(() => Promise.resolve(true)); const addBlockMock = jest.fn(() => Promise.resolve({ acknowledged: true })); const esClientMock = { indices: { get: getIndicesMock, + getDataStream: getDatastreamsMock, rollover: rolloverMock, addBlock: addBlockMock, }, @@ -194,11 +232,13 @@ describe('setPreEightEnterpriseSearchIndicesReadOnly', () => { it('does rollover datastreams if there are any', async () => { const getIndicesMock = getMockIndicesFxn(testIndices); + const getDatastreamsMock = getMockDatastreamsFxn(additionalDatastreams); const rolloverMock = jest.fn(() => Promise.resolve(true)); const addBlockMock = jest.fn(() => Promise.resolve({ acknowledged: true })); const esClientMock = { indices: { get: getIndicesMock, + getDataStream: getDatastreamsMock, rollover: rolloverMock, addBlock: addBlockMock, }, @@ -207,7 +247,7 @@ describe('setPreEightEnterpriseSearchIndicesReadOnly', () => { const result = await setPreEightEnterpriseSearchIndicesReadOnly(esClientMock); expect(result).toEqual(''); expect(getIndicesMock).toHaveBeenCalledTimes(2); - expect(rolloverMock).toHaveBeenCalledTimes(2); + expect(rolloverMock).toHaveBeenCalledTimes(3); expect(addBlockMock).toHaveBeenCalledTimes(4); }); }); diff --git a/x-pack/solutions/search/plugins/enterprise_search/server/deprecations/pre_eight_index_deprecator.ts b/x-pack/solutions/search/plugins/enterprise_search/server/deprecations/pre_eight_index_deprecator.ts index 869c0da52eb72..58033966ce1d4 100644 --- a/x-pack/solutions/search/plugins/enterprise_search/server/deprecations/pre_eight_index_deprecator.ts +++ b/x-pack/solutions/search/plugins/enterprise_search/server/deprecations/pre_eight_index_deprecator.ts @@ -8,11 +8,17 @@ import { ElasticsearchClient } from '@kbn/core/server'; const ENT_SEARCH_INDEX_PREFIX = '.ent-search-'; +const ENT_SEARCH_DATASTREAM_PATTERN = [ + 'logs-enterprise_search.*', + 'logs-app_search.*', + 'logs-workplace_search.*', + 'logs-crawler-*', +]; export interface EnterpriseSearchIndexMapping { name: string; - isDatastream: boolean; - datastreamName: string; + hasDatastream: boolean; + datastreams: string[]; } export async function getPreEightEnterpriseSearchIndices( @@ -24,9 +30,10 @@ export async function getPreEightEnterpriseSearchIndices( expand_wildcards: ['all'], }); - if (!entSearchIndices) { - return []; - } + const entSearchDatastreams = await esClient.indices.getDataStream({ + name: ENT_SEARCH_DATASTREAM_PATTERN.join(','), + expand_wildcards: ['all'], + }); const returnIndices: EnterpriseSearchIndexMapping[] = []; for (const [index, indexData] of Object.entries(entSearchIndices)) { @@ -37,8 +44,28 @@ export async function getPreEightEnterpriseSearchIndices( const dataStreamName = indexData.data_stream; returnIndices.push({ name: index, - isDatastream: dataStreamName ? true : false, - datastreamName: dataStreamName ?? '', + hasDatastream: dataStreamName ? true : false, + datastreams: [dataStreamName ?? ''], + }); + } + } + + for (const [datastream, datastreamData] of Object.entries(entSearchDatastreams)) { + if (!datastreamData.indices || datastreamData.indices.length === 0) { + continue; + } + + // only get the last index, as this the current write index + const lastIndexName = datastreamData.indices[datastreamData.indices.length - 1].index_name; + const existingIndex = returnIndices.find((index) => index.name === lastIndexName); + if (existingIndex) { + existingIndex.hasDatastream = true; + existingIndex.datastreams.push(datastream); + } else { + returnIndices.push({ + name: lastIndexName, + hasDatastream: true, + datastreams: [datastream], }); } } @@ -55,14 +82,20 @@ export async function setPreEightEnterpriseSearchIndicesReadOnly( // rollover any datastreams first const rolledOverDatastreams: { [id: string]: boolean } = {}; for (const index of indices) { - if (index.isDatastream && !rolledOverDatastreams[index.datastreamName]) { - const indexResponse = await esClient.indices.rollover({ alias: index.datastreamName }); + if (index.hasDatastream) { + for (const datastream of index.datastreams) { + if (datastream.length === 0 || rolledOverDatastreams[datastream]) { + continue; + } - if (!indexResponse) { - return `Could not roll over datastream: ${index.name}`; - } + const indexResponse = await esClient.indices.rollover({ alias: datastream }); + + if (!indexResponse) { + return `Could not roll over datastream: ${index.name}`; + } - rolledOverDatastreams[index.datastreamName] = true; + rolledOverDatastreams[datastream] = true; + } } } diff --git a/x-pack/solutions/search/plugins/enterprise_search/server/index.ts b/x-pack/solutions/search/plugins/enterprise_search/server/index.ts index 9b27a0b652ddd..2f32aaf0d0694 100644 --- a/x-pack/solutions/search/plugins/enterprise_search/server/index.ts +++ b/x-pack/solutions/search/plugins/enterprise_search/server/index.ts @@ -64,11 +64,6 @@ export const config: PluginConfigDescriptor = { level: 'critical', title: ENT_SEARCH_NODE_DEPRECATION_TITLE, }), - deprecate('customHeaders', '9.0.0', { - documentationUrl: context.docLinks.enterpriseSearch.upgrade9x, - level: 'critical', - title: ENT_SEARCH_NODE_DEPRECATION_TITLE, - }), deprecate('isCloud', '9.0.0', { level: 'critical', }), From 7a1c2dbeb23d27bf35d7e0de82b46940d24ea138 Mon Sep 17 00:00:00 2001 From: "Mark J. Hoy" Date: Thu, 20 Feb 2025 09:22:39 -0500 Subject: [PATCH 2/7] use verified_read_only; expand hidden wildcards --- .../deprecations/pre_eight_index_deprecator.test.ts | 2 ++ .../server/deprecations/pre_eight_index_deprecator.ts | 10 ++++------ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/x-pack/solutions/search/plugins/enterprise_search/server/deprecations/pre_eight_index_deprecator.test.ts b/x-pack/solutions/search/plugins/enterprise_search/server/deprecations/pre_eight_index_deprecator.test.ts index 5603bc844411c..d1e01ab77e9c3 100644 --- a/x-pack/solutions/search/plugins/enterprise_search/server/deprecations/pre_eight_index_deprecator.test.ts +++ b/x-pack/solutions/search/plugins/enterprise_search/server/deprecations/pre_eight_index_deprecator.test.ts @@ -32,6 +32,7 @@ const testIndices = { blocks: { write: 'true', }, + verified_read_only: 'true', }, }, data_stream: 'datastream-123', @@ -105,6 +106,7 @@ const testIndicesWithoutDatastream = { blocks: { write: 'true', }, + verified_read_only: 'true', }, }, }, diff --git a/x-pack/solutions/search/plugins/enterprise_search/server/deprecations/pre_eight_index_deprecator.ts b/x-pack/solutions/search/plugins/enterprise_search/server/deprecations/pre_eight_index_deprecator.ts index 58033966ce1d4..a9e9ee01e6cdf 100644 --- a/x-pack/solutions/search/plugins/enterprise_search/server/deprecations/pre_eight_index_deprecator.ts +++ b/x-pack/solutions/search/plugins/enterprise_search/server/deprecations/pre_eight_index_deprecator.ts @@ -27,20 +27,18 @@ export async function getPreEightEnterpriseSearchIndices( const entSearchIndices = await esClient.indices.get({ index: `${ENT_SEARCH_INDEX_PREFIX}*`, ignore_unavailable: true, - expand_wildcards: ['all'], + expand_wildcards: ['all', 'hidden'], }); const entSearchDatastreams = await esClient.indices.getDataStream({ name: ENT_SEARCH_DATASTREAM_PATTERN.join(','), - expand_wildcards: ['all'], + expand_wildcards: ['all', 'hidden'], }); const returnIndices: EnterpriseSearchIndexMapping[] = []; for (const [index, indexData] of Object.entries(entSearchIndices)) { - if ( - indexData.settings?.index?.version?.created?.startsWith('7') && - indexData.settings?.index?.blocks?.write !== 'true' - ) { + const isReadOnly = indexData.settings?.index?.verified_read_only ?? 'false'; + if (indexData.settings?.index?.version?.created?.startsWith('7') && isReadOnly !== 'true') { const dataStreamName = indexData.data_stream; returnIndices.push({ name: index, From 4eac1462f039ab6b0d748ccaec0e0619e8c9d0d8 Mon Sep 17 00:00:00 2001 From: "Mark J. Hoy" Date: Thu, 20 Feb 2025 09:53:23 -0500 Subject: [PATCH 3/7] remove crawler datastream pattern --- .../server/deprecations/pre_eight_index_deprecator.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/x-pack/solutions/search/plugins/enterprise_search/server/deprecations/pre_eight_index_deprecator.ts b/x-pack/solutions/search/plugins/enterprise_search/server/deprecations/pre_eight_index_deprecator.ts index a9e9ee01e6cdf..043a08aea058f 100644 --- a/x-pack/solutions/search/plugins/enterprise_search/server/deprecations/pre_eight_index_deprecator.ts +++ b/x-pack/solutions/search/plugins/enterprise_search/server/deprecations/pre_eight_index_deprecator.ts @@ -12,7 +12,6 @@ const ENT_SEARCH_DATASTREAM_PATTERN = [ 'logs-enterprise_search.*', 'logs-app_search.*', 'logs-workplace_search.*', - 'logs-crawler-*', ]; export interface EnterpriseSearchIndexMapping { From c305b5dbfc1ac70339da448c3ed1354fdcb3ce11 Mon Sep 17 00:00:00 2001 From: "Mark J. Hoy" Date: Fri, 21 Feb 2025 12:04:45 -0500 Subject: [PATCH 4/7] move EntSearch pre 8.x index deps to UA --- .../enterprise_search_deprecations.test.ts | 98 ++++++++++++++ .../enterprise_search_deprecations.ts | 126 ++++++++++++++++++ .../pre_eight_index_deprecator.test.ts | 1 - .../pre_eight_index_deprecator.ts | 0 .../upgrade_assistant/server/plugin.ts | 8 +- .../enterprise_search_deprecations.test.ts | 76 +++++++++++ .../routes/enterprise_search_deprecations.ts | 39 ++++++ .../server/routes/register_routes.ts | 4 + .../server/deprecations/index.test.ts | 84 ------------ .../server/deprecations/index.ts | 125 +---------------- .../enterprise_search/deprecations.test.ts | 47 ------- .../routes/enterprise_search/deprecations.ts | 26 ---- 12 files changed, 355 insertions(+), 279 deletions(-) create mode 100644 x-pack/platform/plugins/private/upgrade_assistant/server/lib/enterprise_search/enterprise_search_deprecations.test.ts create mode 100644 x-pack/platform/plugins/private/upgrade_assistant/server/lib/enterprise_search/enterprise_search_deprecations.ts rename x-pack/{solutions/search/plugins/enterprise_search/server/deprecations => platform/plugins/private/upgrade_assistant/server/lib/enterprise_search}/pre_eight_index_deprecator.test.ts (98%) rename x-pack/{solutions/search/plugins/enterprise_search/server/deprecations => platform/plugins/private/upgrade_assistant/server/lib/enterprise_search}/pre_eight_index_deprecator.ts (100%) create mode 100644 x-pack/platform/plugins/private/upgrade_assistant/server/routes/enterprise_search_deprecations.test.ts create mode 100644 x-pack/platform/plugins/private/upgrade_assistant/server/routes/enterprise_search_deprecations.ts diff --git a/x-pack/platform/plugins/private/upgrade_assistant/server/lib/enterprise_search/enterprise_search_deprecations.test.ts b/x-pack/platform/plugins/private/upgrade_assistant/server/lib/enterprise_search/enterprise_search_deprecations.test.ts new file mode 100644 index 0000000000000..94f46c124831a --- /dev/null +++ b/x-pack/platform/plugins/private/upgrade_assistant/server/lib/enterprise_search/enterprise_search_deprecations.test.ts @@ -0,0 +1,98 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import { DeprecationDetailsMessage, DeprecationsDetails } from '@kbn/core-deprecations-common'; +import { GetDeprecationsContext } from '@kbn/core-deprecations-server'; + +import { getEnterpriseSearchPre8IndexDeprecations } from './enterprise_search_deprecations'; +import indexDeprecatorFxns = require('./pre_eight_index_deprecator'); + +const ctx = { + esClient: { + asInternalUser: {}, + }, +} as GetDeprecationsContext; + +function getMessageFromDeprecation(details: DeprecationsDetails): string { + const message = details.message as DeprecationDetailsMessage; + return message.content; +} + +describe('getEnterpriseSearchPre8IndexDeprecations', () => { + it('can register index and data stream deprecations that need to be set to read only', async () => { + const getIndicesMock = jest.fn(() => + Promise.resolve([ + { + name: '.ent-search-index_without_datastream', + hasDatastream: false, + datastreams: [], + }, + { + name: '.ent-search-with_data_stream', + hasDatastream: true, + datastreams: ['datastream-testing'], + }, + ]) + ); + + jest + .spyOn(indexDeprecatorFxns, 'getPreEightEnterpriseSearchIndices') + .mockImplementation(getIndicesMock); + + const deprecations = await getEnterpriseSearchPre8IndexDeprecations(ctx, 'docsurl'); + expect(deprecations).toHaveLength(1); + expect(deprecations[0].correctiveActions.api?.path).toStrictEqual( + '/internal/enterprise_search/deprecations/set_enterprise_search_indices_read_only' + ); + expect(deprecations[0].title).toMatch('Pre 8.x Enterprise Search indices compatibility'); + expect(getMessageFromDeprecation(deprecations[0])).toContain( + 'The following indices are found to be incompatible for upgrade' + ); + expect(getMessageFromDeprecation(deprecations[0])).toContain( + '.ent-search-index_without_datastream' + ); + expect(getMessageFromDeprecation(deprecations[0])).toContain( + 'The following data streams are found to be incompatible for upgrade' + ); + expect(getMessageFromDeprecation(deprecations[0])).toContain('.ent-search-with_data_stream'); + }); + + it('can register an index without data stream deprecations that need to be set to read only', async () => { + const getIndicesMock = jest.fn(() => + Promise.resolve([ + { + name: '.ent-search-index_without_datastream', + hasDatastream: false, + datastreams: [''], + }, + ]) + ); + + jest + .spyOn(indexDeprecatorFxns, 'getPreEightEnterpriseSearchIndices') + .mockImplementation(getIndicesMock); + + const deprecations = await getEnterpriseSearchPre8IndexDeprecations(ctx, 'docsurl'); + expect(deprecations).toHaveLength(1); + expect(deprecations[0].correctiveActions.api?.path).toStrictEqual( + '/internal/enterprise_search/deprecations/set_enterprise_search_indices_read_only' + ); + expect(deprecations[0].title).toMatch('Pre 8.x Enterprise Search indices compatibility'); + expect(getMessageFromDeprecation(deprecations[0])).toContain( + 'The following indices are found to be incompatible for upgrade' + ); + expect(getMessageFromDeprecation(deprecations[0])).toContain( + '.ent-search-index_without_datastream' + ); + expect(getMessageFromDeprecation(deprecations[0])).not.toContain( + 'The following data streams are found to be incompatible for upgrade' + ); + expect(getMessageFromDeprecation(deprecations[0])).not.toContain( + '.ent-search-with_data_stream' + ); + }); +}); diff --git a/x-pack/platform/plugins/private/upgrade_assistant/server/lib/enterprise_search/enterprise_search_deprecations.ts b/x-pack/platform/plugins/private/upgrade_assistant/server/lib/enterprise_search/enterprise_search_deprecations.ts new file mode 100644 index 0000000000000..311fe1f797007 --- /dev/null +++ b/x-pack/platform/plugins/private/upgrade_assistant/server/lib/enterprise_search/enterprise_search_deprecations.ts @@ -0,0 +1,126 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import { DeprecationsDetails } from '@kbn/core-deprecations-common'; +import { GetDeprecationsContext, RegisterDeprecationsConfig } from '@kbn/core-deprecations-server'; + +import { i18n } from '@kbn/i18n'; +import { getPreEightEnterpriseSearchIndices } from './pre_eight_index_deprecator'; + +export const getEntepriseSearchRegisteredDeprecations = ( + docsUrl: string +): RegisterDeprecationsConfig => { + return { + getDeprecations: async (ctx: GetDeprecationsContext) => { + const [entSearchIndexIncompatibility] = await Promise.all([ + getEnterpriseSearchPre8IndexDeprecations(ctx, docsUrl), + ]); + return [...entSearchIndexIncompatibility]; + }, + }; +}; + +/** + * If there are any Enterprise Search indices that were created with Elasticsearch 7.x, they must be removed + * or set to read-only + */ +export async function getEnterpriseSearchPre8IndexDeprecations( + ctx: GetDeprecationsContext, + docsUrl: string +): Promise { + const deprecations: DeprecationsDetails[] = []; + + const entSearchIndices = await getPreEightEnterpriseSearchIndices(ctx.esClient.asInternalUser); + if (!entSearchIndices || entSearchIndices.length === 0) { + return deprecations; + } + + let indicesList = ''; + let datastreamsList = ''; + for (const index of entSearchIndices) { + if (index.hasDatastream) { + indicesList += `${index.name}\n`; + for (const datastream of index.datastreams) { + if (datastream === '') continue; + datastreamsList += `${datastream}\n`; + } + } else { + indicesList += `${index.name}\n`; + } + } + + let message = `There are ${entSearchIndices.length} incompatible Enterprise Search indices.\n\n`; + + if (indicesList.length > 0) { + message += + 'The following indices are found to be incompatible for upgrade:\n\n' + + '```\n' + + `${indicesList}` + + '\n```\n' + + 'These indices must be either set to read-only or deleted before upgrading.\n'; + } + + if (datastreamsList.length > 0) { + message += + '\nThe following data streams are found to be incompatible for upgrade:\n\n' + + '```\n' + + `${datastreamsList}` + + '\n```\n' + + 'Using the "quick resolve" button below will roll over any datastreams and set all incompatible indices to read-only.\n\n' + + 'Alternatively, manually deleting these indices and data streams will also unblock your upgrade.'; + } else { + message += + 'Setting these indices to read-only can be attempted with the "quick resolve" button below.\n\n' + + 'Alternatively, manually deleting these indices will also unblock your upgrade.'; + } + + deprecations.push({ + level: 'critical', + deprecationType: 'feature', + title: i18n.translate( + 'xpack.upgradeAssistant.deprecations.incompatibleEnterpriseSearchIndexes.title', + { + defaultMessage: 'Pre 8.x Enterprise Search indices compatibility', + } + ), + message: { + type: 'markdown', + content: i18n.translate( + 'xpack.upgradeAssistant.deprecations.incompatibleEnterpriseSearchIndexes.message', + { + defaultMessage: message, + } + ), + }, + documentationUrl: docsUrl, + correctiveActions: { + manualSteps: [ + i18n.translate( + 'xpack.upgradeAssistant.deprecations.incompatibleEnterpriseSearchIndexes.deleteIndices', + { + defaultMessage: 'Set all incompatible indices and data streams to read only, or', + } + ), + i18n.translate( + 'xpack.upgradeAssistant.deprecations.incompatibleEnterpriseSearchIndexes.deleteIndices', + { + defaultMessage: 'Delete all incompatible indices and data streams', + } + ), + ], + api: { + method: 'POST', + path: '/internal/enterprise_search/deprecations/set_enterprise_search_indices_read_only', + body: { + deprecationDetails: { domainId: 'enterpriseSearch' }, + }, + }, + }, + }); + + return deprecations; +} diff --git a/x-pack/solutions/search/plugins/enterprise_search/server/deprecations/pre_eight_index_deprecator.test.ts b/x-pack/platform/plugins/private/upgrade_assistant/server/lib/enterprise_search/pre_eight_index_deprecator.test.ts similarity index 98% rename from x-pack/solutions/search/plugins/enterprise_search/server/deprecations/pre_eight_index_deprecator.test.ts rename to x-pack/platform/plugins/private/upgrade_assistant/server/lib/enterprise_search/pre_eight_index_deprecator.test.ts index d1e01ab77e9c3..f324aef14ea63 100644 --- a/x-pack/solutions/search/plugins/enterprise_search/server/deprecations/pre_eight_index_deprecator.test.ts +++ b/x-pack/platform/plugins/private/upgrade_assistant/server/lib/enterprise_search/pre_eight_index_deprecator.test.ts @@ -12,7 +12,6 @@ import { setPreEightEnterpriseSearchIndicesReadOnly, } from './pre_eight_index_deprecator'; -// settings?.index?.version?.created?.startsWith('7') && indexData.settings?.index?.blocks?.write !== 'true' const testIndices = { 'non-ent-search-index': { settings: { diff --git a/x-pack/solutions/search/plugins/enterprise_search/server/deprecations/pre_eight_index_deprecator.ts b/x-pack/platform/plugins/private/upgrade_assistant/server/lib/enterprise_search/pre_eight_index_deprecator.ts similarity index 100% rename from x-pack/solutions/search/plugins/enterprise_search/server/deprecations/pre_eight_index_deprecator.ts rename to x-pack/platform/plugins/private/upgrade_assistant/server/lib/enterprise_search/pre_eight_index_deprecator.ts diff --git a/x-pack/platform/plugins/private/upgrade_assistant/server/plugin.ts b/x-pack/platform/plugins/private/upgrade_assistant/server/plugin.ts index 9641fd52ed324..ae80ba7dbfd37 100644 --- a/x-pack/platform/plugins/private/upgrade_assistant/server/plugin.ts +++ b/x-pack/platform/plugins/private/upgrade_assistant/server/plugin.ts @@ -38,6 +38,7 @@ import { handleEsError } from './shared_imports'; import { RouteDependencies } from './types'; import type { UpgradeAssistantConfig } from './config'; import type { FeatureSet } from '../common/types'; +import { getEntepriseSearchRegisteredDeprecations } from './lib/enterprise_search/enterprise_search_deprecations'; interface PluginsSetup { usageCollection: UsageCollectionSetup; @@ -82,7 +83,7 @@ export class UpgradeAssistantServerPlugin implements Plugin { } setup( - { http, getStartServices, savedObjects }: CoreSetup, + { http, deprecations, getStartServices, savedObjects, docLinks }: CoreSetup, { usageCollection, features, licensing, logsShared, security }: PluginsSetup ) { this.licensing = licensing; @@ -147,6 +148,11 @@ export class UpgradeAssistantServerPlugin implements Plugin { registerRoutes(dependencies, this.getWorker.bind(this)); + // Register deprecations for Enterprise Search pre-8 indices + deprecations.registerDeprecations({ + ...getEntepriseSearchRegisteredDeprecations(docLinks.links.enterpriseSearch.upgrade9x), + }); + if (usageCollection) { void getStartServices().then(([{ elasticsearch }]) => { registerUpgradeAssistantUsageCollector({ diff --git a/x-pack/platform/plugins/private/upgrade_assistant/server/routes/enterprise_search_deprecations.test.ts b/x-pack/platform/plugins/private/upgrade_assistant/server/routes/enterprise_search_deprecations.test.ts new file mode 100644 index 0000000000000..6c46538d54d1a --- /dev/null +++ b/x-pack/platform/plugins/private/upgrade_assistant/server/routes/enterprise_search_deprecations.test.ts @@ -0,0 +1,76 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import { kibanaResponseFactory } from '@kbn/core/server'; + +import { handleEsError } from '../shared_imports'; +import { createMockRouter, MockRouter, routeHandlerContextMock } from './__mocks__/routes.mock'; +import { createRequestMock } from './__mocks__/request.mock'; + +jest.mock('../lib/es_version_precheck', () => ({ + versionCheckHandlerWrapper: (a: any) => a, +})); + +import indexDeprecatorFxns = require('../lib/enterprise_search/pre_eight_index_deprecator'); + +import { registerEnterpriseSearchDeprecationRoutes } from './enterprise_search_deprecations'; + +describe('deprecation routes', () => { + let routeDependencies: any; + + describe('POST /internal/enterprise_search/deprecations/set_enterprise_search_indices_read_only', () => { + let mockRouter: MockRouter; + + function registerMockRouter({ mlSnapshots } = { mlSnapshots: true }) { + mockRouter = createMockRouter(); + routeDependencies = { + config: { + featureSet: { mlSnapshots, migrateSystemIndices: true, reindexCorrectiveActions: true }, + }, + router: mockRouter, + lib: { handleEsError }, + }; + registerEnterpriseSearchDeprecationRoutes(routeDependencies); + } + + beforeEach(() => { + registerMockRouter(); + }); + + afterEach(() => { + jest.resetAllMocks(); + }); + + it('sets read-only and 200s correctly in happy path', async () => { + const setIndicesReadOnlyMock = jest.spyOn( + indexDeprecatorFxns, + 'setPreEightEnterpriseSearchIndicesReadOnly' + ); + + setIndicesReadOnlyMock.mockResolvedValue(''); + + const resp = await routeDependencies.router.getHandler({ + method: 'post', + pathPattern: + '/internal/enterprise_search/deprecations/set_enterprise_search_indices_read_only', + })( + routeHandlerContextMock, + createRequestMock({ + body: { deprecationDetails: { domainId: 'enterpriseSearch' } }, + }), + kibanaResponseFactory + ); + + expect(resp.status).toEqual(200); + expect(resp.payload).toEqual({ + acknowedged: true, + }); + + expect(setIndicesReadOnlyMock).toHaveBeenCalledTimes(1); + }); + }); +}); diff --git a/x-pack/platform/plugins/private/upgrade_assistant/server/routes/enterprise_search_deprecations.ts b/x-pack/platform/plugins/private/upgrade_assistant/server/routes/enterprise_search_deprecations.ts new file mode 100644 index 0000000000000..a712687fd04a0 --- /dev/null +++ b/x-pack/platform/plugins/private/upgrade_assistant/server/routes/enterprise_search_deprecations.ts @@ -0,0 +1,39 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import { setPreEightEnterpriseSearchIndicesReadOnly } from '../lib/enterprise_search/pre_eight_index_deprecator'; +import { versionCheckHandlerWrapper } from '../lib/es_version_precheck'; +import { RouteDependencies } from '../types'; + +export function registerEnterpriseSearchDeprecationRoutes({ + config: { featureSet }, + router, + lib: { handleEsError }, + licensing, + log, +}: RouteDependencies) { + router.post( + { + path: '/internal/enterprise_search/deprecations/set_enterprise_search_indices_read_only', + validate: {}, + }, + versionCheckHandlerWrapper(async ({ core }, request, response) => { + const { client } = (await core).elasticsearch; + const setResponse = await setPreEightEnterpriseSearchIndicesReadOnly(client.asCurrentUser); + if (setResponse.length > 0) { + return response.badRequest({ + body: { message: setResponse }, + headers: { 'content-type': 'application/json' }, + }); + } + return response.ok({ + body: { acknowedged: true }, + headers: { 'content-type': 'application/json' }, + }); + }) + ); +} diff --git a/x-pack/platform/plugins/private/upgrade_assistant/server/routes/register_routes.ts b/x-pack/platform/plugins/private/upgrade_assistant/server/routes/register_routes.ts index c94a4a378a360..f220c8d7aff78 100644 --- a/x-pack/platform/plugins/private/upgrade_assistant/server/routes/register_routes.ts +++ b/x-pack/platform/plugins/private/upgrade_assistant/server/routes/register_routes.ts @@ -23,6 +23,7 @@ import { registerNodeDiskSpaceRoute } from './node_disk_space'; import { registerClusterSettingsRoute } from './cluster_settings'; import { registerMigrateDataStreamRoutes } from './migrate_data_streams'; import { registerUpdateIndexRoute } from './update_index'; +import { registerEnterpriseSearchDeprecationRoutes } from './enterprise_search_deprecations'; export function registerRoutes(dependencies: RouteDependencies, getWorker: () => ReindexWorker) { registerAppRoutes(dependencies); @@ -47,4 +48,7 @@ export function registerRoutes(dependencies: RouteDependencies, getWorker: () => // Mark index as read-only and unfreeze it registerUpdateIndexRoute(dependencies); + + // Enterprise Search deprecations + registerEnterpriseSearchDeprecationRoutes(dependencies); } diff --git a/x-pack/solutions/search/plugins/enterprise_search/server/deprecations/index.test.ts b/x-pack/solutions/search/plugins/enterprise_search/server/deprecations/index.test.ts index c0d3893fb2f0c..99f14365591f4 100644 --- a/x-pack/solutions/search/plugins/enterprise_search/server/deprecations/index.test.ts +++ b/x-pack/solutions/search/plugins/enterprise_search/server/deprecations/index.test.ts @@ -15,19 +15,15 @@ jest.mock('@kbn/search-connectors', () => { fetchConnectors: () => mockedFetchConnectors(), }; }); -import { DeprecationDetailsMessage, DeprecationsDetails } from '@kbn/core-deprecations-common'; import { GetDeprecationsContext } from '@kbn/core-deprecations-server'; import { Connector } from '@kbn/search-connectors'; import { ConfigType } from '..'; -import indexDeprecatorFxns = require('./pre_eight_index_deprecator'); - import { getCrawlerDeprecations, getEnterpriseSearchNodeDeprecation, - getEnterpriseSearchPre8IndexDeprecations, getNativeConnectorDeprecations, } from '.'; @@ -40,11 +36,6 @@ const cloud = { baseUrl: 'cloud.elastic.co', deploymentId: '123', cloudId: 'abc' const notCloud = {} as CloudSetup; const docsUrl = 'example.com'; -function getMessageFromDeprecation(details: DeprecationsDetails): string { - const message = details.message as DeprecationDetailsMessage; - return message.content; -} - describe('Enterprise Search node deprecation', () => { it('Tells you to remove capacity if running on cloud', () => { const config = { host: 'example.com' } as ConfigType; @@ -136,78 +127,3 @@ describe('Native connector deprecations', () => { expect(deprecations[0].title).toMatch('Elastic-managed connectors are no longer supported'); }); }); - -describe('getEnterpriseSearchPre8IndexDeprecations', () => { - it('can register index and data stream deprecations that need to be set to read only', async () => { - const getIndicesMock = jest.fn(() => - Promise.resolve([ - { - name: '.ent-search-index_without_datastream', - hasDatastream: false, - datastreams: [], - }, - { - name: '.ent-search-with_data_stream', - hasDatastream: true, - datastreams: ['datastream-testing'], - }, - ]) - ); - - jest - .spyOn(indexDeprecatorFxns, 'getPreEightEnterpriseSearchIndices') - .mockImplementation(getIndicesMock); - - const deprecations = await getEnterpriseSearchPre8IndexDeprecations(ctx, 'docsurl', 'mockhost'); - expect(deprecations).toHaveLength(1); - expect(deprecations[0].correctiveActions.api?.path).toStrictEqual( - '/internal/enterprise_search/deprecations/set_enterprise_search_indices_read_only' - ); - expect(deprecations[0].title).toMatch('Pre 8.x Enterprise Search indices compatibility'); - expect(getMessageFromDeprecation(deprecations[0])).toContain( - 'The following indices are found to be incompatible for upgrade' - ); - expect(getMessageFromDeprecation(deprecations[0])).toContain( - '.ent-search-index_without_datastream' - ); - expect(getMessageFromDeprecation(deprecations[0])).toContain( - 'The following data streams are found to be incompatible for upgrade' - ); - expect(getMessageFromDeprecation(deprecations[0])).toContain('.ent-search-with_data_stream'); - }); - - it('can register an index without data stream deprecations that need to be set to read only', async () => { - const getIndicesMock = jest.fn(() => - Promise.resolve([ - { - name: '.ent-search-index_without_datastream', - hasDatastream: false, - datastreams: [''], - }, - ]) - ); - - jest - .spyOn(indexDeprecatorFxns, 'getPreEightEnterpriseSearchIndices') - .mockImplementation(getIndicesMock); - - const deprecations = await getEnterpriseSearchPre8IndexDeprecations(ctx, 'docsurl', 'mockhost'); - expect(deprecations).toHaveLength(1); - expect(deprecations[0].correctiveActions.api?.path).toStrictEqual( - '/internal/enterprise_search/deprecations/set_enterprise_search_indices_read_only' - ); - expect(deprecations[0].title).toMatch('Pre 8.x Enterprise Search indices compatibility'); - expect(getMessageFromDeprecation(deprecations[0])).toContain( - 'The following indices are found to be incompatible for upgrade' - ); - expect(getMessageFromDeprecation(deprecations[0])).toContain( - '.ent-search-index_without_datastream' - ); - expect(getMessageFromDeprecation(deprecations[0])).not.toContain( - 'The following data streams are found to be incompatible for upgrade' - ); - expect(getMessageFromDeprecation(deprecations[0])).not.toContain( - '.ent-search-with_data_stream' - ); - }); -}); diff --git a/x-pack/solutions/search/plugins/enterprise_search/server/deprecations/index.ts b/x-pack/solutions/search/plugins/enterprise_search/server/deprecations/index.ts index a1363612dfaa7..ecc9bb3bb24dc 100644 --- a/x-pack/solutions/search/plugins/enterprise_search/server/deprecations/index.ts +++ b/x-pack/solutions/search/plugins/enterprise_search/server/deprecations/index.ts @@ -14,8 +14,6 @@ import { Connector, fetchConnectors } from '@kbn/search-connectors'; import { ConfigType } from '..'; -import { getPreEightEnterpriseSearchIndices } from './pre_eight_index_deprecator'; - export const getRegisteredDeprecations = ( config: ConfigType, cloud: CloudSetup, @@ -24,18 +22,11 @@ export const getRegisteredDeprecations = ( return { getDeprecations: async (ctx: GetDeprecationsContext) => { const entSearchDetails = getEnterpriseSearchNodeDeprecation(config, cloud, docsUrl); - const [crawlerDetails, nativeConnectorsDetails, entSearchIndexIncompatibility] = - await Promise.all([ - getCrawlerDeprecations(ctx, docsUrl), - getNativeConnectorDeprecations(ctx, docsUrl), - getEnterpriseSearchPre8IndexDeprecations(ctx, docsUrl, config.host), - ]); - return [ - ...entSearchDetails, - ...crawlerDetails, - ...nativeConnectorsDetails, - ...entSearchIndexIncompatibility, - ]; + const [crawlerDetails, nativeConnectorsDetails] = await Promise.all([ + getCrawlerDeprecations(ctx, docsUrl), + getNativeConnectorDeprecations(ctx, docsUrl), + ]); + return [...entSearchDetails, ...crawlerDetails, ...nativeConnectorsDetails]; }, }; }; @@ -272,109 +263,3 @@ export async function getNativeConnectorDeprecations( return deprecations; } } - -/** - * If there are any Enterprise Search indices that were created with Elasticsearch 7.x, they must be removed - * or set to read-only - */ -export async function getEnterpriseSearchPre8IndexDeprecations( - ctx: GetDeprecationsContext, - docsUrl: string, - configHost?: string -): Promise { - const deprecations: DeprecationsDetails[] = []; - - if (!configHost) { - return deprecations; - } - - const entSearchIndices = await getPreEightEnterpriseSearchIndices(ctx.esClient.asInternalUser); - if (!entSearchIndices || entSearchIndices.length === 0) { - return deprecations; - } - - let indicesList = ''; - let datastreamsList = ''; - for (const index of entSearchIndices) { - if (index.hasDatastream) { - indicesList += `${index.name}\n`; - for (const datastream of index.datastreams) { - if (datastream === '') continue; - datastreamsList += `${datastream}\n`; - } - } else { - indicesList += `${index.name}\n`; - } - } - - let message = `There are ${entSearchIndices.length} incompatible Enterprise Search indices.\n\n`; - - if (indicesList.length > 0) { - message += - 'The following indices are found to be incompatible for upgrade:\n\n' + - '```\n' + - `${indicesList}` + - '\n```\n' + - 'These indices must be either set to read-only or deleted before upgrading.\n'; - } - - if (datastreamsList.length > 0) { - message += - '\nThe following data streams are found to be incompatible for upgrade:\n\n' + - '```\n' + - `${datastreamsList}` + - '\n```\n' + - 'Using the "quick resolve" button below will roll over any datastreams and set all incompatible indices to read-only.\n\n' + - 'Alternatively, manually deleting these indices and data streams will also unblock your upgrade.'; - } else { - message += - 'Setting these indices to read-only can be attempted with the "quick resolve" button below.\n\n' + - 'Alternatively, manually deleting these indices will also unblock your upgrade.'; - } - - deprecations.push({ - level: 'critical', - deprecationType: 'feature', - title: i18n.translate( - 'xpack.enterpriseSearch.deprecations.incompatibleEnterpriseSearchIndexes.title', - { - defaultMessage: 'Pre 8.x Enterprise Search indices compatibility', - } - ), - message: { - type: 'markdown', - content: i18n.translate( - 'xpack.enterpriseSearch.deprecations.incompatibleEnterpriseSearchIndexes.message', - { - defaultMessage: message, - } - ), - }, - documentationUrl: docsUrl, - correctiveActions: { - manualSteps: [ - i18n.translate( - 'xpack.enterpriseSearch.deprecations.incompatibleEnterpriseSearchIndexes.deleteIndices', - { - defaultMessage: 'Set all incompatible indices and data streams to read only, or', - } - ), - i18n.translate( - 'xpack.enterpriseSearch.deprecations.incompatibleEnterpriseSearchIndexes.deleteIndices', - { - defaultMessage: 'Delete all incompatible indices and data streams', - } - ), - ], - api: { - method: 'POST', - path: '/internal/enterprise_search/deprecations/set_enterprise_search_indices_read_only', - body: { - deprecationDetails: { domainId: 'enterpriseSearch' }, - }, - }, - }, - }); - - return deprecations; -} diff --git a/x-pack/solutions/search/plugins/enterprise_search/server/routes/enterprise_search/deprecations.test.ts b/x-pack/solutions/search/plugins/enterprise_search/server/routes/enterprise_search/deprecations.test.ts index d297727c05995..56f60103edf60 100644 --- a/x-pack/solutions/search/plugins/enterprise_search/server/routes/enterprise_search/deprecations.test.ts +++ b/x-pack/solutions/search/plugins/enterprise_search/server/routes/enterprise_search/deprecations.test.ts @@ -15,8 +15,6 @@ import { mockDependencies, MockRouter } from '../../__mocks__'; import { RequestHandlerContext } from '@kbn/core-http-request-handler-context-server'; import { deleteConnectorById, putUpdateNative } from '@kbn/search-connectors'; -import indexDeprecatorFxns = require('../../deprecations/pre_eight_index_deprecator'); - import { registerDeprecationRoutes } from './deprecations'; describe('deprecation routes', () => { @@ -180,49 +178,4 @@ describe('deprecation routes', () => { expect(updateNativeMock).toHaveBeenCalledWith(mockClient, 'baz', false); }); }); - - describe('POST /internal/enterprise_search/deprecations/set_enterprise_search_indices_read_only', () => { - const mockClient = {}; - let mockRouter: MockRouter; - - beforeEach(() => { - jest.clearAllMocks(); - const context = { - core: Promise.resolve({ elasticsearch: { client: { asCurrentUser: mockClient } } }), - } as jest.Mocked; - mockRouter = new MockRouter({ - context, - method: 'post', - path: '/internal/enterprise_search/deprecations/set_enterprise_search_indices_read_only', - }); - - registerDeprecationRoutes({ - ...mockDependencies, - router: mockRouter.router, - }); - }); - - it('sets read-only and 200s correctly in happy path', async () => { - const setIndicesReadOnlyMock = jest.spyOn( - indexDeprecatorFxns, - 'setPreEightEnterpriseSearchIndicesReadOnly' - ); - - const request = { - body: { deprecationDetails: { domainId: 'enterpriseSearch' } }, - }; - mockRouter.shouldValidate(request); - - setIndicesReadOnlyMock.mockResolvedValue(''); - - await mockRouter.callRoute(request); - expect(setIndicesReadOnlyMock).toHaveBeenCalledTimes(1); - expect(mockRouter.response.ok).toHaveBeenCalledTimes(1); - }); - - it('fails validation without deprecation context', () => { - const request = { body: {} }; - mockRouter.shouldThrow(request); - }); - }); }); diff --git a/x-pack/solutions/search/plugins/enterprise_search/server/routes/enterprise_search/deprecations.ts b/x-pack/solutions/search/plugins/enterprise_search/server/routes/enterprise_search/deprecations.ts index 4b63c35b2ab53..daacb68e3e936 100644 --- a/x-pack/solutions/search/plugins/enterprise_search/server/routes/enterprise_search/deprecations.ts +++ b/x-pack/solutions/search/plugins/enterprise_search/server/routes/enterprise_search/deprecations.ts @@ -9,7 +9,6 @@ import { schema } from '@kbn/config-schema'; import { deleteConnectorById, putUpdateNative } from '@kbn/search-connectors'; -import { setPreEightEnterpriseSearchIndicesReadOnly } from '../../deprecations/pre_eight_index_deprecator'; import { RouteDependencies } from '../../plugin'; import { elasticsearchErrorHandler } from '../../utils/elasticsearch_error_handler'; @@ -62,29 +61,4 @@ export function registerDeprecationRoutes({ router, log }: RouteDependencies) { }); }) ); - - router.post( - { - path: '/internal/enterprise_search/deprecations/set_enterprise_search_indices_read_only', - validate: { - body: schema.object({ - deprecationDetails: schema.object({ domainId: schema.literal('enterpriseSearch') }), - }), - }, - }, - elasticsearchErrorHandler(log, async (context, request, response) => { - const { client } = (await context.core).elasticsearch; - const setResponse = await setPreEightEnterpriseSearchIndicesReadOnly(client.asCurrentUser); - if (setResponse.length > 0) { - return response.badRequest({ - body: { message: setResponse }, - headers: { 'content-type': 'application/json' }, - }); - } - return response.ok({ - body: { acknowedged: true }, - headers: { 'content-type': 'application/json' }, - }); - }) - ); } From 28575a255090230b8272ed888448c2d705294b6a Mon Sep 17 00:00:00 2001 From: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Date: Fri, 21 Feb 2025 17:19:06 +0000 Subject: [PATCH 5/7] [CI] Auto-commit changed files from 'node scripts/yarn_deduplicate' --- .../platform/plugins/private/upgrade_assistant/tsconfig.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/x-pack/platform/plugins/private/upgrade_assistant/tsconfig.json b/x-pack/platform/plugins/private/upgrade_assistant/tsconfig.json index 4dba530b7c0e8..befeddd09be1c 100644 --- a/x-pack/platform/plugins/private/upgrade_assistant/tsconfig.json +++ b/x-pack/platform/plugins/private/upgrade_assistant/tsconfig.json @@ -43,7 +43,9 @@ "@kbn/core-logging-server-mocks", "@kbn/core-http-server-mocks", "@kbn/core-http-server-utils", - "@kbn/core-elasticsearch-server" + "@kbn/core-elasticsearch-server", + "@kbn/core-deprecations-common", + "@kbn/core-deprecations-server" ], "exclude": [ "target/**/*", From 6713b5dde5f37fef2bb9d6bc32b3bf3431316927 Mon Sep 17 00:00:00 2001 From: "Mark J. Hoy" Date: Mon, 24 Feb 2025 09:08:12 -0500 Subject: [PATCH 6/7] move routing; add codeowners --- .github/CODEOWNERS | 1 + ...nterprise_search_deprecations_routes.test.ts} | 16 ++++++++++------ .../enterprise_search_deprecations_routes.ts} | 6 +++--- .../server/routes/register_routes.ts | 2 +- 4 files changed, 15 insertions(+), 10 deletions(-) rename x-pack/platform/plugins/private/upgrade_assistant/server/{routes/enterprise_search_deprecations.test.ts => lib/enterprise_search/enterprise_search_deprecations_routes.test.ts} (83%) rename x-pack/platform/plugins/private/upgrade_assistant/server/{routes/enterprise_search_deprecations.ts => lib/enterprise_search/enterprise_search_deprecations_routes.ts} (82%) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index e948dc8db9b9a..7e7f014d1139c 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1024,6 +1024,7 @@ src/platform/plugins/shared/unified_search @elastic/kibana-visualizations src/platform/packages/private/kbn-unsaved-changes-badge @elastic/kibana-data-discovery src/platform/packages/shared/kbn-unsaved-changes-prompt @elastic/kibana-management x-pack/platform/plugins/private/upgrade_assistant @elastic/kibana-management +x-pack/platform/plugins/private/upgrade_assistant/server/lib/enterprise_search @elastic/search-kibana x-pack/solutions/observability/plugins/uptime @elastic/obs-ux-management-team x-pack/platform/plugins/private/drilldowns/url_drilldown @elastic/appex-sharedux src/platform/plugins/private/url_forwarding @elastic/kibana-visualizations diff --git a/x-pack/platform/plugins/private/upgrade_assistant/server/routes/enterprise_search_deprecations.test.ts b/x-pack/platform/plugins/private/upgrade_assistant/server/lib/enterprise_search/enterprise_search_deprecations_routes.test.ts similarity index 83% rename from x-pack/platform/plugins/private/upgrade_assistant/server/routes/enterprise_search_deprecations.test.ts rename to x-pack/platform/plugins/private/upgrade_assistant/server/lib/enterprise_search/enterprise_search_deprecations_routes.test.ts index 6c46538d54d1a..7b885729daddd 100644 --- a/x-pack/platform/plugins/private/upgrade_assistant/server/routes/enterprise_search_deprecations.test.ts +++ b/x-pack/platform/plugins/private/upgrade_assistant/server/lib/enterprise_search/enterprise_search_deprecations_routes.test.ts @@ -7,17 +7,21 @@ import { kibanaResponseFactory } from '@kbn/core/server'; -import { handleEsError } from '../shared_imports'; -import { createMockRouter, MockRouter, routeHandlerContextMock } from './__mocks__/routes.mock'; -import { createRequestMock } from './__mocks__/request.mock'; +import { handleEsError } from '../../shared_imports'; +import { + createMockRouter, + MockRouter, + routeHandlerContextMock, +} from '../../routes/__mocks__/routes.mock'; +import { createRequestMock } from '../../routes/__mocks__/request.mock'; -jest.mock('../lib/es_version_precheck', () => ({ +jest.mock('../es_version_precheck', () => ({ versionCheckHandlerWrapper: (a: any) => a, })); -import indexDeprecatorFxns = require('../lib/enterprise_search/pre_eight_index_deprecator'); +import indexDeprecatorFxns = require('./pre_eight_index_deprecator'); -import { registerEnterpriseSearchDeprecationRoutes } from './enterprise_search_deprecations'; +import { registerEnterpriseSearchDeprecationRoutes } from './enterprise_search_deprecations_routes'; describe('deprecation routes', () => { let routeDependencies: any; diff --git a/x-pack/platform/plugins/private/upgrade_assistant/server/routes/enterprise_search_deprecations.ts b/x-pack/platform/plugins/private/upgrade_assistant/server/lib/enterprise_search/enterprise_search_deprecations_routes.ts similarity index 82% rename from x-pack/platform/plugins/private/upgrade_assistant/server/routes/enterprise_search_deprecations.ts rename to x-pack/platform/plugins/private/upgrade_assistant/server/lib/enterprise_search/enterprise_search_deprecations_routes.ts index a712687fd04a0..6dcc023500545 100644 --- a/x-pack/platform/plugins/private/upgrade_assistant/server/routes/enterprise_search_deprecations.ts +++ b/x-pack/platform/plugins/private/upgrade_assistant/server/lib/enterprise_search/enterprise_search_deprecations_routes.ts @@ -5,9 +5,9 @@ * 2.0. */ -import { setPreEightEnterpriseSearchIndicesReadOnly } from '../lib/enterprise_search/pre_eight_index_deprecator'; -import { versionCheckHandlerWrapper } from '../lib/es_version_precheck'; -import { RouteDependencies } from '../types'; +import { setPreEightEnterpriseSearchIndicesReadOnly } from './pre_eight_index_deprecator'; +import { versionCheckHandlerWrapper } from '../es_version_precheck'; +import { RouteDependencies } from '../../types'; export function registerEnterpriseSearchDeprecationRoutes({ config: { featureSet }, diff --git a/x-pack/platform/plugins/private/upgrade_assistant/server/routes/register_routes.ts b/x-pack/platform/plugins/private/upgrade_assistant/server/routes/register_routes.ts index f220c8d7aff78..e65b665092588 100644 --- a/x-pack/platform/plugins/private/upgrade_assistant/server/routes/register_routes.ts +++ b/x-pack/platform/plugins/private/upgrade_assistant/server/routes/register_routes.ts @@ -23,7 +23,7 @@ import { registerNodeDiskSpaceRoute } from './node_disk_space'; import { registerClusterSettingsRoute } from './cluster_settings'; import { registerMigrateDataStreamRoutes } from './migrate_data_streams'; import { registerUpdateIndexRoute } from './update_index'; -import { registerEnterpriseSearchDeprecationRoutes } from './enterprise_search_deprecations'; +import { registerEnterpriseSearchDeprecationRoutes } from '../lib/enterprise_search/enterprise_search_deprecations_routes'; export function registerRoutes(dependencies: RouteDependencies, getWorker: () => ReindexWorker) { registerAppRoutes(dependencies); From b62b2ab1c24785bdf7faf3d8729dc50d8a94c8be Mon Sep 17 00:00:00 2001 From: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Date: Mon, 24 Feb 2025 14:19:46 +0000 Subject: [PATCH 7/7] [CI] Auto-commit changed files from 'node scripts/build_plugin_list_docs' --- .github/CODEOWNERS | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 7e7f014d1139c..e948dc8db9b9a 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1024,7 +1024,6 @@ src/platform/plugins/shared/unified_search @elastic/kibana-visualizations src/platform/packages/private/kbn-unsaved-changes-badge @elastic/kibana-data-discovery src/platform/packages/shared/kbn-unsaved-changes-prompt @elastic/kibana-management x-pack/platform/plugins/private/upgrade_assistant @elastic/kibana-management -x-pack/platform/plugins/private/upgrade_assistant/server/lib/enterprise_search @elastic/search-kibana x-pack/solutions/observability/plugins/uptime @elastic/obs-ux-management-team x-pack/platform/plugins/private/drilldowns/url_drilldown @elastic/appex-sharedux src/platform/plugins/private/url_forwarding @elastic/kibana-visualizations