|
| 1 | +/* |
| 2 | + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one |
| 3 | + * or more contributor license agreements. Licensed under the "Elastic License |
| 4 | + * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side |
| 5 | + * Public License v 1"; you may not use this file except in compliance with, at |
| 6 | + * your election, the "Elastic License 2.0", the "GNU Affero General Public |
| 7 | + * License v3.0 only", or the "Server Side Public License, v 1". |
| 8 | + */ |
| 9 | + |
| 10 | +import type { |
| 11 | + CoreSetup, |
| 12 | + DeprecationsDetails, |
| 13 | + GetDeprecationsContext, |
| 14 | + RegisterDeprecationsConfig, |
| 15 | + SavedObjectsFindResult, |
| 16 | +} from '@kbn/core/server'; |
| 17 | +import { i18n } from '@kbn/i18n'; |
| 18 | +import type { DeprecationDetailsMessage } from '@kbn/core-deprecations-common'; |
| 19 | +import { SEARCH_SESSION_TYPE, SearchSessionSavedObjectAttributes } from '../../common'; |
| 20 | + |
| 21 | +type SearchSessionAttributes = Pick< |
| 22 | + SearchSessionSavedObjectAttributes, |
| 23 | + 'name' | 'username' | 'expires' |
| 24 | +>; |
| 25 | + |
| 26 | +export const createSearchSessionsDeprecationsConfig: ( |
| 27 | + core: CoreSetup |
| 28 | +) => RegisterDeprecationsConfig = (core: CoreSetup) => ({ |
| 29 | + getDeprecations: async (context: GetDeprecationsContext): Promise<DeprecationsDetails[]> => { |
| 30 | + const searchSessionsLink = core.http.basePath.prepend('/app/management/kibana/search_sessions'); |
| 31 | + const [coreStart] = await core.getStartServices(); |
| 32 | + const savedObjectsClient = coreStart.savedObjects.getScopedClient(context.request, { |
| 33 | + includedHiddenTypes: [SEARCH_SESSION_TYPE], |
| 34 | + }); |
| 35 | + const results = await savedObjectsClient.find<SearchSessionAttributes>({ |
| 36 | + type: 'search-session', |
| 37 | + perPage: 1000, |
| 38 | + fields: ['name', 'username', 'expires'], |
| 39 | + sortField: 'created', |
| 40 | + sortOrder: 'desc', |
| 41 | + namespaces: ['*'], |
| 42 | + }); |
| 43 | + |
| 44 | + const searchSessions: Array<SavedObjectsFindResult<SearchSessionAttributes>> = |
| 45 | + results.saved_objects.filter((so) => new Date(so.attributes.expires).getTime() > Date.now()); |
| 46 | + |
| 47 | + if (!searchSessions.length) { |
| 48 | + return []; |
| 49 | + } |
| 50 | + |
| 51 | + return [ |
| 52 | + { |
| 53 | + title: i18n.translate('data.deprecations.searchSessionsTitle', { |
| 54 | + defaultMessage: 'Search sessions will be disabled by default', |
| 55 | + }), |
| 56 | + message: buildMessage({ searchSessions, searchSessionsLink }), |
| 57 | + deprecationType: 'feature', |
| 58 | + level: 'warning', |
| 59 | + correctiveActions: { |
| 60 | + manualSteps: [ |
| 61 | + i18n.translate('data.deprecations.searchSessions.manualStepOneMessage', { |
| 62 | + defaultMessage: 'Navigate to Stack Management > Kibana > Search Sessions', |
| 63 | + }), |
| 64 | + i18n.translate('data.deprecations.searchSessions.manualStepTwoMessage', { |
| 65 | + defaultMessage: 'Delete search sessions that have not expired', |
| 66 | + }), |
| 67 | + i18n.translate('data.deprecations.searchSessions.manualStepTwoMessage', { |
| 68 | + defaultMessage: |
| 69 | + 'Alternatively, to continue using search sessions until 9.1, open the kibana.yml config file and add the following: "data.search.sessions.enabled: true"', |
| 70 | + }), |
| 71 | + ], |
| 72 | + }, |
| 73 | + }, |
| 74 | + ]; |
| 75 | + }, |
| 76 | +}); |
| 77 | + |
| 78 | +const buildMessage = ({ |
| 79 | + searchSessions, |
| 80 | + searchSessionsLink, |
| 81 | +}: { |
| 82 | + searchSessions: Array<SavedObjectsFindResult<SearchSessionAttributes>>; |
| 83 | + searchSessionsLink: string; |
| 84 | +}): DeprecationDetailsMessage => ({ |
| 85 | + type: 'markdown', |
| 86 | + content: i18n.translate('data.deprecations.scriptedFieldsMessage', { |
| 87 | + defaultMessage: `The search sessions feature is deprecated and is disabled by default in 9.0. You currently have {numberOfSearchSessions} active search session(s): [Manage Search Sessions]({searchSessionsLink})`, |
| 88 | + values: { |
| 89 | + numberOfSearchSessions: searchSessions.length, |
| 90 | + searchSessionsLink, |
| 91 | + }, |
| 92 | + }), |
| 93 | +}); |
0 commit comments