-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Deprecations] Logs Sources settings in all spaces #203042
Changes from 5 commits
0f800e6
4721ac5
08c00be
61489d8
08bf159
79969b2
8e2dde0
2ca3ce9
cac8be0
acf77fd
88ce365
6dae433
032f3b8
b2bf260
cb0176b
dc649a8
cf9687e
1e5777d
212ea7d
d759cbd
024bb68
11716b9
b0ad7c1
7776e31
339a047
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -427,4 +427,16 @@ export interface SavedObjectsClientContract { | |||||
* Returns the namespace associated with the client. If the namespace is the default one, this method returns `undefined`. | ||||||
*/ | ||||||
getCurrentNamespace(): string | undefined; | ||||||
|
||||||
/** | ||||||
* Given a list of namespace strings, returns a subset that the user is authorized to search in. | ||||||
* If a wildcard '*' is used, it is expanded to an explicit list of namespace strings. | ||||||
*/ | ||||||
getSearchableNamespaces: (namespaces: string[] | undefined) => Promise<string[]>; | ||||||
|
||||||
/** | ||||||
* Returns a new Saved Objects client scoped to the new namespace. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
We're not creating a namespace, only a client that is scoped to one |
||||||
* @param namespace Space to switch to. | ||||||
afharo marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
*/ | ||||||
asScopedToNamespace(namespace: string): SavedObjectsClientContract; | ||||||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -552,4 +552,16 @@ export interface ISavedObjectsRepository { | |||||
* namespace. | ||||||
*/ | ||||||
getCurrentNamespace(namespace?: string): string | undefined; | ||||||
|
||||||
/** | ||||||
* Given a list of namespace strings, returns a subset that the user is authorized to search in. | ||||||
* If a wildcard '*' is used, it is expanded to an explicit list of namespace strings. | ||||||
*/ | ||||||
getSearchableNamespaces: (namespaces: string[] | undefined) => Promise<string[]>; | ||||||
|
||||||
/** | ||||||
* Returns a new Saved Objects repository scoped to the new namespace. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
* @param namespace Space to switch to. | ||||||
*/ | ||||||
asScopedToNamespace(namespace: string): ISavedObjectsRepository; | ||||||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -25,4 +25,9 @@ export interface ISavedObjectsSpacesExtension { | |||||
* If a wildcard '*' is used, it is expanded to an explicit list of namespace strings. | ||||||
*/ | ||||||
getSearchableNamespaces: (namespaces: string[] | undefined) => Promise<string[]>; | ||||||
/** | ||||||
* Returns a new Saved Objects Spaces Extension scoped to the new namespace. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
* @param namespace Space to switch to. | ||||||
*/ | ||||||
asScopedToNamespace(namespace: string): ISavedObjectsSpacesExtension; | ||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,67 +7,94 @@ | |
import { DeprecationsDetails } from '@kbn/core-deprecations-common'; | ||
import { GetDeprecationsContext } from '@kbn/core-deprecations-server'; | ||
import { i18n } from '@kbn/i18n'; | ||
import pMap from 'p-map'; | ||
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'; | ||
|
||
export const getLogSourcesSettingDeprecationInfo = async ({ | ||
getStartServices, | ||
context, | ||
}: { | ||
export interface LogSourcesSettingDeprecationParams { | ||
context: GetDeprecationsContext; | ||
getStartServices: LogsSharedPluginStartServicesAccessor; | ||
}): Promise<DeprecationsDetails[]> => { | ||
const [_, pluginStartDeps, pluginStart] = await getStartServices(); | ||
const logSourcesService = | ||
pluginStartDeps.logsDataAccess.services.logSourcesServiceFactory.getLogSourcesService( | ||
context.savedObjectsClient | ||
} | ||
|
||
export const getLogSourcesSettingDeprecationInfo = async ( | ||
params: LogSourcesSettingDeprecationParams | ||
): Promise<DeprecationsDetails[]> => { | ||
const allAvailableSpaces = await params.context.savedObjectsClient.getSearchableNamespaces(['*']); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Requires end users to actively enable Log sources in each space. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, I don't fully understand this comment. We're reading a SO, and it's perfectly fine if the SO doesn't exist. Why would we need Log sources to be enabled in each space for this logic to work? |
||
|
||
const deprecationPerSpaceFactory = getLogSourcesSettingDeprecationInfoForSpaceFactory(params); | ||
|
||
const deprecations = await pMap(allAvailableSpaces, deprecationPerSpaceFactory, { | ||
concurrency: 20, // limit the number of spaces handled concurrently to make sure that we cover large deployments | ||
}); | ||
|
||
// unnest results | ||
return ([] as DeprecationsDetails[]).concat(...deprecations); | ||
}; | ||
|
||
export const getLogSourcesSettingDeprecationInfoForSpaceFactory = ({ | ||
getStartServices, | ||
context, | ||
}: LogSourcesSettingDeprecationParams): ((spaceId: string) => Promise<DeprecationsDetails[]>) => { | ||
return async (spaceId) => { | ||
const [_, pluginStartDeps, pluginStart] = await getStartServices(); | ||
|
||
// Get a new Saved Object Client scoped to the spaceId | ||
const spaceScopedSavedObjectsClient = context.savedObjectsClient.asScopedToNamespace(spaceId); | ||
|
||
const logSourcesService = | ||
pluginStartDeps.logsDataAccess.services.logSourcesServiceFactory.getLogSourcesService( | ||
spaceScopedSavedObjectsClient | ||
); | ||
const logViewsClient = pluginStart.logViews.getClient( | ||
spaceScopedSavedObjectsClient, | ||
context.esClient.asCurrentUser, | ||
logSourcesService | ||
); | ||
const logViewsClient = pluginStart.logViews.getClient( | ||
context.savedObjectsClient, | ||
context.esClient.asCurrentUser, | ||
logSourcesService | ||
); | ||
|
||
const logView = await logViewsClient.getLogView(defaultLogViewId); | ||
const logView = await logViewsClient.getLogView(defaultLogViewId); | ||
|
||
if (logView && !logSourcesKibanaAdvancedSettingRT.is(logView.attributes.logIndices)) { | ||
return [ | ||
{ | ||
title: i18n.translate( | ||
'xpack.logsShared.deprecations.migrateLogViewSettingsToLogSourcesSetting.title', | ||
{ | ||
defaultMessage: 'Log sources setting', | ||
} | ||
), | ||
level: 'warning', | ||
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.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.', | ||
} | ||
), | ||
], | ||
api: { | ||
method: 'PUT', | ||
path: MIGRATE_LOG_VIEW_SETTINGS_URL, | ||
if (logView && !logSourcesKibanaAdvancedSettingRT.is(logView.attributes.logIndices)) { | ||
return [ | ||
{ | ||
title: i18n.translate( | ||
'xpack.logsShared.deprecations.migrateLogViewSettingsToLogSourcesSetting.title', | ||
{ | ||
defaultMessage: 'Log sources setting in the space "{spaceId}"', | ||
values: { spaceId }, | ||
} | ||
), | ||
level: 'warning', | ||
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 in the space "{spaceId}".', | ||
values: { spaceId }, | ||
} | ||
), | ||
correctiveActions: { | ||
manualSteps: [ | ||
i18n.translate( | ||
'xpack.logsShared.deprecations.migrateLogViewSettingsToLogSourcesSetting.message.manualStepMessage', | ||
{ | ||
defaultMessage: | ||
'While in the space "{spaceId}" 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.', | ||
values: { spaceId }, | ||
} | ||
), | ||
], | ||
api: { | ||
method: 'PUT', | ||
path: MIGRATE_LOG_VIEW_SETTINGS_URL, | ||
}, | ||
}, | ||
}, | ||
}, | ||
]; | ||
} else { | ||
return []; | ||
} | ||
]; | ||
} else { | ||
return []; | ||
} | ||
}; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to make it super clear that the explicit list of namespace strings only includes the namespaces the current user has access to othewise consumers might incorrectly interpret that as a list of all namespaces.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And it's worth noting that this will include any namespace the user has ANY access to.