From d6e244e11cc285b9940246b3a1b228beddd6e51a Mon Sep 17 00:00:00 2001 From: Kerry Gallagher <471693+Kerry350@users.noreply.github.com> Date: Mon, 8 Jul 2024 19:59:26 +0100 Subject: [PATCH 01/10] Utilise the central log sources setting within the Logs UI and related code --- x-pack/plugins/observability_solution/infra/tsconfig.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/x-pack/plugins/observability_solution/infra/tsconfig.json b/x-pack/plugins/observability_solution/infra/tsconfig.json index e0e6750550fbb..7adb62ed01f6b 100644 --- a/x-pack/plugins/observability_solution/infra/tsconfig.json +++ b/x-pack/plugins/observability_solution/infra/tsconfig.json @@ -110,7 +110,8 @@ "@kbn/core-analytics-browser", "@kbn/observability-alerting-rule-utils", "@kbn/core-application-browser", - "@kbn/shared-ux-page-no-data-types" + "@kbn/shared-ux-page-no-data-types", + "@kbn/core-application-browser" ], "exclude": ["target/**/*"] } From cc6abcf390c1cc4a0a7fd0d2fc17ff201955c3e2 Mon Sep 17 00:00:00 2001 From: Kerry Gallagher <471693+Kerry350@users.noreply.github.com> Date: Fri, 26 Jul 2024 12:04:52 +0100 Subject: [PATCH 02/10] Match the old defaults exactly --- .../observability_solution/logs_data_access/common/constants.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugins/observability_solution/logs_data_access/common/constants.ts b/x-pack/plugins/observability_solution/logs_data_access/common/constants.ts index c0caaa846f56e..fcac9c90aa6d5 100644 --- a/x-pack/plugins/observability_solution/logs_data_access/common/constants.ts +++ b/x-pack/plugins/observability_solution/logs_data_access/common/constants.ts @@ -5,4 +5,4 @@ * 2.0. */ -export const DEFAULT_LOG_SOURCES = ['logs-*-*,logs-*,filebeat-*,kibana_sample_data_logs*']; +export const DEFAULT_LOG_SOURCES = ['logs-*,filebeat-*,kibana_sample_data_logs*']; From 0692ac76116ba29296a6c93143d1990d3c40c6cc Mon Sep 17 00:00:00 2001 From: Kerry Gallagher <471693+Kerry350@users.noreply.github.com> Date: Fri, 26 Jul 2024 12:31:00 +0100 Subject: [PATCH 03/10] Revert "Match the old defaults exactly" This reverts commit b98490cda3da17c792fb6a42a85c6099ce96ab21. --- .../observability_solution/logs_data_access/common/constants.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugins/observability_solution/logs_data_access/common/constants.ts b/x-pack/plugins/observability_solution/logs_data_access/common/constants.ts index fcac9c90aa6d5..c0caaa846f56e 100644 --- a/x-pack/plugins/observability_solution/logs_data_access/common/constants.ts +++ b/x-pack/plugins/observability_solution/logs_data_access/common/constants.ts @@ -5,4 +5,4 @@ * 2.0. */ -export const DEFAULT_LOG_SOURCES = ['logs-*,filebeat-*,kibana_sample_data_logs*']; +export const DEFAULT_LOG_SOURCES = ['logs-*-*,logs-*,filebeat-*,kibana_sample_data_logs*']; From 479cafcbd265decf802d8744a4d8aaa8df548291 Mon Sep 17 00:00:00 2001 From: Kerry Gallagher <471693+Kerry350@users.noreply.github.com> Date: Wed, 31 Jul 2024 15:36:55 +0100 Subject: [PATCH 04/10] Amend tsconfig --- x-pack/plugins/observability_solution/infra/tsconfig.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/x-pack/plugins/observability_solution/infra/tsconfig.json b/x-pack/plugins/observability_solution/infra/tsconfig.json index 7adb62ed01f6b..4802bba8f0abf 100644 --- a/x-pack/plugins/observability_solution/infra/tsconfig.json +++ b/x-pack/plugins/observability_solution/infra/tsconfig.json @@ -109,8 +109,11 @@ "@kbn/logs-data-access-plugin", "@kbn/core-analytics-browser", "@kbn/observability-alerting-rule-utils", +<<<<<<< HEAD "@kbn/core-application-browser", "@kbn/shared-ux-page-no-data-types", +======= +>>>>>>> 72641dda8c7 (Amend tsconfig) "@kbn/core-application-browser" ], "exclude": ["target/**/*"] From 45274e02c26ae5f3b76593843849ad68aa5059fb Mon Sep 17 00:00:00 2001 From: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Date: Wed, 31 Jul 2024 14:21:49 +0000 Subject: [PATCH 05/10] [CI] Auto-commit changed files from 'node scripts/lint_ts_projects --fix' --- x-pack/plugins/observability_solution/infra/tsconfig.json | 3 --- 1 file changed, 3 deletions(-) diff --git a/x-pack/plugins/observability_solution/infra/tsconfig.json b/x-pack/plugins/observability_solution/infra/tsconfig.json index 4802bba8f0abf..7adb62ed01f6b 100644 --- a/x-pack/plugins/observability_solution/infra/tsconfig.json +++ b/x-pack/plugins/observability_solution/infra/tsconfig.json @@ -109,11 +109,8 @@ "@kbn/logs-data-access-plugin", "@kbn/core-analytics-browser", "@kbn/observability-alerting-rule-utils", -<<<<<<< HEAD "@kbn/core-application-browser", "@kbn/shared-ux-page-no-data-types", -======= ->>>>>>> 72641dda8c7 (Amend tsconfig) "@kbn/core-application-browser" ], "exclude": ["target/**/*"] From 114f3aaa0a32b39dfe2f7514b2593420aae75e43 Mon Sep 17 00:00:00 2001 From: Kerry Gallagher <471693+Kerry350@users.noreply.github.com> Date: Wed, 31 Jul 2024 14:33:47 +0100 Subject: [PATCH 06/10] Add a log sources setting migration to the upgrade assistant --- .../common/http_api/deprecations/index.ts | 9 +++ .../logs_shared/server/deprecations/index.ts | 22 ++++++ .../deprecations/log_sources_setting.ts | 67 +++++++++++++++++++ .../logs_shared/server/logs_shared_server.ts | 2 + .../logs_shared/server/plugin.ts | 3 + .../server/routes/deprecations/index.ts | 8 +++ .../deprecations/migrate_log_view_settings.ts | 54 +++++++++++++++ .../logs_shared/tsconfig.json | 2 + 8 files changed, 167 insertions(+) create mode 100644 x-pack/plugins/observability_solution/logs_shared/common/http_api/deprecations/index.ts create mode 100644 x-pack/plugins/observability_solution/logs_shared/server/deprecations/index.ts create mode 100644 x-pack/plugins/observability_solution/logs_shared/server/deprecations/log_sources_setting.ts create mode 100644 x-pack/plugins/observability_solution/logs_shared/server/routes/deprecations/index.ts create mode 100644 x-pack/plugins/observability_solution/logs_shared/server/routes/deprecations/migrate_log_view_settings.ts diff --git a/x-pack/plugins/observability_solution/logs_shared/common/http_api/deprecations/index.ts b/x-pack/plugins/observability_solution/logs_shared/common/http_api/deprecations/index.ts new file mode 100644 index 0000000000000..57f91cc799828 --- /dev/null +++ b/x-pack/plugins/observability_solution/logs_shared/common/http_api/deprecations/index.ts @@ -0,0 +1,9 @@ +/* + * 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. + */ + +export const MIGRATE_LOG_VIEW_SETTINGS_URL = + '/api/logs_shared/deprecations/migrate_log_view_settings'; diff --git a/x-pack/plugins/observability_solution/logs_shared/server/deprecations/index.ts b/x-pack/plugins/observability_solution/logs_shared/server/deprecations/index.ts new file mode 100644 index 0000000000000..3e80046644144 --- /dev/null +++ b/x-pack/plugins/observability_solution/logs_shared/server/deprecations/index.ts @@ -0,0 +1,22 @@ +/* + * 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 { LogsSharedPluginCoreSetup } from '../types'; +import { getLogSourcesSettingDeprecationInfo } from './log_sources_setting'; + +export const registerDeprecations = ({ core }: { core: LogsSharedPluginCoreSetup }) => { + core.deprecations.registerDeprecations({ + getDeprecations: async (context) => { + return [ + ...(await getLogSourcesSettingDeprecationInfo({ + context, + getStartServices: core.getStartServices, + })), + ]; + }, + }); +}; diff --git a/x-pack/plugins/observability_solution/logs_shared/server/deprecations/log_sources_setting.ts b/x-pack/plugins/observability_solution/logs_shared/server/deprecations/log_sources_setting.ts new file mode 100644 index 0000000000000..4e69a3b7f829e --- /dev/null +++ b/x-pack/plugins/observability_solution/logs_shared/server/deprecations/log_sources_setting.ts @@ -0,0 +1,67 @@ +/* + * 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 } from '@kbn/core-deprecations-server'; +import { i18n } from '@kbn/i18n'; +import { MIGRATE_LOG_VIEW_SETTINGS_URL } from '../../common/http_api/deprecations'; +import { logSourcesKibanaAdvancedSettingRT } from '../../common'; +import { LogsSharedPluginStartServicesAccessor } from '../types'; + +export const getLogSourcesSettingDeprecationInfo = async ({ + getStartServices, + context, +}: { + context: GetDeprecationsContext; + getStartServices: LogsSharedPluginStartServicesAccessor; +}): Promise => { + const [_, pluginStartDeps, pluginStart] = await getStartServices(); + const logSourcesService = + pluginStartDeps.logsDataAccess.services.logSourcesServiceFactory.getLogSourcesService( + context.savedObjectsClient + ); + const logViewsClient = pluginStart.logViews.getClient( + context.savedObjectsClient, + context.esClient.asCurrentUser, + logSourcesService + ); + + const logView = await logViewsClient.getLogView('default'); + + if (logView && !logSourcesKibanaAdvancedSettingRT.is(logView.attributes.logIndices)) { + return [ + { + title: i18n.translate('xpack.logsShared.deprecations.migrateLogSourcesSettingTitle', { + defaultMessage: 'Log sources setting', + }), + level: 'warning', + deprecationType: 'config', + configPath: '', + message: i18n.translate('xpack.logsShared.deprecations.migrateLogSourcesSettingMessage', { + defaultMessage: + 'Indices and Data view options previously provided via the Logs UI settings page are now deprecated. Please migrate to using the Kibana log sources advanced setting.', + }), + correctiveActions: { + manualSteps: [ + i18n.translate( + 'xpack.logsShared.deprecations.migrateLogSourcesSettingMessage.manualStepMessage', + { + defaultMessage: + 'Update the Log sources Kibana advanced setting (via Management > Advanced Settings) to match the setting previously provided via the Logs UI settings page. Then via the Logs UI settings page use the Kibana log sources advanced setting option.', + } + ), + ], + api: { + method: 'PUT', + path: MIGRATE_LOG_VIEW_SETTINGS_URL, + }, + }, + }, + ]; + } else { + return []; + } +}; diff --git a/x-pack/plugins/observability_solution/logs_shared/server/logs_shared_server.ts b/x-pack/plugins/observability_solution/logs_shared/server/logs_shared_server.ts index 60dc17be61d2d..9bb643c8dd617 100644 --- a/x-pack/plugins/observability_solution/logs_shared/server/logs_shared_server.ts +++ b/x-pack/plugins/observability_solution/logs_shared/server/logs_shared_server.ts @@ -12,10 +12,12 @@ import { initLogEntriesSummaryRoute, } from './routes/log_entries'; import { initLogViewRoutes } from './routes/log_views'; +import { initMigrateLogViewSettingsRoute } from './routes/deprecations'; export const initLogsSharedServer = (libs: LogsSharedBackendLibs) => { initLogEntriesHighlightsRoute(libs); initLogEntriesSummaryRoute(libs); initLogEntriesSummaryHighlightsRoute(libs); initLogViewRoutes(libs); + initMigrateLogViewSettingsRoute(libs); }; diff --git a/x-pack/plugins/observability_solution/logs_shared/server/plugin.ts b/x-pack/plugins/observability_solution/logs_shared/server/plugin.ts index 6bc9560764a7b..9e31bed9e029e 100644 --- a/x-pack/plugins/observability_solution/logs_shared/server/plugin.ts +++ b/x-pack/plugins/observability_solution/logs_shared/server/plugin.ts @@ -24,6 +24,7 @@ import { LogsSharedLogEntriesDomain } from './lib/domains/log_entries_domain'; import { LogsSharedKibanaLogEntriesAdapter } from './lib/adapters/log_entries/kibana_log_entries_adapter'; import { LogEntriesService } from './services/log_entries'; import { LogsSharedConfig } from '../common/plugin_config'; +import { registerDeprecations } from './deprecations'; export class LogsSharedPlugin implements @@ -84,6 +85,8 @@ export class LogsSharedPlugin const logEntriesService = new LogEntriesService(); logEntriesService.setup(core, plugins); + registerDeprecations({ core }); + return { ...domainLibs, logViews, diff --git a/x-pack/plugins/observability_solution/logs_shared/server/routes/deprecations/index.ts b/x-pack/plugins/observability_solution/logs_shared/server/routes/deprecations/index.ts new file mode 100644 index 0000000000000..2478fabf328c9 --- /dev/null +++ b/x-pack/plugins/observability_solution/logs_shared/server/routes/deprecations/index.ts @@ -0,0 +1,8 @@ +/* + * 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. + */ + +export * from './migrate_log_view_settings'; diff --git a/x-pack/plugins/observability_solution/logs_shared/server/routes/deprecations/migrate_log_view_settings.ts b/x-pack/plugins/observability_solution/logs_shared/server/routes/deprecations/migrate_log_view_settings.ts new file mode 100644 index 0000000000000..e94faf208a4ed --- /dev/null +++ b/x-pack/plugins/observability_solution/logs_shared/server/routes/deprecations/migrate_log_view_settings.ts @@ -0,0 +1,54 @@ +/* + * 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 { MIGRATE_LOG_VIEW_SETTINGS_URL } from '../../../common/http_api/deprecations'; +import { logSourcesKibanaAdvancedSettingRT } from '../../../common'; +import { LogsSharedBackendLibs } from '../../lib/logs_shared_types'; + +// This route facilitates automated one-click handling of updating log view's to use the +// Kibana advanced setting as part of the upgrade assistant. +// First, it will gather the indices currently set on the log view. +// Secondly, it will update the advanced setting to use these indices. +// Lastly, it will update the log view to use the kibana advanced setting. +export const initMigrateLogViewSettingsRoute = ({ + framework, + getStartServices, +}: LogsSharedBackendLibs) => { + framework.router.put( + { path: MIGRATE_LOG_VIEW_SETTINGS_URL, validate: false }, + async (context, request, response) => { + const [_, pluginStartDeps, pluginStart] = await getStartServices(); + + const logSourcesService = + await pluginStartDeps.logsDataAccess.services.logSourcesServiceFactory.getScopedLogSourcesService( + request + ); + const logViewsClient = pluginStart.logViews.getScopedClient(request); + + const logView = await logViewsClient.getLogView('default'); + + if (!logView || logSourcesKibanaAdvancedSettingRT.is(logView.attributes.logIndices)) { + throw new Error( + "Unable to migrate log view settings. A log view either doesn't exist or is already using the Kibana advanced setting." + ); + } + + const indices = ( + await logViewsClient.getResolvedLogView({ + type: 'log-view-reference', + logViewId: 'default', + }) + ).indices; + + await logSourcesService.setLogSources([{ indexPattern: indices }]); + await logViewsClient.putLogView('default', { + logIndices: { type: 'kibana_advanced_setting' }, + }); + return response.ok(); + } + ); +}; diff --git a/x-pack/plugins/observability_solution/logs_shared/tsconfig.json b/x-pack/plugins/observability_solution/logs_shared/tsconfig.json index f1bb2527f9311..38cbba7c252c0 100644 --- a/x-pack/plugins/observability_solution/logs_shared/tsconfig.json +++ b/x-pack/plugins/observability_solution/logs_shared/tsconfig.json @@ -42,5 +42,7 @@ "@kbn/test-jest-helpers", "@kbn/router-utils", "@kbn/logs-data-access-plugin", + "@kbn/core-deprecations-common", + "@kbn/core-deprecations-server", ] } From b1adcd2d575179145f5c07f060dbc2e7d865f2cd Mon Sep 17 00:00:00 2001 From: Kerry Gallagher <471693+Kerry350@users.noreply.github.com> Date: Wed, 7 Aug 2024 13:34:26 +0100 Subject: [PATCH 07/10] Add API tests --- .buildkite/ftr_oblt_stateful_configs.yml | 1 + .../deprecations/migrate_log_view_settings.ts | 54 ++++++----- .../apis/logs_shared/config.ts | 17 ++++ .../api_integration/apis/logs_shared/index.ts | 14 +++ .../logs_shared/migrate_log_view_settings.ts | 95 +++++++++++++++++++ x-pack/test/tsconfig.json | 3 +- 6 files changed, 160 insertions(+), 24 deletions(-) create mode 100644 x-pack/test/api_integration/apis/logs_shared/config.ts create mode 100644 x-pack/test/api_integration/apis/logs_shared/index.ts create mode 100644 x-pack/test/api_integration/apis/logs_shared/migrate_log_view_settings.ts diff --git a/.buildkite/ftr_oblt_stateful_configs.yml b/.buildkite/ftr_oblt_stateful_configs.yml index 55f3c1b603fca..eb8382eacce89 100644 --- a/.buildkite/ftr_oblt_stateful_configs.yml +++ b/.buildkite/ftr_oblt_stateful_configs.yml @@ -25,6 +25,7 @@ defaultQueue: 'n2-4-spot' enabled: - x-pack/test/alerting_api_integration/observability/config.ts - x-pack/test/api_integration/apis/logs_ui/config.ts + - x-pack/test/api_integration/apis/logs_shared/config.ts - x-pack/test/api_integration/apis/metrics_ui/config.ts - x-pack/test/api_integration/apis/osquery/config.ts - x-pack/test/api_integration/apis/synthetics/config.ts diff --git a/x-pack/plugins/observability_solution/logs_shared/server/routes/deprecations/migrate_log_view_settings.ts b/x-pack/plugins/observability_solution/logs_shared/server/routes/deprecations/migrate_log_view_settings.ts index e94faf208a4ed..08152eb850e51 100644 --- a/x-pack/plugins/observability_solution/logs_shared/server/routes/deprecations/migrate_log_view_settings.ts +++ b/x-pack/plugins/observability_solution/logs_shared/server/routes/deprecations/migrate_log_view_settings.ts @@ -5,6 +5,7 @@ * 2.0. */ +import { defaultLogViewId } from '../../../common/log_views'; import { MIGRATE_LOG_VIEW_SETTINGS_URL } from '../../../common/http_api/deprecations'; import { logSourcesKibanaAdvancedSettingRT } from '../../../common'; import { LogsSharedBackendLibs } from '../../lib/logs_shared_types'; @@ -21,34 +22,41 @@ export const initMigrateLogViewSettingsRoute = ({ framework.router.put( { path: MIGRATE_LOG_VIEW_SETTINGS_URL, validate: false }, async (context, request, response) => { - const [_, pluginStartDeps, pluginStart] = await getStartServices(); + try { + const [_, pluginStartDeps, pluginStart] = await getStartServices(); - const logSourcesService = - await pluginStartDeps.logsDataAccess.services.logSourcesServiceFactory.getScopedLogSourcesService( - request - ); - const logViewsClient = pluginStart.logViews.getScopedClient(request); + const logSourcesService = + await pluginStartDeps.logsDataAccess.services.logSourcesServiceFactory.getScopedLogSourcesService( + request + ); + const logViewsClient = pluginStart.logViews.getScopedClient(request); - const logView = await logViewsClient.getLogView('default'); + const logView = await logViewsClient.getLogView('default'); - if (!logView || logSourcesKibanaAdvancedSettingRT.is(logView.attributes.logIndices)) { - throw new Error( - "Unable to migrate log view settings. A log view either doesn't exist or is already using the Kibana advanced setting." - ); - } + if (!logView || logSourcesKibanaAdvancedSettingRT.is(logView.attributes.logIndices)) { + return response.customError({ + body: new Error( + "Unable to migrate log view settings. A log view either doesn't exist or is already using the Kibana advanced setting." + ), + statusCode: 400, + }); + } - const indices = ( - await logViewsClient.getResolvedLogView({ - type: 'log-view-reference', - logViewId: 'default', - }) - ).indices; + const indices = ( + await logViewsClient.getResolvedLogView({ + type: 'log-view-reference', + logViewId: defaultLogViewId, + }) + ).indices; - await logSourcesService.setLogSources([{ indexPattern: indices }]); - await logViewsClient.putLogView('default', { - logIndices: { type: 'kibana_advanced_setting' }, - }); - return response.ok(); + await logSourcesService.setLogSources([{ indexPattern: indices }]); + await logViewsClient.putLogView(defaultLogViewId, { + logIndices: { type: 'kibana_advanced_setting' }, + }); + return response.ok(); + } catch (error) { + throw error; + } } ); }; diff --git a/x-pack/test/api_integration/apis/logs_shared/config.ts b/x-pack/test/api_integration/apis/logs_shared/config.ts new file mode 100644 index 0000000000000..5f335f116fefe --- /dev/null +++ b/x-pack/test/api_integration/apis/logs_shared/config.ts @@ -0,0 +1,17 @@ +/* + * 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 { FtrConfigProviderContext } from '@kbn/test'; + +export default async function ({ readConfigFile }: FtrConfigProviderContext) { + const baseIntegrationTestsConfig = await readConfigFile(require.resolve('../../config.ts')); + + return { + ...baseIntegrationTestsConfig.getAll(), + testFiles: [require.resolve('.')], + }; +} diff --git a/x-pack/test/api_integration/apis/logs_shared/index.ts b/x-pack/test/api_integration/apis/logs_shared/index.ts new file mode 100644 index 0000000000000..157526c418754 --- /dev/null +++ b/x-pack/test/api_integration/apis/logs_shared/index.ts @@ -0,0 +1,14 @@ +/* + * 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 { FtrProviderContext } from '../../ftr_provider_context'; + +export default function ({ loadTestFile }: FtrProviderContext) { + describe('Logs shared routes', () => { + loadTestFile(require.resolve('./migrate_log_view_settings')); + }); +} diff --git a/x-pack/test/api_integration/apis/logs_shared/migrate_log_view_settings.ts b/x-pack/test/api_integration/apis/logs_shared/migrate_log_view_settings.ts new file mode 100644 index 0000000000000..e3185fc82dacf --- /dev/null +++ b/x-pack/test/api_integration/apis/logs_shared/migrate_log_view_settings.ts @@ -0,0 +1,95 @@ +/* + * 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 expect from '@kbn/expect'; +import { LogViewAttributes } from '@kbn/logs-shared-plugin/common/log_views'; +import { infraSourceConfigurationSavedObjectName } from '@kbn/infra-plugin/server/lib/sources'; +import { logViewSavedObjectName } from '@kbn/logs-shared-plugin/server'; +import { defaultLogViewId } from '@kbn/logs-shared-plugin/common/log_views'; +import { MIGRATE_LOG_VIEW_SETTINGS_URL } from '@kbn/logs-shared-plugin/common/http_api/deprecations'; +import { OBSERVABILITY_LOGS_DATA_ACCESS_LOG_SOURCES_ID } from '@kbn/management-settings-ids'; +import { FtrProviderContext } from '../../ftr_provider_context'; + +export default function ({ getService }: FtrProviderContext) { + const supertest = getService('supertest'); + const logViewsService = getService('infraLogViews'); + const kibanaServer = getService('kibanaServer'); + const retry = getService('retry'); + + const INDICES = 'logs-*,something-else-*,test-*'; + + describe('Log view settings migration', () => { + describe('Migration API', () => { + before(async () => { + await kibanaServer.savedObjects.clean({ + types: [infraSourceConfigurationSavedObjectName, logViewSavedObjectName], + }); + }); + + afterEach(async () => { + await kibanaServer.savedObjects.clean({ + types: [infraSourceConfigurationSavedObjectName, logViewSavedObjectName], + }); + }); + + it('performs a migration when the log view is not using the Kibana advanced setting', async () => { + const logViewAttributes: Partial = { + name: 'Test Log View 1', + description: 'Test Description 1', + logIndices: { type: 'index_name', indexName: INDICES }, + logColumns: [], + }; + + await logViewsService.putLogView(defaultLogViewId, { + attributes: logViewAttributes, + }); + + await supertest + .put(MIGRATE_LOG_VIEW_SETTINGS_URL) + .set({ + 'kbn-xsrf': 'some-xsrf-token', + }) + .send() + .expect(200); + + await retry.try(async () => { + const migratedLogView = await logViewsService.getLogView(defaultLogViewId); + expect(migratedLogView.data.attributes.logIndices.type).to.eql('kibana_advanced_setting'); + const uiSetting = await kibanaServer.uiSettings.get( + OBSERVABILITY_LOGS_DATA_ACCESS_LOG_SOURCES_ID + ); + expect(uiSetting).to.eql([INDICES]); + }); + }); + + it('should error when the log view is already using the Kibana advanced setting', async () => { + const logViewAttributes: Partial = { + name: 'Test Log View 1', + description: 'Test Description 1', + logIndices: { type: 'kibana_advanced_setting' }, + logColumns: [], + }; + + await logViewsService.putLogView(defaultLogViewId, { + attributes: logViewAttributes, + }); + + const response = await supertest + .put(MIGRATE_LOG_VIEW_SETTINGS_URL) + .set({ + 'kbn-xsrf': 'some-xsrf-token', + }) + .send() + .expect(400); + + expect(response.body.message).to.eql( + "Unable to migrate log view settings. A log view either doesn't exist or is already using the Kibana advanced setting." + ); + }); + }); + }); +} diff --git a/x-pack/test/tsconfig.json b/x-pack/test/tsconfig.json index 3449df8d6f23c..fe82748f6e6ae 100644 --- a/x-pack/test/tsconfig.json +++ b/x-pack/test/tsconfig.json @@ -176,6 +176,7 @@ "@kbn/osquery-plugin", "@kbn/entities-schema", "@kbn/actions-simulators-plugin", - "@kbn/cases-api-integration-test-plugin" + "@kbn/cases-api-integration-test-plugin", + "@kbn/management-settings-ids" ] } From 6530c50082b748075403aaab0d3d53c0dcd7fa46 Mon Sep 17 00:00:00 2001 From: Kerry Gallagher <471693+Kerry350@users.noreply.github.com> Date: Wed, 7 Aug 2024 13:40:10 +0100 Subject: [PATCH 08/10] Use constant --- .../logs_shared/server/deprecations/log_sources_setting.ts | 3 ++- .../observability_solution/logs_shared/server/plugin.ts | 3 ++- .../server/routes/deprecations/migrate_log_view_settings.ts | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/x-pack/plugins/observability_solution/logs_shared/server/deprecations/log_sources_setting.ts b/x-pack/plugins/observability_solution/logs_shared/server/deprecations/log_sources_setting.ts index 4e69a3b7f829e..836637e0bcbf2 100644 --- a/x-pack/plugins/observability_solution/logs_shared/server/deprecations/log_sources_setting.ts +++ b/x-pack/plugins/observability_solution/logs_shared/server/deprecations/log_sources_setting.ts @@ -7,6 +7,7 @@ import { DeprecationsDetails } from '@kbn/core-deprecations-common'; import { GetDeprecationsContext } from '@kbn/core-deprecations-server'; import { i18n } from '@kbn/i18n'; +import { defaultLogViewId } from '../../common/log_views'; import { MIGRATE_LOG_VIEW_SETTINGS_URL } from '../../common/http_api/deprecations'; import { logSourcesKibanaAdvancedSettingRT } from '../../common'; import { LogsSharedPluginStartServicesAccessor } from '../types'; @@ -29,7 +30,7 @@ export const getLogSourcesSettingDeprecationInfo = async ({ logSourcesService ); - const logView = await logViewsClient.getLogView('default'); + const logView = await logViewsClient.getLogView(defaultLogViewId); if (logView && !logSourcesKibanaAdvancedSettingRT.is(logView.attributes.logIndices)) { return [ diff --git a/x-pack/plugins/observability_solution/logs_shared/server/plugin.ts b/x-pack/plugins/observability_solution/logs_shared/server/plugin.ts index 9e31bed9e029e..7c97e175ed64f 100644 --- a/x-pack/plugins/observability_solution/logs_shared/server/plugin.ts +++ b/x-pack/plugins/observability_solution/logs_shared/server/plugin.ts @@ -25,6 +25,7 @@ import { LogsSharedKibanaLogEntriesAdapter } from './lib/adapters/log_entries/ki import { LogEntriesService } from './services/log_entries'; import { LogsSharedConfig } from '../common/plugin_config'; import { registerDeprecations } from './deprecations'; +import { defaultLogViewId } from '../common/log_views'; export class LogsSharedPlugin implements @@ -59,7 +60,7 @@ export class LogsSharedPlugin core.savedObjects.registerType(logViewSavedObjectType); } else { // Register a static internal view to use as a fallback when the log view SO is not registered - logViews.defineInternalLogView('default', {}); + logViews.defineInternalLogView(defaultLogViewId, {}); } const domainLibs: LogsSharedDomainLibs = { diff --git a/x-pack/plugins/observability_solution/logs_shared/server/routes/deprecations/migrate_log_view_settings.ts b/x-pack/plugins/observability_solution/logs_shared/server/routes/deprecations/migrate_log_view_settings.ts index 08152eb850e51..f3e9db4f1a765 100644 --- a/x-pack/plugins/observability_solution/logs_shared/server/routes/deprecations/migrate_log_view_settings.ts +++ b/x-pack/plugins/observability_solution/logs_shared/server/routes/deprecations/migrate_log_view_settings.ts @@ -31,7 +31,7 @@ export const initMigrateLogViewSettingsRoute = ({ ); const logViewsClient = pluginStart.logViews.getScopedClient(request); - const logView = await logViewsClient.getLogView('default'); + const logView = await logViewsClient.getLogView(defaultLogViewId); if (!logView || logSourcesKibanaAdvancedSettingRT.is(logView.attributes.logIndices)) { return response.customError({ From 357701a0307c864bf24ca3b44e8bc68597357cdd Mon Sep 17 00:00:00 2001 From: Kerry Gallagher <471693+Kerry350@users.noreply.github.com> Date: Wed, 7 Aug 2024 16:07:15 +0100 Subject: [PATCH 09/10] Remove duplicate entry from rebase --- x-pack/plugins/observability_solution/infra/tsconfig.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/x-pack/plugins/observability_solution/infra/tsconfig.json b/x-pack/plugins/observability_solution/infra/tsconfig.json index 7adb62ed01f6b..e0e6750550fbb 100644 --- a/x-pack/plugins/observability_solution/infra/tsconfig.json +++ b/x-pack/plugins/observability_solution/infra/tsconfig.json @@ -110,8 +110,7 @@ "@kbn/core-analytics-browser", "@kbn/observability-alerting-rule-utils", "@kbn/core-application-browser", - "@kbn/shared-ux-page-no-data-types", - "@kbn/core-application-browser" + "@kbn/shared-ux-page-no-data-types" ], "exclude": ["target/**/*"] } From dc8443729b335dbfb1acb79fa49b66854911cadf Mon Sep 17 00:00:00 2001 From: Kerry Gallagher <471693+Kerry350@users.noreply.github.com> Date: Tue, 13 Aug 2024 11:11:18 +0100 Subject: [PATCH 10/10] PR feedback --- .../deprecations/log_sources_setting.ts | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/x-pack/plugins/observability_solution/logs_shared/server/deprecations/log_sources_setting.ts b/x-pack/plugins/observability_solution/logs_shared/server/deprecations/log_sources_setting.ts index 836637e0bcbf2..c3e891edf74c9 100644 --- a/x-pack/plugins/observability_solution/logs_shared/server/deprecations/log_sources_setting.ts +++ b/x-pack/plugins/observability_solution/logs_shared/server/deprecations/log_sources_setting.ts @@ -35,20 +35,25 @@ export const getLogSourcesSettingDeprecationInfo = async ({ if (logView && !logSourcesKibanaAdvancedSettingRT.is(logView.attributes.logIndices)) { return [ { - title: i18n.translate('xpack.logsShared.deprecations.migrateLogSourcesSettingTitle', { - defaultMessage: 'Log sources setting', - }), + title: i18n.translate( + 'xpack.logsShared.deprecations.migrateLogViewSettingsToLogSourcesSetting.title', + { + defaultMessage: 'Log sources setting', + } + ), level: 'warning', - deprecationType: 'config', - configPath: '', - message: i18n.translate('xpack.logsShared.deprecations.migrateLogSourcesSettingMessage', { - defaultMessage: - 'Indices and Data view options previously provided via the Logs UI settings page are now deprecated. Please migrate to using the Kibana log sources advanced setting.', - }), + deprecationType: 'feature', + message: i18n.translate( + 'xpack.logsShared.deprecations.migrateLogViewSettingsToLogSourcesSetting.message', + { + defaultMessage: + 'Indices and Data view options previously provided via the Logs UI settings page are now deprecated. Please migrate to using the Kibana log sources advanced setting.', + } + ), correctiveActions: { manualSteps: [ i18n.translate( - 'xpack.logsShared.deprecations.migrateLogSourcesSettingMessage.manualStepMessage', + 'xpack.logsShared.deprecations.migrateLogViewSettingsToLogSourcesSetting.message.manualStepMessage', { defaultMessage: 'Update the Log sources Kibana advanced setting (via Management > Advanced Settings) to match the setting previously provided via the Logs UI settings page. Then via the Logs UI settings page use the Kibana log sources advanced setting option.',