diff --git a/x-pack/index.js b/x-pack/index.js index ab29aaa2a10a2..99b63a49f5793 100644 --- a/x-pack/index.js +++ b/x-pack/index.js @@ -12,7 +12,6 @@ import { dashboardMode } from './legacy/plugins/dashboard_mode'; import { beats } from './legacy/plugins/beats_management'; import { maps } from './legacy/plugins/maps'; import { spaces } from './legacy/plugins/spaces'; -import { infra } from './legacy/plugins/infra'; import { taskManager } from './legacy/plugins/task_manager'; import { encryptedSavedObjects } from './legacy/plugins/encrypted_saved_objects'; import { ingestManager } from './legacy/plugins/ingest_manager'; @@ -27,7 +26,6 @@ module.exports = function(kibana) { dashboardMode(kibana), beats(kibana), maps(kibana), - infra(kibana), taskManager(kibana), encryptedSavedObjects(kibana), ingestManager(kibana), diff --git a/x-pack/legacy/plugins/infra/index.ts b/x-pack/legacy/plugins/infra/index.ts deleted file mode 100644 index 6ef273924a346..0000000000000 --- a/x-pack/legacy/plugins/infra/index.ts +++ /dev/null @@ -1,25 +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; - * you may not use this file except in compliance with the Elastic License. - */ -import { Root } from 'joi'; -import { savedObjectMappings } from '../../../plugins/infra/server'; - -export function infra(kibana: any) { - return new kibana.Plugin({ - id: 'infra', - configPrefix: 'xpack.infra', - require: ['kibana', 'elasticsearch'], - uiExports: { - mappings: savedObjectMappings, - }, - config(Joi: Root) { - return Joi.object({ - enabled: Joi.boolean().default(true), - }) - .unknown() - .default(); - }, - }); -} diff --git a/x-pack/plugins/infra/common/saved_objects/inventory_view.ts b/x-pack/plugins/infra/common/saved_objects/inventory_view.ts index 8933de57b0448..c14b75efc6887 100644 --- a/x-pack/plugins/infra/common/saved_objects/inventory_view.ts +++ b/x-pack/plugins/infra/common/saved_objects/inventory_view.ts @@ -5,18 +5,18 @@ */ // eslint-disable-next-line @kbn/eslint/no-restricted-paths -import { ElasticsearchMappingOf } from '../../server/utils/typed_elasticsearch_mappings'; -// eslint-disable-next-line @kbn/eslint/no-restricted-paths -import { WaffleViewState } from '../../public/pages/metrics/inventory_view/hooks/use_waffle_view_state'; +import { SavedObjectsType } from 'src/core/server'; -export const inventoryViewSavedObjectType = 'inventory-view'; -// eslint-disable-next-line @kbn/eslint/no-restricted-paths -import { SavedViewSavedObject } from '../../public/hooks/use_saved_view'; +export const inventoryViewSavedObjectName = 'inventory-view'; -export const inventoryViewSavedObjectMappings: { - [inventoryViewSavedObjectType]: ElasticsearchMappingOf>; -} = { - [inventoryViewSavedObjectType]: { +export const inventoryViewSavedObjectType: SavedObjectsType = { + name: inventoryViewSavedObjectName, + hidden: false, + namespaceType: 'single', + management: { + importableAndExportable: true, + }, + mappings: { properties: { name: { type: 'keyword', diff --git a/x-pack/plugins/infra/common/saved_objects/metrics_explorer_view.ts b/x-pack/plugins/infra/common/saved_objects/metrics_explorer_view.ts index add6ab0f132b5..88bbc945e32dc 100644 --- a/x-pack/plugins/infra/common/saved_objects/metrics_explorer_view.ts +++ b/x-pack/plugins/infra/common/saved_objects/metrics_explorer_view.ts @@ -5,30 +5,18 @@ */ // eslint-disable-next-line @kbn/eslint/no-restricted-paths -import { ElasticsearchMappingOf } from '../../server/utils/typed_elasticsearch_mappings'; -import { - MetricsExplorerOptions, - MetricsExplorerChartOptions, - MetricsExplorerTimeOptions, - // eslint-disable-next-line @kbn/eslint/no-restricted-paths -} from '../../public/pages/metrics/metrics_explorer/hooks/use_metrics_explorer_options'; -// eslint-disable-next-line @kbn/eslint/no-restricted-paths -import { SavedViewSavedObject } from '../../public/hooks/use_saved_view'; - -interface MetricsExplorerSavedView { - options: MetricsExplorerOptions; - chartOptions: MetricsExplorerChartOptions; - currentTimerange: MetricsExplorerTimeOptions; -} +import { SavedObjectsType } from 'src/core/server'; -export const metricsExplorerViewSavedObjectType = 'metrics-explorer-view'; +export const metricsExplorerViewSavedObjectName = 'metrics-explorer-view'; -export const metricsExplorerViewSavedObjectMappings: { - [metricsExplorerViewSavedObjectType]: ElasticsearchMappingOf< - SavedViewSavedObject - >; -} = { - [metricsExplorerViewSavedObjectType]: { +export const metricsExplorerViewSavedObjectType: SavedObjectsType = { + name: metricsExplorerViewSavedObjectName, + hidden: false, + namespaceType: 'single', + management: { + importableAndExportable: true, + }, + mappings: { properties: { name: { type: 'keyword', diff --git a/x-pack/plugins/infra/public/pages/metrics/inventory_view/components/saved_views.tsx b/x-pack/plugins/infra/public/pages/metrics/inventory_view/components/saved_views.tsx index 356f0598e00d2..96271ea126046 100644 --- a/x-pack/plugins/infra/public/pages/metrics/inventory_view/components/saved_views.tsx +++ b/x-pack/plugins/infra/public/pages/metrics/inventory_view/components/saved_views.tsx @@ -5,7 +5,7 @@ */ import React from 'react'; import { SavedViewsToolbarControls } from '../../../../components/saved_views/toolbar_control'; -import { inventoryViewSavedObjectType } from '../../../../../common/saved_objects/inventory_view'; +import { inventoryViewSavedObjectName } from '../../../../../common/saved_objects/inventory_view'; import { useWaffleViewState } from '../hooks/use_waffle_view_state'; export const SavedViews = () => { @@ -15,7 +15,7 @@ export const SavedViews = () => { defaultViewState={defaultViewState} viewState={viewState} onViewChange={onViewChange} - viewType={inventoryViewSavedObjectType} + viewType={inventoryViewSavedObjectName} /> ); }; diff --git a/x-pack/plugins/infra/public/pages/metrics/metrics_explorer/components/toolbar.tsx b/x-pack/plugins/infra/public/pages/metrics/metrics_explorer/components/toolbar.tsx index 6913f67bad08a..76945eb528345 100644 --- a/x-pack/plugins/infra/public/pages/metrics/metrics_explorer/components/toolbar.tsx +++ b/x-pack/plugins/infra/public/pages/metrics/metrics_explorer/components/toolbar.tsx @@ -24,7 +24,7 @@ import { MetricsExplorerAggregationPicker } from './aggregation'; import { MetricsExplorerChartOptions as MetricsExplorerChartOptionsComponent } from './chart_options'; import { SavedViewsToolbarControls } from '../../../../components/saved_views/toolbar_control'; import { MetricExplorerViewState } from '../hooks/use_metric_explorer_state'; -import { metricsExplorerViewSavedObjectType } from '../../../../../common/saved_objects/metrics_explorer_view'; +import { metricsExplorerViewSavedObjectName } from '../../../../../common/saved_objects/metrics_explorer_view'; import { useKibanaUiSetting } from '../../../../utils/use_kibana_ui_setting'; import { mapKibanaQuickRangesToDatePickerRanges } from '../../../../utils/map_timepicker_quickranges_to_datepicker_ranges'; import { ToolbarPanel } from '../../../../components/toolbar_panel'; @@ -129,7 +129,7 @@ export const MetricsExplorerToolbar = ({ chartOptions, currentTimerange: timeRange, }} - viewType={metricsExplorerViewSavedObjectType} + viewType={metricsExplorerViewSavedObjectName} onViewChange={onViewStateChange} /> diff --git a/x-pack/plugins/infra/server/index.ts b/x-pack/plugins/infra/server/index.ts index 6cb04897af3f5..f0d417c5c311a 100644 --- a/x-pack/plugins/infra/server/index.ts +++ b/x-pack/plugins/infra/server/index.ts @@ -6,9 +6,8 @@ import { PluginInitializerContext } from 'src/core/server'; import { config, InfraConfig, InfraServerPlugin, InfraPluginSetup } from './plugin'; -import { savedObjectMappings } from './saved_objects'; -export { config, InfraConfig, savedObjectMappings, InfraPluginSetup }; +export { config, InfraConfig, InfraPluginSetup }; export function plugin(context: PluginInitializerContext) { return new InfraServerPlugin(context); diff --git a/x-pack/plugins/infra/server/lib/sources/index.ts b/x-pack/plugins/infra/server/lib/sources/index.ts index 9dcbe02bd064b..45348e1bfc6d8 100644 --- a/x-pack/plugins/infra/server/lib/sources/index.ts +++ b/x-pack/plugins/infra/server/lib/sources/index.ts @@ -5,6 +5,6 @@ */ export * from './defaults'; -export * from './saved_object_mappings'; +export { infraSourceConfigurationSavedObjectType } from './saved_object_type'; export * from './sources'; export * from '../../../common/http_api/source_api'; diff --git a/x-pack/plugins/infra/server/lib/sources/saved_object_mappings.ts b/x-pack/plugins/infra/server/lib/sources/saved_object_type.ts similarity index 76% rename from x-pack/plugins/infra/server/lib/sources/saved_object_mappings.ts rename to x-pack/plugins/infra/server/lib/sources/saved_object_type.ts index e5b230373b7ec..49780fc249d1f 100644 --- a/x-pack/plugins/infra/server/lib/sources/saved_object_mappings.ts +++ b/x-pack/plugins/infra/server/lib/sources/saved_object_type.ts @@ -4,15 +4,19 @@ * you may not use this file except in compliance with the Elastic License. */ -import { ElasticsearchMappingOf } from '../../utils/typed_elasticsearch_mappings'; -import { InfraSavedSourceConfiguration } from '../../../common/http_api/source_api'; +// eslint-disable-next-line @kbn/eslint/no-restricted-paths +import { SavedObjectsType } from 'src/core/server'; -export const infraSourceConfigurationSavedObjectType = 'infrastructure-ui-source'; +export const infraSourceConfigurationSavedObjectName = 'infrastructure-ui-source'; -export const infraSourceConfigurationSavedObjectMappings: { - [infraSourceConfigurationSavedObjectType]: ElasticsearchMappingOf; -} = { - [infraSourceConfigurationSavedObjectType]: { +export const infraSourceConfigurationSavedObjectType: SavedObjectsType = { + name: infraSourceConfigurationSavedObjectName, + hidden: false, + namespaceType: 'single', + management: { + importableAndExportable: true, + }, + mappings: { properties: { name: { type: 'text', diff --git a/x-pack/plugins/infra/server/lib/sources/sources.ts b/x-pack/plugins/infra/server/lib/sources/sources.ts index 71682c9e798a6..50f725cc6e099 100644 --- a/x-pack/plugins/infra/server/lib/sources/sources.ts +++ b/x-pack/plugins/infra/server/lib/sources/sources.ts @@ -12,7 +12,7 @@ import { map, fold } from 'fp-ts/lib/Either'; import { SavedObjectsClientContract } from 'src/core/server'; import { defaultSourceConfiguration } from './defaults'; import { NotFoundError } from './errors'; -import { infraSourceConfigurationSavedObjectType } from './saved_object_mappings'; +import { infraSourceConfigurationSavedObjectName } from './saved_object_type'; import { InfraSavedSourceConfiguration, InfraSourceConfiguration, @@ -108,7 +108,7 @@ export class InfraSources { const createdSourceConfiguration = convertSavedObjectToSavedSourceConfiguration( await savedObjectsClient.create( - infraSourceConfigurationSavedObjectType, + infraSourceConfigurationSavedObjectName, pickSavedSourceConfiguration(newSourceConfiguration) as any, { id: sourceId } ) @@ -127,7 +127,7 @@ export class InfraSources { savedObjectsClient: SavedObjectsClientContract, sourceId: string ) { - await savedObjectsClient.delete(infraSourceConfigurationSavedObjectType, sourceId); + await savedObjectsClient.delete(infraSourceConfigurationSavedObjectName, sourceId); } public async updateSourceConfiguration( @@ -149,7 +149,7 @@ export class InfraSources { const updatedSourceConfiguration = convertSavedObjectToSavedSourceConfiguration( await savedObjectsClient.update( - infraSourceConfigurationSavedObjectType, + infraSourceConfigurationSavedObjectName, sourceId, pickSavedSourceConfiguration(updatedSourceConfigurationAttributes) as any, { @@ -207,7 +207,7 @@ export class InfraSources { sourceId: string ) { const savedObject = await savedObjectsClient.get( - infraSourceConfigurationSavedObjectType, + infraSourceConfigurationSavedObjectName, sourceId ); @@ -216,7 +216,7 @@ export class InfraSources { private async getAllSavedSourceConfigurations(savedObjectsClient: SavedObjectsClientContract) { const savedObjects = await savedObjectsClient.find({ - type: infraSourceConfigurationSavedObjectType, + type: infraSourceConfigurationSavedObjectName, }); return savedObjects.saved_objects.map(convertSavedObjectToSavedSourceConfiguration); diff --git a/x-pack/plugins/infra/server/plugin.ts b/x-pack/plugins/infra/server/plugin.ts index 13446594ab114..496c2b32373a8 100644 --- a/x-pack/plugins/infra/server/plugin.ts +++ b/x-pack/plugins/infra/server/plugin.ts @@ -28,6 +28,9 @@ import { METRICS_FEATURE, LOGS_FEATURE } from './features'; import { UsageCollector } from './usage/usage_collector'; import { InfraStaticSourceConfiguration } from '../common/http_api/source_api'; import { registerAlertTypes } from './lib/alerting'; +import { infraSourceConfigurationSavedObjectType } from './lib/sources'; +import { metricsExplorerViewSavedObjectType } from '../common/saved_objects/metrics_explorer_view'; +import { inventoryViewSavedObjectType } from '../common/saved_objects/inventory_view'; export const config = { schema: schema.object({ @@ -85,13 +88,6 @@ export class InfraServerPlugin { this.config$ = context.config.create(); } - getLibs() { - if (!this.libs) { - throw new Error('libs not set up yet'); - } - return this.libs; - } - async setup(core: CoreSetup, plugins: InfraServerPluginDeps) { await new Promise(resolve => { this.config$.subscribe(configValue => { @@ -113,6 +109,11 @@ export class InfraServerPlugin { const logEntryCategoriesAnalysis = new LogEntryCategoriesAnalysis({ framework }); const logEntryRateAnalysis = new LogEntryRateAnalysis({ framework }); + // register saved object types + core.savedObjects.registerType(infraSourceConfigurationSavedObjectType); + core.savedObjects.registerType(metricsExplorerViewSavedObjectType); + core.savedObjects.registerType(inventoryViewSavedObjectType); + // TODO: separate these out individually and do away with "domains" as a temporary group const domainLibs: InfraDomainLibs = { fields: new InfraFieldsDomain(new FrameworkFieldsAdapter(framework), { diff --git a/x-pack/plugins/infra/server/saved_objects.ts b/x-pack/plugins/infra/server/saved_objects.ts deleted file mode 100644 index 2e554300b0ecb..0000000000000 --- a/x-pack/plugins/infra/server/saved_objects.ts +++ /dev/null @@ -1,15 +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; - * you may not use this file except in compliance with the Elastic License. - */ - -import { infraSourceConfigurationSavedObjectMappings } from './lib/sources'; -import { metricsExplorerViewSavedObjectMappings } from '../common/saved_objects/metrics_explorer_view'; -import { inventoryViewSavedObjectMappings } from '../common/saved_objects/inventory_view'; - -export const savedObjectMappings = { - ...infraSourceConfigurationSavedObjectMappings, - ...metricsExplorerViewSavedObjectMappings, - ...inventoryViewSavedObjectMappings, -};