-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a log sources setting migration to the upgrade assistant
- Loading branch information
Showing
8 changed files
with
167 additions
and
0 deletions.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
x-pack/plugins/observability_solution/logs_shared/common/http_api/deprecations/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'; |
22 changes: 22 additions & 0 deletions
22
x-pack/plugins/observability_solution/logs_shared/server/deprecations/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
})), | ||
]; | ||
}, | ||
}); | ||
}; |
67 changes: 67 additions & 0 deletions
67
x-pack/plugins/observability_solution/logs_shared/server/deprecations/log_sources_setting.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<DeprecationsDetails[]> => { | ||
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 []; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
x-pack/plugins/observability_solution/logs_shared/server/routes/deprecations/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'; |
54 changes: 54 additions & 0 deletions
54
...bservability_solution/logs_shared/server/routes/deprecations/migrate_log_view_settings.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters