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", ] }