diff --git a/packages/kbn-analytics/tsconfig.json b/packages/kbn-analytics/tsconfig.json index 80a2255d71805..c2e579e7fdbea 100644 --- a/packages/kbn-analytics/tsconfig.json +++ b/packages/kbn-analytics/tsconfig.json @@ -7,7 +7,6 @@ "emitDeclarationOnly": true, "declaration": true, "declarationMap": true, - "isolatedModules": true, "sourceMap": true, "sourceRoot": "../../../../../packages/kbn-analytics/src", "types": [ diff --git a/packages/kbn-telemetry-tools/src/tools/tasks/index.ts b/packages/kbn-telemetry-tools/src/tools/tasks/index.ts index f55a9aa80d40d..5d946b73d9759 100644 --- a/packages/kbn-telemetry-tools/src/tools/tasks/index.ts +++ b/packages/kbn-telemetry-tools/src/tools/tasks/index.ts @@ -7,9 +7,7 @@ */ export { ErrorReporter } from './error_reporter'; - -export type { TaskContext } from './task_context'; -export { createTaskContext } from './task_context'; +export { TaskContext, createTaskContext } from './task_context'; export { parseConfigsTask } from './parse_configs_task'; export { extractCollectorsTask } from './extract_collectors_task'; diff --git a/packages/kbn-telemetry-tools/tsconfig.json b/packages/kbn-telemetry-tools/tsconfig.json index 419af1d02f83b..39946fe9907e5 100644 --- a/packages/kbn-telemetry-tools/tsconfig.json +++ b/packages/kbn-telemetry-tools/tsconfig.json @@ -6,8 +6,7 @@ "declaration": true, "declarationMap": true, "sourceMap": true, - "sourceRoot": "../../../../packages/kbn-telemetry-tools/src", - "isolatedModules": true + "sourceRoot": "../../../../packages/kbn-telemetry-tools/src" }, "include": [ "src/**/*", diff --git a/src/plugins/kibana_usage_collection/tsconfig.json b/src/plugins/kibana_usage_collection/tsconfig.json index ee07dfe589e4a..d664d936f6667 100644 --- a/src/plugins/kibana_usage_collection/tsconfig.json +++ b/src/plugins/kibana_usage_collection/tsconfig.json @@ -5,8 +5,7 @@ "outDir": "./target/types", "emitDeclarationOnly": true, "declaration": true, - "declarationMap": true, - "isolatedModules": true + "declarationMap": true }, "include": [ "common/*", diff --git a/src/plugins/telemetry/common/telemetry_config/index.ts b/src/plugins/telemetry/common/telemetry_config/index.ts index cc4ff102742d7..84b6486f35b24 100644 --- a/src/plugins/telemetry/common/telemetry_config/index.ts +++ b/src/plugins/telemetry/common/telemetry_config/index.ts @@ -9,5 +9,7 @@ export { getTelemetryOptIn } from './get_telemetry_opt_in'; export { getTelemetrySendUsageFrom } from './get_telemetry_send_usage_from'; export { getTelemetryAllowChangingOptInStatus } from './get_telemetry_allow_changing_opt_in_status'; -export { getTelemetryFailureDetails } from './get_telemetry_failure_details'; -export type { TelemetryFailureDetails } from './get_telemetry_failure_details'; +export { + getTelemetryFailureDetails, + TelemetryFailureDetails, +} from './get_telemetry_failure_details'; diff --git a/src/plugins/telemetry/public/index.ts b/src/plugins/telemetry/public/index.ts index 47ba7828eaec2..6cca9bdf881dd 100644 --- a/src/plugins/telemetry/public/index.ts +++ b/src/plugins/telemetry/public/index.ts @@ -8,7 +8,7 @@ import { PluginInitializerContext } from 'kibana/public'; import { TelemetryPlugin, TelemetryPluginConfig } from './plugin'; -export type { TelemetryPluginStart, TelemetryPluginSetup } from './plugin'; +export { TelemetryPluginStart, TelemetryPluginSetup } from './plugin'; export function plugin(initializerContext: PluginInitializerContext) { return new TelemetryPlugin(initializerContext); diff --git a/src/plugins/telemetry/server/index.ts b/src/plugins/telemetry/server/index.ts index 1c335426ffd03..debdf7515cd58 100644 --- a/src/plugins/telemetry/server/index.ts +++ b/src/plugins/telemetry/server/index.ts @@ -13,7 +13,7 @@ import { configSchema, TelemetryConfigType } from './config'; export { FetcherTask } from './fetcher'; export { handleOldSettings } from './handle_old_settings'; -export type { TelemetryPluginSetup, TelemetryPluginStart } from './plugin'; +export { TelemetryPluginSetup, TelemetryPluginStart } from './plugin'; export const config: PluginConfigDescriptor = { schema: configSchema, @@ -34,12 +34,9 @@ export { constants }; export { getClusterUuids, getLocalStats, - DATA_TELEMETRY_ID, - buildDataTelemetryPayload, -} from './telemetry_collection'; - -export type { TelemetryLocalStats, + DATA_TELEMETRY_ID, DataTelemetryIndex, DataTelemetryPayload, + buildDataTelemetryPayload, } from './telemetry_collection'; diff --git a/src/plugins/telemetry/server/telemetry_collection/get_data_telemetry/index.ts b/src/plugins/telemetry/server/telemetry_collection/get_data_telemetry/index.ts index c93b7e872924b..def1131dfb1a3 100644 --- a/src/plugins/telemetry/server/telemetry_collection/get_data_telemetry/index.ts +++ b/src/plugins/telemetry/server/telemetry_collection/get_data_telemetry/index.ts @@ -7,5 +7,10 @@ */ export { DATA_TELEMETRY_ID } from './constants'; -export { getDataTelemetry, buildDataTelemetryPayload } from './get_data_telemetry'; -export type { DataTelemetryPayload, DataTelemetryIndex } from './get_data_telemetry'; + +export { + getDataTelemetry, + buildDataTelemetryPayload, + DataTelemetryPayload, + DataTelemetryIndex, +} from './get_data_telemetry'; diff --git a/src/plugins/telemetry/server/telemetry_collection/index.ts b/src/plugins/telemetry/server/telemetry_collection/index.ts index 151e89a11a192..55f9c7f0e624c 100644 --- a/src/plugins/telemetry/server/telemetry_collection/index.ts +++ b/src/plugins/telemetry/server/telemetry_collection/index.ts @@ -6,9 +6,12 @@ * Side Public License, v 1. */ -export { DATA_TELEMETRY_ID, buildDataTelemetryPayload } from './get_data_telemetry'; -export type { DataTelemetryIndex, DataTelemetryPayload } from './get_data_telemetry'; -export { getLocalStats } from './get_local_stats'; -export type { TelemetryLocalStats } from './get_local_stats'; +export { + DATA_TELEMETRY_ID, + DataTelemetryIndex, + DataTelemetryPayload, + buildDataTelemetryPayload, +} from './get_data_telemetry'; +export { getLocalStats, TelemetryLocalStats } from './get_local_stats'; export { getClusterUuids } from './get_cluster_stats'; export { registerCollection } from './register_collection'; diff --git a/src/plugins/telemetry/server/telemetry_repository/index.ts b/src/plugins/telemetry/server/telemetry_repository/index.ts index 594b53259a65f..4e3f046f7611f 100644 --- a/src/plugins/telemetry/server/telemetry_repository/index.ts +++ b/src/plugins/telemetry/server/telemetry_repository/index.ts @@ -8,7 +8,7 @@ export { getTelemetrySavedObject } from './get_telemetry_saved_object'; export { updateTelemetrySavedObject } from './update_telemetry_saved_object'; -export type { +export { TelemetrySavedObject, TelemetrySavedObjectAttributes, } from '../../common/telemetry_config/types'; diff --git a/src/plugins/telemetry/tsconfig.json b/src/plugins/telemetry/tsconfig.json index 6629e479906c9..bdced01d9eb6f 100644 --- a/src/plugins/telemetry/tsconfig.json +++ b/src/plugins/telemetry/tsconfig.json @@ -5,8 +5,7 @@ "outDir": "./target/types", "emitDeclarationOnly": true, "declaration": true, - "declarationMap": true, - "isolatedModules": true + "declarationMap": true }, "include": [ "public/**/**/*", diff --git a/src/plugins/telemetry_collection_manager/server/index.ts b/src/plugins/telemetry_collection_manager/server/index.ts index c0cd124a132c0..77077b73cf8ad 100644 --- a/src/plugins/telemetry_collection_manager/server/index.ts +++ b/src/plugins/telemetry_collection_manager/server/index.ts @@ -16,7 +16,7 @@ export function plugin(initializerContext: PluginInitializerContext) { return new TelemetryCollectionManagerPlugin(initializerContext); } -export type { +export { TelemetryCollectionManagerPluginSetup, TelemetryCollectionManagerPluginStart, StatsCollectionConfig, diff --git a/src/plugins/telemetry_collection_manager/tsconfig.json b/src/plugins/telemetry_collection_manager/tsconfig.json index 1329979860603..1bba81769f0dd 100644 --- a/src/plugins/telemetry_collection_manager/tsconfig.json +++ b/src/plugins/telemetry_collection_manager/tsconfig.json @@ -5,8 +5,7 @@ "outDir": "./target/types", "emitDeclarationOnly": true, "declaration": true, - "declarationMap": true, - "isolatedModules": true + "declarationMap": true }, "include": [ "server/**/*", diff --git a/src/plugins/telemetry_management_section/public/index.ts b/src/plugins/telemetry_management_section/public/index.ts index db6ea17556ed3..28b04418f512d 100644 --- a/src/plugins/telemetry_management_section/public/index.ts +++ b/src/plugins/telemetry_management_section/public/index.ts @@ -10,7 +10,7 @@ import { TelemetryManagementSectionPlugin } from './plugin'; export { OptInExampleFlyout } from './components'; -export type { TelemetryManagementSectionPluginSetup } from './plugin'; +export { TelemetryManagementSectionPluginSetup } from './plugin'; export function plugin() { return new TelemetryManagementSectionPlugin(); } diff --git a/src/plugins/telemetry_management_section/tsconfig.json b/src/plugins/telemetry_management_section/tsconfig.json index 2daee868ac200..48e40814b8570 100644 --- a/src/plugins/telemetry_management_section/tsconfig.json +++ b/src/plugins/telemetry_management_section/tsconfig.json @@ -5,8 +5,7 @@ "outDir": "./target/types", "emitDeclarationOnly": true, "declaration": true, - "declarationMap": true, - "isolatedModules": true + "declarationMap": true }, "include": [ "public/**/*", diff --git a/src/plugins/usage_collection/public/index.ts b/src/plugins/usage_collection/public/index.ts index 9b009b1d9e264..b9e0e0a8985b1 100644 --- a/src/plugins/usage_collection/public/index.ts +++ b/src/plugins/usage_collection/public/index.ts @@ -10,7 +10,7 @@ import { PluginInitializerContext } from '../../../core/public'; import { UsageCollectionPlugin } from './plugin'; export { METRIC_TYPE } from '@kbn/analytics'; -export type { UsageCollectionSetup, UsageCollectionStart } from './plugin'; +export { UsageCollectionSetup, UsageCollectionStart } from './plugin'; export { TrackApplicationView } from './components'; export function plugin(initializerContext: PluginInitializerContext) { diff --git a/src/plugins/usage_collection/server/collector/index.ts b/src/plugins/usage_collection/server/collector/index.ts index d5e0d95659e58..5f48f9fb93813 100644 --- a/src/plugins/usage_collection/server/collector/index.ts +++ b/src/plugins/usage_collection/server/collector/index.ts @@ -6,10 +6,9 @@ * Side Public License, v 1. */ -export { CollectorSet } from './collector_set'; -export type { CollectorSetPublic } from './collector_set'; -export { Collector } from './collector'; -export type { +export { CollectorSet, CollectorSetPublic } from './collector_set'; +export { + Collector, AllowedSchemaTypes, AllowedSchemaNumberTypes, SchemaField, @@ -17,5 +16,4 @@ export type { CollectorOptions, CollectorFetchContext, } from './collector'; -export { UsageCollector } from './usage_collector'; -export type { UsageCollectorOptions } from './usage_collector'; +export { UsageCollector, UsageCollectorOptions } from './usage_collector'; diff --git a/src/plugins/usage_collection/server/index.ts b/src/plugins/usage_collection/server/index.ts index dd9e6644a827d..dfc9d19b69646 100644 --- a/src/plugins/usage_collection/server/index.ts +++ b/src/plugins/usage_collection/server/index.ts @@ -9,16 +9,17 @@ import { PluginInitializerContext } from 'src/core/server'; import { UsageCollectionPlugin } from './plugin'; -export { Collector } from './collector'; -export type { +export { AllowedSchemaTypes, MakeSchemaFrom, SchemaField, CollectorOptions, UsageCollectorOptions, + Collector, CollectorFetchContext, } from './collector'; -export type { UsageCollectionSetup } from './plugin'; + +export { UsageCollectionSetup } from './plugin'; export { config } from './config'; export const plugin = (initializerContext: PluginInitializerContext) => new UsageCollectionPlugin(initializerContext); diff --git a/src/plugins/usage_collection/tsconfig.json b/src/plugins/usage_collection/tsconfig.json index 68a0853994e80..96b2c4d37e17c 100644 --- a/src/plugins/usage_collection/tsconfig.json +++ b/src/plugins/usage_collection/tsconfig.json @@ -5,8 +5,7 @@ "outDir": "./target/types", "emitDeclarationOnly": true, "declaration": true, - "declarationMap": true, - "isolatedModules": true + "declarationMap": true }, "include": [ "public/**/*", diff --git a/x-pack/plugins/apm/server/lib/index_pattern/get_dynamic_index_pattern.ts b/x-pack/plugins/apm/server/lib/index_pattern/get_dynamic_index_pattern.ts index 8b81101fd2f39..5d5e6eebb4c9f 100644 --- a/x-pack/plugins/apm/server/lib/index_pattern/get_dynamic_index_pattern.ts +++ b/x-pack/plugins/apm/server/lib/index_pattern/get_dynamic_index_pattern.ts @@ -5,7 +5,6 @@ * 2.0. */ -import LRU from 'lru-cache'; import { IndexPatternsFetcher, FieldDescriptor, @@ -19,11 +18,6 @@ export interface IndexPatternTitleAndFields { fields: FieldDescriptor[]; } -const cache = new LRU({ - max: 100, - maxAge: 1000 * 60, -}); - // TODO: this is currently cached globally. In the future we might want to cache this per user export const getDynamicIndexPattern = ({ context, @@ -33,11 +27,6 @@ export const getDynamicIndexPattern = ({ return withApmSpan('get_dynamic_index_pattern', async () => { const indexPatternTitle = context.config['apm_oss.indexPattern']; - const CACHE_KEY = `apm_dynamic_index_pattern_${indexPatternTitle}`; - if (cache.has(CACHE_KEY)) { - return cache.get(CACHE_KEY); - } - const indexPatternsFetcher = new IndexPatternsFetcher( context.core.elasticsearch.client.asCurrentUser ); @@ -57,11 +46,8 @@ export const getDynamicIndexPattern = ({ title: indexPatternTitle, }; - cache.set(CACHE_KEY, indexPattern); return indexPattern; } catch (e) { - // since `getDynamicIndexPattern` can be called multiple times per request it can be expensive not to cache failed lookups - cache.set(CACHE_KEY, undefined); const notExists = e.output?.statusCode === 404; if (notExists) { context.logger.error( diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/engines/components/header.tsx b/x-pack/plugins/enterprise_search/public/applications/app_search/components/engines/components/header.tsx index fb3b771850a31..df87f2e5230db 100644 --- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/engines/components/header.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/engines/components/header.tsx @@ -26,7 +26,7 @@ export const EnginesOverviewHeader: React.FC = () => { rightSideItems={[ // eslint-disable-next-line @elastic/eui/href-or-on-click { {canManageEngines && ( @@ -108,6 +109,7 @@ export const EnginesOverview: React.FC = () => { + { return (
+

{i18n.translate( diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/relevance_tuning/relevance_tuning_preview.tsx b/x-pack/plugins/enterprise_search/public/applications/app_search/components/relevance_tuning/relevance_tuning_preview.tsx index 5e5ee2ea8d0f0..911e97de5b53f 100644 --- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/relevance_tuning/relevance_tuning_preview.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/relevance_tuning/relevance_tuning_preview.tsx @@ -48,7 +48,7 @@ export const RelevanceTuningPreview: React.FC = () => { const { engineName, isMetaEngine } = useValues(EngineLogic); return ( - +

{i18n.translate('xpack.enterpriseSearch.appSearch.engine.relevanceTuning.preview.title', { diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/layout/account_header/account_header.test.tsx b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/layout/account_header/account_header.test.tsx new file mode 100644 index 0000000000000..e8035f01a9405 --- /dev/null +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/layout/account_header/account_header.test.tsx @@ -0,0 +1,53 @@ +/* + * 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 { setMockValues } from '../../../../__mocks__'; + +import React from 'react'; + +import { shallow } from 'enzyme'; + +import { EuiHeader, EuiPopover } from '@elastic/eui'; + +import { AccountHeader } from './'; + +describe('AccountHeader', () => { + const mockValues = { + account: { + isAdmin: true, + }, + }; + + beforeEach(() => { + setMockValues({ ...mockValues }); + }); + + it('renders', () => { + const wrapper = shallow(); + + expect(wrapper.find(EuiHeader)).toHaveLength(1); + }); + + describe('accountSubNav', () => { + it('handles popover trigger click', () => { + const wrapper = shallow(); + const popover = wrapper.find(EuiPopover); + const onClick = popover.dive().find('[data-test-subj="AccountButton"]').prop('onClick'); + onClick!({} as any); + + expect(onClick).toBeDefined(); + }); + + it('handles close popover', () => { + const wrapper = shallow(); + const popover = wrapper.find(EuiPopover); + popover.prop('closePopover')!(); + + expect(popover.prop('isOpen')).toEqual(false); + }); + }); +}); diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/layout/account_header/account_header.tsx b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/layout/account_header/account_header.tsx new file mode 100644 index 0000000000000..a878d87af09e4 --- /dev/null +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/layout/account_header/account_header.tsx @@ -0,0 +1,107 @@ +/* + * 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 React, { useState } from 'react'; + +import { useValues } from 'kea'; + +import { + EuiButton, + EuiButtonEmpty, + EuiHeader, + EuiHeaderLogo, + EuiHeaderLinks, + EuiHeaderSection, + EuiHeaderSectionItem, + EuiText, + EuiContextMenuPanel, + EuiContextMenuItem, + EuiPopover, +} from '@elastic/eui'; + +import { getWorkplaceSearchUrl } from '../../../../shared/enterprise_search_url'; +import { EuiButtonEmptyTo } from '../../../../shared/react_router_helpers'; +import { AppLogic } from '../../../app_logic'; +import { WORKPLACE_SEARCH_TITLE, ACCOUNT_NAV } from '../../../constants'; +import { + ALPHA_PATH, + PERSONAL_SOURCES_PATH, + LOGOUT_ROUTE, + KIBANA_ACCOUNT_ROUTE, +} from '../../../routes'; + +export const AccountHeader: React.FC = () => { + const [isPopoverOpen, setPopover] = useState(false); + const onButtonClick = () => { + setPopover(!isPopoverOpen); + }; + const closePopover = () => { + setPopover(false); + }; + + const { + account: { isAdmin }, + } = useValues(AppLogic); + + const accountNavItems = [ + + {/* TODO: Once auth is completed, we need to have non-admins redirect to the self-hosted form */} + {ACCOUNT_NAV.SETTINGS} + , + + {ACCOUNT_NAV.LOGOUT} + , + ]; + + const accountButton = ( + + {ACCOUNT_NAV.ACCOUNT} + + ); + + return ( + + + + + {WORKPLACE_SEARCH_TITLE} + + + + {ACCOUNT_NAV.SOURCES} + + + + + + {isAdmin && ( + {ACCOUNT_NAV.ORG_DASHBOARD} + )} + + + + + {ACCOUNT_NAV.SEARCH} + + + + + ); +}; diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/layout/account_header/index.ts b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/layout/account_header/index.ts new file mode 100644 index 0000000000000..e6cd2516fc03a --- /dev/null +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/layout/account_header/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 { AccountHeader } from './account_header'; diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/layout/index.ts b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/layout/index.ts index 2678b5d01b475..b9a49c416f283 100644 --- a/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/layout/index.ts +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/layout/index.ts @@ -7,3 +7,4 @@ export { WorkplaceSearchNav } from './nav'; export { WorkplaceSearchHeaderActions } from './kibana_header_actions'; +export { AccountHeader } from './account_header'; diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/constants.ts b/x-pack/plugins/enterprise_search/public/applications/workplace_search/constants.ts index a6e9ce282bf3d..d771673506761 100644 --- a/x-pack/plugins/enterprise_search/public/applications/workplace_search/constants.ts +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/constants.ts @@ -9,6 +9,13 @@ import { i18n } from '@kbn/i18n'; import { UPDATE_BUTTON_LABEL, SAVE_BUTTON_LABEL, CANCEL_BUTTON_LABEL } from '../shared/constants'; +export const WORKPLACE_SEARCH_TITLE = i18n.translate( + 'xpack.enterpriseSearch.workplaceSearch.title', + { + defaultMessage: 'Workplace Search', + } +); + export const NAV = { OVERVIEW: i18n.translate('xpack.enterpriseSearch.workplaceSearch.nav.overview', { defaultMessage: 'Overview', @@ -76,6 +83,30 @@ export const NAV = { }), }; +export const ACCOUNT_NAV = { + SOURCES: i18n.translate('xpack.enterpriseSearch.workplaceSearch.accountNav.sources.link', { + defaultMessage: 'Content sources', + }), + ORG_DASHBOARD: i18n.translate( + 'xpack.enterpriseSearch.workplaceSearch.accountNav.orgDashboard.link', + { + defaultMessage: 'Go to organizational dashboard', + } + ), + SEARCH: i18n.translate('xpack.enterpriseSearch.workplaceSearch.accountNav.search.link', { + defaultMessage: 'Search', + }), + ACCOUNT: i18n.translate('xpack.enterpriseSearch.workplaceSearch.accountNav.account.link', { + defaultMessage: 'My account', + }), + SETTINGS: i18n.translate('xpack.enterpriseSearch.workplaceSearch.accountNav.settings.link', { + defaultMessage: 'Account settings', + }), + LOGOUT: i18n.translate('xpack.enterpriseSearch.workplaceSearch.accountNav.logout.link', { + defaultMessage: 'Logout', + }), +}; + export const MAX_TABLE_ROW_ICONS = 3; export const SOURCE_STATUSES = { diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/index.tsx b/x-pack/plugins/enterprise_search/public/applications/workplace_search/index.tsx index 7a76de43be41b..a8d6fc54f7924 100644 --- a/x-pack/plugins/enterprise_search/public/applications/workplace_search/index.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/index.tsx @@ -66,11 +66,13 @@ export const WorkplaceSearchConfigured: React.FC = (props) => { * Personal dashboard urls begin with /p/ * EX: http://localhost:5601/app/enterprise_search/workplace_search/p/sources */ - useEffect(() => { - const personalSourceUrlRegex = /^\/p\//g; // matches '/p/*' - const isOrganization = !pathname.match(personalSourceUrlRegex); // TODO: Once auth is figured out, we need to have a check for the equivilent of `isAdmin`. - setContext(isOrganization); + const personalSourceUrlRegex = /^\/p\//g; // matches '/p/*' + const isOrganization = !pathname.match(personalSourceUrlRegex); // TODO: Once auth is figured out, we need to have a check for the equivilent of `isAdmin`. + + setContext(isOrganization); + + useEffect(() => { setChromeIsVisible(isOrganization); }, [pathname]); diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/routes.ts b/x-pack/plugins/enterprise_search/public/applications/workplace_search/routes.ts index 9e514d7c73493..e08050335671e 100644 --- a/x-pack/plugins/enterprise_search/public/applications/workplace_search/routes.ts +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/routes.ts @@ -12,6 +12,8 @@ import { docLinks } from '../shared/doc_links'; export const SETUP_GUIDE_PATH = '/setup_guide'; export const NOT_FOUND_PATH = '/404'; +export const LOGOUT_ROUTE = '/logout'; +export const KIBANA_ACCOUNT_ROUTE = '/security/account'; export const LEAVE_FEEDBACK_EMAIL = 'support@elastic.co'; export const LEAVE_FEEDBACK_URL = `mailto:${LEAVE_FEEDBACK_EMAIL}?Subject=Elastic%20Workplace%20Search%20Feedback`; diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/private_sources_layout.test.tsx b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/private_sources_layout.test.tsx index 9e3b50ea083eb..7558eb1e4e662 100644 --- a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/private_sources_layout.test.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/private_sources_layout.test.tsx @@ -15,6 +15,7 @@ import { shallow } from 'enzyme'; import { EuiCallOut } from '@elastic/eui'; +import { AccountHeader } from '../../components/layout'; import { ViewContentHeader } from '../../components/shared/view_content_header'; import { SourceSubNav } from './components/source_sub_nav'; @@ -43,6 +44,7 @@ describe('PrivateSourcesLayout', () => { expect(wrapper.find('[data-test-subj="TestChildren"]')).toHaveLength(1); expect(wrapper.find(SourceSubNav)).toHaveLength(1); + expect(wrapper.find(AccountHeader)).toHaveLength(1); }); it('uses correct title and description when private sources are enabled', () => { diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/private_sources_layout.tsx b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/private_sources_layout.tsx index 2a6281075dc40..c565ee5f39a71 100644 --- a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/private_sources_layout.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/private_sources_layout.tsx @@ -12,6 +12,7 @@ import { useValues } from 'kea'; import { EuiPage, EuiPageSideBar, EuiPageBody, EuiCallOut } from '@elastic/eui'; import { AppLogic } from '../../app_logic'; +import { AccountHeader } from '../../components/layout'; import { ViewContentHeader } from '../../components/shared/view_content_header'; import { SourceSubNav } from './components/source_sub_nav'; @@ -48,22 +49,25 @@ export const PrivateSourcesLayout: React.FC = ({ : PRIVATE_VIEW_ONLY_PAGE_DESCRIPTION; return ( - - - - - - - {readOnlyMode && ( - - )} - {children} - - + <> + + + + + + + + {readOnlyMode && ( + + )} + {children} + + + ); }; diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/sources.scss b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/sources.scss index abab139e32369..549ca3ae9154e 100644 --- a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/sources.scss +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/sources.scss @@ -20,14 +20,18 @@ .privateSourcesLayout { $sideBarWidth: $euiSize * 30; + $consoleHeaderHeight: 48px; // NOTE: Keep an eye on this for changes + $pageHeight: calc(100vh - #{$consoleHeaderHeight}); left: $sideBarWidth; width: calc(100% - #{$sideBarWidth}); + min-height: $pageHeight; &__sideBar { padding: 32px 40px 40px; width: $sideBarWidth; margin-left: -$sideBarWidth; + height: $pageHeight; } } diff --git a/x-pack/plugins/fleet/common/types/models/preconfiguration.ts b/x-pack/plugins/fleet/common/types/models/preconfiguration.ts index b16234d5a5f97..c9fff1c1581bd 100644 --- a/x-pack/plugins/fleet/common/types/models/preconfiguration.ts +++ b/x-pack/plugins/fleet/common/types/models/preconfiguration.ts @@ -27,3 +27,7 @@ export interface PreconfiguredAgentPolicy extends Omit; } + +export interface PreconfiguredPackage extends Omit { + force?: boolean; +} diff --git a/x-pack/plugins/fleet/server/services/agents/crud.ts b/x-pack/plugins/fleet/server/services/agents/crud.ts index ecf18430da668..a23efa1e50fc0 100644 --- a/x-pack/plugins/fleet/server/services/agents/crud.ts +++ b/x-pack/plugins/fleet/server/services/agents/crud.ts @@ -125,6 +125,7 @@ export async function getAgentsByKuery( size: perPage, sort: `${sortField}:${sortOrder}`, track_total_hits: true, + ignore_unavailable: true, body, }); @@ -180,6 +181,7 @@ export async function countInactiveAgents( index: AGENTS_INDEX, size: 0, track_total_hits: true, + ignore_unavailable: true, body, }); // @ts-expect-error value is number | TotalHits @@ -249,6 +251,7 @@ export async function getAgentByAccessAPIKeyId( ): Promise { const res = await esClient.search({ index: AGENTS_INDEX, + ignore_unavailable: true, q: `access_api_key_id:${escapeSearchQueryPhrase(accessAPIKeyId)}`, }); diff --git a/x-pack/plugins/fleet/server/services/api_keys/enrollment_api_key.ts b/x-pack/plugins/fleet/server/services/api_keys/enrollment_api_key.ts index 643caa8d3bb6f..7059cc96159b9 100644 --- a/x-pack/plugins/fleet/server/services/api_keys/enrollment_api_key.ts +++ b/x-pack/plugins/fleet/server/services/api_keys/enrollment_api_key.ts @@ -38,6 +38,7 @@ export async function listEnrollmentApiKeys( size: perPage, sort: 'created_at:desc', track_total_hits: true, + ignore_unavailable: true, q: kuery, }); @@ -230,6 +231,7 @@ export async function generateEnrollmentAPIKey( export async function getEnrollmentAPIKeyById(esClient: ElasticsearchClient, apiKeyId: string) { const res = await esClient.search({ index: ENROLLMENT_API_KEYS_INDEX, + ignore_unavailable: true, q: `api_key_id:${escapeSearchQueryPhrase(apiKeyId)}`, }); diff --git a/x-pack/plugins/fleet/server/services/artifacts/artifacts.test.ts b/x-pack/plugins/fleet/server/services/artifacts/artifacts.test.ts index d4f129a1ae241..5681be3e8793b 100644 --- a/x-pack/plugins/fleet/server/services/artifacts/artifacts.test.ts +++ b/x-pack/plugins/fleet/server/services/artifacts/artifacts.test.ts @@ -152,6 +152,7 @@ describe('When using the artifacts services', () => { expect(esClientMock.search).toHaveBeenCalledWith({ index: FLEET_SERVER_ARTIFACTS_INDEX, sort: 'created:asc', + ignore_unavailable: true, q: '', from: 0, size: 20, @@ -184,6 +185,7 @@ describe('When using the artifacts services', () => { index: FLEET_SERVER_ARTIFACTS_INDEX, sort: 'identifier:desc', q: 'packageName:endpoint', + ignore_unavailable: true, from: 450, size: 50, }); diff --git a/x-pack/plugins/fleet/server/services/artifacts/artifacts.ts b/x-pack/plugins/fleet/server/services/artifacts/artifacts.ts index 6e2c22cc2f045..26032ab94dbc8 100644 --- a/x-pack/plugins/fleet/server/services/artifacts/artifacts.ts +++ b/x-pack/plugins/fleet/server/services/artifacts/artifacts.ts @@ -105,6 +105,7 @@ export const listArtifacts = async ( sort: `${sortField}:${sortOrder}`, q: kuery, from: (page - 1) * perPage, + ignore_unavailable: true, size: perPage, }); diff --git a/x-pack/plugins/fleet/server/services/epm/packages/install.ts b/x-pack/plugins/fleet/server/services/epm/packages/install.ts index 7095bb1688c73..168ec55b14876 100644 --- a/x-pack/plugins/fleet/server/services/epm/packages/install.ts +++ b/x-pack/plugins/fleet/server/services/epm/packages/install.ts @@ -115,8 +115,9 @@ export async function ensureInstalledPackage(options: { pkgName: string; esClient: ElasticsearchClient; pkgVersion?: string; + force?: boolean; }): Promise { - const { savedObjectsClient, pkgName, esClient, pkgVersion } = options; + const { savedObjectsClient, pkgName, esClient, pkgVersion, force } = options; const installedPackage = await isPackageVersionInstalled({ savedObjectsClient, pkgName, @@ -136,7 +137,7 @@ export async function ensureInstalledPackage(options: { savedObjectsClient, pkgkey, esClient, - force: true, + force, }); } else { await installLatestPackage({ diff --git a/x-pack/plugins/fleet/server/services/fleet_server/elastic_index.test.ts b/x-pack/plugins/fleet/server/services/fleet_server/elastic_index.test.ts deleted file mode 100644 index 275ea421a508f..0000000000000 --- a/x-pack/plugins/fleet/server/services/fleet_server/elastic_index.test.ts +++ /dev/null @@ -1,141 +0,0 @@ -/* - * 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 { elasticsearchServiceMock } from 'src/core/server/mocks'; -import hash from 'object-hash'; - -import { FLEET_SERVER_INDICES } from '../../../common'; - -import { setupFleetServerIndexes } from './elastic_index'; -import ESFleetAgentIndex from './elasticsearch/fleet_agents.json'; -import ESFleetPoliciesIndex from './elasticsearch/fleet_policies.json'; -import ESFleetPoliciesLeaderIndex from './elasticsearch/fleet_policies_leader.json'; -import ESFleetServersIndex from './elasticsearch/fleet_servers.json'; -import ESFleetEnrollmentApiKeysIndex from './elasticsearch/fleet_enrollment_api_keys.json'; -import EsFleetActionsIndex from './elasticsearch/fleet_actions.json'; -import EsFleetArtifactsIndex from './elasticsearch/fleet_artifacts.json'; - -const FLEET_INDEXES_MIGRATION_HASH: Record = { - '.fleet-actions': hash(EsFleetActionsIndex), - '.fleet-agents': hash(ESFleetAgentIndex), - '.fleet-artifacts': hash(EsFleetArtifactsIndex), - '.fleet-enrollment-apy-keys': hash(ESFleetEnrollmentApiKeysIndex), - '.fleet-policies': hash(ESFleetPoliciesIndex), - '.fleet-policies-leader': hash(ESFleetPoliciesLeaderIndex), - '.fleet-servers': hash(ESFleetServersIndex), -}; - -const getIndexList = (returnAliases: boolean = false): string[] => { - const response = [...FLEET_SERVER_INDICES]; - - if (returnAliases) { - return response.sort(); - } - - return response.map((index) => `${index}_1`).sort(); -}; - -describe('setupFleetServerIndexes ', () => { - it('should create all the indices and aliases if nothings exists', async () => { - const esMock = elasticsearchServiceMock.createInternalClient(); - await setupFleetServerIndexes(esMock); - - const indexesCreated = esMock.indices.create.mock.calls.map((call) => call[0].index).sort(); - expect(indexesCreated).toEqual(getIndexList()); - const aliasesCreated = esMock.indices.updateAliases.mock.calls - .map((call) => (call[0].body as any)?.actions[0].add.alias) - .sort(); - - expect(aliasesCreated).toEqual(getIndexList(true)); - }); - - it('should not create any indices and create aliases if indices exists but not the aliases', async () => { - const esMock = elasticsearchServiceMock.createInternalClient(); - // @ts-expect-error - esMock.indices.exists.mockResolvedValue({ body: true }); - // @ts-expect-error - esMock.indices.getMapping.mockImplementation((params: { index: string }) => { - return { - body: { - [params.index]: { - mappings: { - _meta: { - migrationHash: FLEET_INDEXES_MIGRATION_HASH[params.index.replace(/_1$/, '')], - }, - }, - }, - }, - }; - }); - - await setupFleetServerIndexes(esMock); - - expect(esMock.indices.create).not.toBeCalled(); - const aliasesCreated = esMock.indices.updateAliases.mock.calls - .map((call) => (call[0].body as any)?.actions[0].add.alias) - .sort(); - - expect(aliasesCreated).toEqual(getIndexList(true)); - }); - - it('should put new indices mapping if the mapping has been updated ', async () => { - const esMock = elasticsearchServiceMock.createInternalClient(); - // @ts-expect-error - esMock.indices.exists.mockResolvedValue({ body: true }); - // @ts-expect-error - esMock.indices.getMapping.mockImplementation((params: { index: string }) => { - return { - body: { - [params.index]: { - mappings: { - _meta: { - migrationHash: 'NOT_VALID_HASH', - }, - }, - }, - }, - }; - }); - - await setupFleetServerIndexes(esMock); - - expect(esMock.indices.create).not.toBeCalled(); - const indexesMappingUpdated = esMock.indices.putMapping.mock.calls - .map((call) => call[0].index) - .sort(); - - expect(indexesMappingUpdated).toEqual(getIndexList()); - }); - - it('should not create any indices or aliases if indices and aliases already exists', async () => { - const esMock = elasticsearchServiceMock.createInternalClient(); - - // @ts-expect-error - esMock.indices.exists.mockResolvedValue({ body: true }); - // @ts-expect-error - esMock.indices.getMapping.mockImplementation((params: { index: string }) => { - return { - body: { - [params.index]: { - mappings: { - _meta: { - migrationHash: FLEET_INDEXES_MIGRATION_HASH[params.index.replace(/_1$/, '')], - }, - }, - }, - }, - }; - }); - // @ts-expect-error - esMock.indices.existsAlias.mockResolvedValue({ body: true }); - - await setupFleetServerIndexes(esMock); - - expect(esMock.indices.create).not.toBeCalled(); - expect(esMock.indices.updateAliases).not.toBeCalled(); - }); -}); diff --git a/x-pack/plugins/fleet/server/services/fleet_server/elastic_index.ts b/x-pack/plugins/fleet/server/services/fleet_server/elastic_index.ts deleted file mode 100644 index b0dce60085529..0000000000000 --- a/x-pack/plugins/fleet/server/services/fleet_server/elastic_index.ts +++ /dev/null @@ -1,136 +0,0 @@ -/* - * 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 type { ElasticsearchClient } from 'kibana/server'; -import hash from 'object-hash'; - -import type { FLEET_SERVER_INDICES } from '../../../common'; -import { FLEET_SERVER_INDICES_VERSION } from '../../../common'; -import { appContextService } from '../app_context'; - -import { FleetSetupError } from '../../errors'; - -import ESFleetAgentIndex from './elasticsearch/fleet_agents.json'; -import ESFleetPoliciesIndex from './elasticsearch/fleet_policies.json'; -import ESFleetPoliciesLeaderIndex from './elasticsearch/fleet_policies_leader.json'; -import ESFleetServersIndex from './elasticsearch/fleet_servers.json'; -import ESFleetEnrollmentApiKeysIndex from './elasticsearch/fleet_enrollment_api_keys.json'; -import EsFleetActionsIndex from './elasticsearch/fleet_actions.json'; -import EsFleetArtifactsIndex from './elasticsearch/fleet_artifacts.json'; - -const FLEET_INDEXES: Array<[typeof FLEET_SERVER_INDICES[number], any]> = [ - ['.fleet-actions', EsFleetActionsIndex], - ['.fleet-agents', ESFleetAgentIndex], - ['.fleet-artifacts', EsFleetArtifactsIndex], - ['.fleet-enrollment-api-keys', ESFleetEnrollmentApiKeysIndex], - ['.fleet-policies', ESFleetPoliciesIndex], - ['.fleet-policies-leader', ESFleetPoliciesLeaderIndex], - ['.fleet-servers', ESFleetServersIndex], -]; - -export async function setupFleetServerIndexes( - esClient = appContextService.getInternalUserESClient() -) { - await Promise.all( - FLEET_INDEXES.map(async ([indexAlias, indexData]) => { - const index = `${indexAlias}_${FLEET_SERVER_INDICES_VERSION}`; - await createOrUpdateIndex(esClient, index, indexData); - await createAliasIfDoNotExists(esClient, indexAlias, index); - }) - ); -} - -export async function createAliasIfDoNotExists( - esClient: ElasticsearchClient, - alias: string, - index: string -) { - try { - const { body: exists } = await esClient.indices.existsAlias({ - name: alias, - }); - - if (exists === true) { - return; - } - await esClient.indices.updateAliases({ - body: { - actions: [ - { - add: { index, alias }, - }, - ], - }, - }); - } catch (e) { - throw new FleetSetupError(`Create of alias [${alias}] for index [${index}] failed`, e); - } -} - -async function createOrUpdateIndex( - esClient: ElasticsearchClient, - indexName: string, - indexData: any -) { - const resExists = await esClient.indices.exists({ - index: indexName, - }); - - // Support non destructive migration only (adding new field) - if (resExists.body === true) { - return updateIndex(esClient, indexName, indexData); - } - - return createIndex(esClient, indexName, indexData); -} - -async function updateIndex(esClient: ElasticsearchClient, indexName: string, indexData: any) { - try { - const res = await esClient.indices.getMapping({ - index: indexName, - }); - - const migrationHash = hash(indexData); - if (res.body[indexName].mappings?._meta?.migrationHash !== migrationHash) { - await esClient.indices.putMapping({ - index: indexName, - body: Object.assign({ - ...indexData.mappings, - _meta: { ...(indexData.mappings._meta || {}), migrationHash }, - }), - }); - } - } catch (e) { - throw new FleetSetupError(`update of index [${indexName}] failed`, e); - } -} - -async function createIndex(esClient: ElasticsearchClient, indexName: string, indexData: any) { - try { - const migrationHash = hash(indexData); - await esClient.indices.create({ - index: indexName, - body: { - ...indexData, - settings: { - ...(indexData.settings || {}), - auto_expand_replicas: '0-1', - }, - - mappings: Object.assign({ - ...indexData.mappings, - _meta: { ...(indexData.mappings._meta || {}), migrationHash }, - }), - }, - }); - } catch (err) { - // Swallow already exists errors as concurent Kibana can try to create that indice - if (err?.body?.error?.type !== 'resource_already_exists_exception') { - throw new FleetSetupError(`create of index [${indexName}] Failed`, err); - } - } -} diff --git a/x-pack/plugins/fleet/server/services/fleet_server/elasticsearch/fleet_actions.json b/x-pack/plugins/fleet/server/services/fleet_server/elasticsearch/fleet_actions.json deleted file mode 100644 index 94ad02c6d5f18..0000000000000 --- a/x-pack/plugins/fleet/server/services/fleet_server/elasticsearch/fleet_actions.json +++ /dev/null @@ -1,33 +0,0 @@ -{ - "settings": {}, - "mappings": { - "dynamic": false, - "properties": { - "action_id": { - "type": "keyword" - }, - "agents": { - "type": "keyword" - }, - "data": { - "enabled": false, - "type": "object" - }, - "expiration": { - "type": "date" - }, - "input_type": { - "type": "keyword" - }, - "@timestamp": { - "type": "date" - }, - "type": { - "type": "keyword" - }, - "user_id" : { - "type": "keyword" - } - } - } -} diff --git a/x-pack/plugins/fleet/server/services/fleet_server/elasticsearch/fleet_agents.json b/x-pack/plugins/fleet/server/services/fleet_server/elasticsearch/fleet_agents.json deleted file mode 100644 index 32caa684679d8..0000000000000 --- a/x-pack/plugins/fleet/server/services/fleet_server/elasticsearch/fleet_agents.json +++ /dev/null @@ -1,224 +0,0 @@ -{ - "settings": {}, - "mappings": { - "dynamic": false, - "properties": { - "access_api_key_id": { - "type": "keyword" - }, - "action_seq_no": { - "type": "integer", - "index": false - }, - "active": { - "type": "boolean" - }, - "agent": { - "properties": { - "id": { - "type": "keyword" - }, - "version": { - "type": "keyword" - } - } - }, - "default_api_key": { - "type": "keyword" - }, - "default_api_key_id": { - "type": "keyword" - }, - "enrolled_at": { - "type": "date" - }, - "last_checkin": { - "type": "date" - }, - "last_checkin_status": { - "type": "keyword" - }, - "last_updated": { - "type": "date" - }, - "local_metadata": { - "properties": { - "elastic": { - "properties": { - "agent": { - "properties": { - "build": { - "properties": { - "original": { - "type": "text", - "fields": { - "keyword": { - "type": "keyword", - "ignore_above": 256 - } - } - } - } - }, - "id": { - "type": "keyword" - }, - "log_level": { - "type": "keyword" - }, - "snapshot": { - "type": "boolean" - }, - "upgradeable": { - "type": "boolean" - }, - "version": { - "type": "text", - "fields": { - "keyword": { - "type": "keyword", - "ignore_above": 16 - } - } - } - } - } - } - }, - "host": { - "properties": { - "architecture": { - "type": "keyword" - }, - "hostname": { - "type": "text", - "fields": { - "keyword": { - "type": "keyword", - "ignore_above": 256 - } - } - }, - "id": { - "type": "keyword" - }, - "ip": { - "type": "text", - "fields": { - "keyword": { - "type": "keyword", - "ignore_above": 64 - } - } - }, - "mac": { - "type": "text", - "fields": { - "keyword": { - "type": "keyword", - "ignore_above": 17 - } - } - }, - "name": { - "type": "text", - "fields": { - "keyword": { - "type": "keyword", - "ignore_above": 256 - } - } - } - } - }, - "os": { - "properties": { - "family": { - "type": "keyword" - }, - "full": { - "type": "text", - "fields": { - "keyword": { - "type": "keyword", - "ignore_above": 128 - } - } - }, - "kernel": { - "type": "text", - "fields": { - "keyword": { - "type": "keyword", - "ignore_above": 128 - } - } - }, - "name": { - "type": "text", - "fields": { - "keyword": { - "type": "keyword", - "ignore_above": 256 - } - } - }, - "platform": { - "type": "keyword" - }, - "version": { - "type": "text", - "fields": { - "keyword": { - "type": "keyword", - "ignore_above": 32 - } - } - } - } - } - } - }, - "packages": { - "type": "keyword" - }, - "policy_coordinator_idx": { - "type": "integer" - }, - "policy_id": { - "type": "keyword" - }, - "policy_output_permissions_hash": { - "type": "keyword" - }, - "policy_revision_idx": { - "type": "integer" - }, - "shared_id": { - "type": "keyword" - }, - "type": { - "type": "keyword" - }, - "unenrolled_at": { - "type": "date" - }, - "unenrollment_started_at": { - "type": "date" - }, - "updated_at": { - "type": "date" - }, - "upgrade_started_at": { - "type": "date" - }, - "upgraded_at": { - "type": "date" - }, - "user_provided_metadata": { - "type": "object", - "enabled": false - } - } - } -} diff --git a/x-pack/plugins/fleet/server/services/fleet_server/elasticsearch/fleet_artifacts.json b/x-pack/plugins/fleet/server/services/fleet_server/elasticsearch/fleet_artifacts.json deleted file mode 100644 index 1f9643fd599d5..0000000000000 --- a/x-pack/plugins/fleet/server/services/fleet_server/elasticsearch/fleet_artifacts.json +++ /dev/null @@ -1,48 +0,0 @@ -{ - "settings": {}, - "mappings": { - "dynamic": false, - "properties": { - "identifier": { - "type": "keyword" - }, - "compression_algorithm": { - "type": "keyword", - "index": false - }, - "encryption_algorithm": { - "type": "keyword", - "index": false - }, - "encoded_sha256": { - "type": "keyword" - }, - "encoded_size": { - "type": "long", - "index": false - }, - "decoded_sha256": { - "type": "keyword" - }, - "decoded_size": { - "type": "long", - "index": false - }, - "created": { - "type": "date" - }, - "package_name": { - "type": "keyword" - }, - "type": { - "type": "keyword" - }, - "relative_url": { - "type": "keyword" - }, - "body": { - "type": "binary" - } - } - } -} diff --git a/x-pack/plugins/fleet/server/services/fleet_server/elasticsearch/fleet_enrollment_api_keys.json b/x-pack/plugins/fleet/server/services/fleet_server/elasticsearch/fleet_enrollment_api_keys.json deleted file mode 100644 index fc3898aff55c6..0000000000000 --- a/x-pack/plugins/fleet/server/services/fleet_server/elasticsearch/fleet_enrollment_api_keys.json +++ /dev/null @@ -1,32 +0,0 @@ -{ - "settings": {}, - "mappings": { - "dynamic": false, - "properties": { - "active": { - "type": "boolean" - }, - "api_key": { - "type": "keyword" - }, - "api_key_id": { - "type": "keyword" - }, - "created_at": { - "type": "date" - }, - "expire_at": { - "type": "date" - }, - "name": { - "type": "keyword" - }, - "policy_id": { - "type": "keyword" - }, - "updated_at": { - "type": "date" - } - } - } -} diff --git a/x-pack/plugins/fleet/server/services/fleet_server/elasticsearch/fleet_policies.json b/x-pack/plugins/fleet/server/services/fleet_server/elasticsearch/fleet_policies.json deleted file mode 100644 index 50078aaa5ea98..0000000000000 --- a/x-pack/plugins/fleet/server/services/fleet_server/elasticsearch/fleet_policies.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "settings": {}, - "mappings": { - "dynamic": false, - "properties": { - "coordinator_idx": { - "type": "integer" - }, - "data": { - "enabled": false, - "type": "object" - }, - "default_fleet_server": { - "type": "boolean" - }, - "policy_id": { - "type": "keyword" - }, - "revision_idx": { - "type": "integer" - }, - "@timestamp": { - "type": "date" - } - } - } -} diff --git a/x-pack/plugins/fleet/server/services/fleet_server/elasticsearch/fleet_policies_leader.json b/x-pack/plugins/fleet/server/services/fleet_server/elasticsearch/fleet_policies_leader.json deleted file mode 100644 index ad3dfe64df57c..0000000000000 --- a/x-pack/plugins/fleet/server/services/fleet_server/elasticsearch/fleet_policies_leader.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "settings": {}, - "mappings": { - "dynamic": false, - "properties": { - "server": { - "properties": { - "id": { - "type": "keyword" - }, - "version": { - "type": "keyword" - } - } - }, - "@timestamp": { - "type": "date" - } - } - } -} diff --git a/x-pack/plugins/fleet/server/services/fleet_server/elasticsearch/fleet_servers.json b/x-pack/plugins/fleet/server/services/fleet_server/elasticsearch/fleet_servers.json deleted file mode 100644 index 9ee68735d5b6f..0000000000000 --- a/x-pack/plugins/fleet/server/services/fleet_server/elasticsearch/fleet_servers.json +++ /dev/null @@ -1,47 +0,0 @@ -{ - "settings": {}, - "mappings": { - "dynamic": false, - "properties": { - "agent": { - "properties": { - "id": { - "type": "keyword" - }, - "version": { - "type": "keyword" - } - } - }, - "host": { - "properties": { - "architecture": { - "type": "keyword" - }, - "id": { - "type": "keyword" - }, - "ip": { - "type": "keyword" - }, - "name": { - "type": "keyword" - } - } - }, - "server": { - "properties": { - "id": { - "type": "keyword" - }, - "version": { - "type": "keyword" - } - } - }, - "@timestamp": { - "type": "date" - } - } - } -} diff --git a/x-pack/plugins/fleet/server/services/fleet_server/index.ts b/x-pack/plugins/fleet/server/services/fleet_server/index.ts index c2b24ce96c213..94f14fac01d3f 100644 --- a/x-pack/plugins/fleet/server/services/fleet_server/index.ts +++ b/x-pack/plugins/fleet/server/services/fleet_server/index.ts @@ -10,7 +10,6 @@ import { first } from 'rxjs/operators'; import { appContextService } from '../app_context'; import { licenseService } from '../license'; -import { setupFleetServerIndexes } from './elastic_index'; import { runFleetServerMigration } from './saved_object_migrations'; let _isFleetServerSetup = false; @@ -45,7 +44,6 @@ export async function startFleetServerSetup() { try { // We need licence to be initialized before using the SO service. await licenseService.getLicenseInformation$()?.pipe(first())?.toPromise(); - await setupFleetServerIndexes(); await runFleetServerMigration(); _isFleetServerSetup = true; } catch (err) { diff --git a/x-pack/plugins/fleet/server/services/fleet_server/saved_object_migrations.ts b/x-pack/plugins/fleet/server/services/fleet_server/saved_object_migrations.ts index 78172e4dae366..df8aa7cb01286 100644 --- a/x-pack/plugins/fleet/server/services/fleet_server/saved_object_migrations.ts +++ b/x-pack/plugins/fleet/server/services/fleet_server/saved_object_migrations.ts @@ -177,6 +177,7 @@ async function migrateAgentPolicies() { index: AGENT_POLICY_INDEX, q: `policy_id:${agentPolicy.id}`, track_total_hits: true, + ignore_unavailable: true, }); // @ts-expect-error value is number | TotalHits diff --git a/x-pack/plugins/fleet/server/services/preconfiguration.test.ts b/x-pack/plugins/fleet/server/services/preconfiguration.test.ts index bcde8ade427e5..8a885f9c5c821 100644 --- a/x-pack/plugins/fleet/server/services/preconfiguration.test.ts +++ b/x-pack/plugins/fleet/server/services/preconfiguration.test.ts @@ -66,9 +66,19 @@ function getPutPreconfiguredPackagesMock() { } jest.mock('./epm/packages/install', () => ({ - ensureInstalledPackage({ pkgName, pkgVersion }: { pkgName: string; pkgVersion: string }) { + ensureInstalledPackage({ + pkgName, + pkgVersion, + force, + }: { + pkgName: string; + pkgVersion: string; + force?: boolean; + }) { const installedPackage = mockInstalledPackages.get(pkgName); - if (installedPackage) return installedPackage; + if (installedPackage) { + if (installedPackage.version === pkgVersion) return installedPackage; + } const packageInstallation = { name: pkgName, version: pkgVersion, title: pkgName }; mockInstalledPackages.set(pkgName, packageInstallation); @@ -138,12 +148,12 @@ describe('policy preconfiguration', () => { soClient, esClient, [], - [{ name: 'test-package', version: '3.0.0' }], + [{ name: 'test_package', version: '3.0.0' }], mockDefaultOutput ); expect(policies.length).toBe(0); - expect(packages).toEqual(expect.arrayContaining(['test-package:3.0.0'])); + expect(packages).toEqual(expect.arrayContaining(['test_package-3.0.0'])); }); it('should install packages and configure agent policies successfully', async () => { @@ -160,19 +170,19 @@ describe('policy preconfiguration', () => { id: 'test-id', package_policies: [ { - package: { name: 'test-package' }, + package: { name: 'test_package' }, name: 'Test package', }, ], }, ] as PreconfiguredAgentPolicy[], - [{ name: 'test-package', version: '3.0.0' }], + [{ name: 'test_package', version: '3.0.0' }], mockDefaultOutput ); expect(policies.length).toEqual(1); expect(policies[0].id).toBe('mocked-test-id'); - expect(packages).toEqual(expect.arrayContaining(['test-package:3.0.0'])); + expect(packages).toEqual(expect.arrayContaining(['test_package-3.0.0'])); }); it('should throw an error when trying to install duplicate packages', async () => { @@ -185,13 +195,13 @@ describe('policy preconfiguration', () => { esClient, [], [ - { name: 'test-package', version: '3.0.0' }, - { name: 'test-package', version: '2.0.0' }, + { name: 'test_package', version: '3.0.0' }, + { name: 'test_package', version: '2.0.0' }, ], mockDefaultOutput ) ).rejects.toThrow( - 'Duplicate packages specified in configuration: test-package:3.0.0, test-package:2.0.0' + 'Duplicate packages specified in configuration: test_package-3.0.0, test_package-2.0.0' ); }); diff --git a/x-pack/plugins/fleet/server/services/preconfiguration.ts b/x-pack/plugins/fleet/server/services/preconfiguration.ts index bd1c2ca1f23ef..97480fcf6b2a8 100644 --- a/x-pack/plugins/fleet/server/services/preconfiguration.ts +++ b/x-pack/plugins/fleet/server/services/preconfiguration.ts @@ -7,10 +7,9 @@ import type { ElasticsearchClient, SavedObjectsClientContract } from 'src/core/server'; import { i18n } from '@kbn/i18n'; -import { groupBy } from 'lodash'; +import { groupBy, omit } from 'lodash'; import type { - PackagePolicyPackage, NewPackagePolicy, AgentPolicy, Installation, @@ -18,8 +17,10 @@ import type { NewPackagePolicyInput, NewPackagePolicyInputStream, PreconfiguredAgentPolicy, + PreconfiguredPackage, } from '../../common'; +import { pkgToPkgKey } from './epm/registry'; import { getInstallation } from './epm/packages'; import { ensureInstalledPackage } from './epm/packages/install'; import { agentPolicyService, addPackageToAgentPolicy } from './agent_policy'; @@ -32,7 +33,7 @@ export async function ensurePreconfiguredPackagesAndPolicies( soClient: SavedObjectsClientContract, esClient: ElasticsearchClient, policies: PreconfiguredAgentPolicy[] = [], - packages: Array> = [], + packages: PreconfiguredPackage[] = [], defaultOutput: Output ) { // Validate configured packages to ensure there are no version conflicts @@ -45,7 +46,7 @@ export async function ensurePreconfiguredPackagesAndPolicies( // If there are multiple packages with duplicate versions, separate them with semicolons, e.g // package-a:1.0.0, package-a:2.0.0; package-b:1.0.0, package-b:2.0.0 const duplicateList = duplicatePackages - .map(([, versions]) => versions.map((v) => `${v.name}:${v.version}`).join(', ')) + .map(([, versions]) => versions.map((v) => pkgToPkgKey(v)).join(', ')) .join('; '); throw new Error( @@ -60,8 +61,8 @@ export async function ensurePreconfiguredPackagesAndPolicies( // Preinstall packages specified in Kibana config const preconfiguredPackages = await Promise.all( - packages.map(({ name, version }) => - ensureInstalledPreconfiguredPackage(soClient, esClient, name, version) + packages.map(({ name, version, force }) => + ensureInstalledPreconfiguredPackage(soClient, esClient, name, version, force) ) ); @@ -71,7 +72,7 @@ export async function ensurePreconfiguredPackagesAndPolicies( const { created, policy } = await agentPolicyService.ensurePreconfiguredAgentPolicy( soClient, esClient, - preconfiguredAgentPolicy + omit(preconfiguredAgentPolicy, 'is_managed') // Don't add `is_managed` until the policy has been fully configured ); if (!created) return { created, policy }; @@ -101,12 +102,22 @@ export async function ensurePreconfiguredPackagesAndPolicies( }) ); - return { created, policy, installedPackagePolicies }; + return { + created, + policy, + installedPackagePolicies, + shouldAddIsManagedFlag: preconfiguredAgentPolicy.is_managed, + }; }) ); for (const preconfiguredPolicy of preconfiguredPolicies) { - const { created, policy, installedPackagePolicies } = preconfiguredPolicy; + const { + created, + policy, + installedPackagePolicies, + shouldAddIsManagedFlag, + } = preconfiguredPolicy; if (created) { await addPreconfiguredPolicyPackages( soClient, @@ -115,6 +126,10 @@ export async function ensurePreconfiguredPackagesAndPolicies( installedPackagePolicies!, defaultOutput ); + // Add the is_managed flag after configuring package policies to avoid errors + if (shouldAddIsManagedFlag) { + agentPolicyService.update(soClient, esClient, policy.id, { is_managed: true }); + } } } @@ -123,7 +138,7 @@ export async function ensurePreconfiguredPackagesAndPolicies( id: p.policy.id, updated_at: p.policy.updated_at, })), - packages: preconfiguredPackages.map((pkg) => `${pkg.name}:${pkg.version}`), + packages: preconfiguredPackages.map((pkg) => pkgToPkgKey(pkg)), }; } @@ -160,13 +175,15 @@ async function ensureInstalledPreconfiguredPackage( soClient: SavedObjectsClientContract, esClient: ElasticsearchClient, pkgName: string, - pkgVersion: string + pkgVersion: string, + force?: boolean ) { return ensureInstalledPackage({ savedObjectsClient: soClient, pkgName, esClient, pkgVersion, + force, }); } diff --git a/x-pack/plugins/fleet/server/types/models/preconfiguration.ts b/x-pack/plugins/fleet/server/types/models/preconfiguration.ts index 77a28defaf1bd..0dc0ae8f1db88 100644 --- a/x-pack/plugins/fleet/server/types/models/preconfiguration.ts +++ b/x-pack/plugins/fleet/server/types/models/preconfiguration.ts @@ -33,6 +33,7 @@ export const PreconfiguredPackagesSchema = schema.arrayOf( } }, }), + force: schema.maybe(schema.boolean()), }) ); @@ -41,6 +42,8 @@ export const PreconfiguredAgentPoliciesSchema = schema.arrayOf( ...AgentPolicyBaseSchema, namespace: schema.maybe(NamespaceSchema), id: schema.oneOf([schema.string(), schema.number()]), + is_default: schema.maybe(schema.boolean()), + is_default_fleet_server: schema.maybe(schema.boolean()), package_policies: schema.arrayOf( schema.object({ name: schema.string(), diff --git a/x-pack/plugins/telemetry_collection_xpack/server/index.ts b/x-pack/plugins/telemetry_collection_xpack/server/index.ts index aab1bdb58fe59..d924882e17fbd 100644 --- a/x-pack/plugins/telemetry_collection_xpack/server/index.ts +++ b/x-pack/plugins/telemetry_collection_xpack/server/index.ts @@ -7,7 +7,7 @@ import { TelemetryCollectionXpackPlugin } from './plugin'; -export type { ESLicense } from './telemetry_collection'; +export { ESLicense } from './telemetry_collection'; // This exports static code and TypeScript types, // as well as, Kibana Platform `plugin()` initializer. diff --git a/x-pack/plugins/telemetry_collection_xpack/server/telemetry_collection/index.ts b/x-pack/plugins/telemetry_collection_xpack/server/telemetry_collection/index.ts index c1a11caf44f24..4599b068b9b38 100644 --- a/x-pack/plugins/telemetry_collection_xpack/server/telemetry_collection/index.ts +++ b/x-pack/plugins/telemetry_collection_xpack/server/telemetry_collection/index.ts @@ -5,5 +5,5 @@ * 2.0. */ -export type { ESLicense } from './get_license'; +export { ESLicense } from './get_license'; export { getStatsWithXpack } from './get_stats_with_xpack'; diff --git a/x-pack/plugins/telemetry_collection_xpack/tsconfig.json b/x-pack/plugins/telemetry_collection_xpack/tsconfig.json index 1221200c7548c..476f5926f757a 100644 --- a/x-pack/plugins/telemetry_collection_xpack/tsconfig.json +++ b/x-pack/plugins/telemetry_collection_xpack/tsconfig.json @@ -5,8 +5,7 @@ "outDir": "./target/types", "emitDeclarationOnly": true, "declaration": true, - "declarationMap": true, - "isolatedModules": true + "declarationMap": true }, "include": [ "common/**/*", diff --git a/yarn.lock b/yarn.lock index 0390c2f7cdaf8..6b977be1797ec 100644 --- a/yarn.lock +++ b/yarn.lock @@ -9858,15 +9858,7 @@ color-name@^1.0.0, color-name@~1.1.4: resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.4.tgz#c2a09a87acbde69543de6f63fa3995c826c536a2" integrity sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA== -color-string@^1.4.0, color-string@^1.5.2: - version "1.5.3" - resolved "https://registry.yarnpkg.com/color-string/-/color-string-1.5.3.tgz#c9bbc5f01b58b5492f3d6857459cb6590ce204cc" - integrity sha512-dC2C5qeWoYkxki5UAXapdjqO672AM4vZuPGRQfO8b5HKuKGBbKWpITyDYN7TOFKvRW7kOgAn3746clDBMDJyQw== - dependencies: - color-name "^1.0.0" - simple-swizzle "^0.2.2" - -color-string@^1.5.4: +color-string@^1.4.0, color-string@^1.5.2, color-string@^1.5.4: version "1.5.5" resolved "https://registry.yarnpkg.com/color-string/-/color-string-1.5.5.tgz#65474a8f0e7439625f3d27a6a19d89fc45223014" integrity sha512-jgIoum0OfQfq9Whcfc2z/VhCNcmQjWbey6qBX0vqt7YICflUmBCh9E9CiQD5GSJ+Uehixm3NUwHVhqUAWRivZg==