diff --git a/x-pack/index.js b/x-pack/index.js index cfadddac3994a..3dc539f3b4348 100644 --- a/x-pack/index.js +++ b/x-pack/index.js @@ -14,7 +14,6 @@ import { apm } from './legacy/plugins/apm'; import { maps } from './legacy/plugins/maps'; import { spaces } from './legacy/plugins/spaces'; import { canvas } from './legacy/plugins/canvas'; -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'; @@ -31,7 +30,6 @@ module.exports = function(kibana) { apm(kibana), maps(kibana), canvas(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..085119fc9faad 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: 'agnostic', + 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 6eb08eabc15b5..ac67496de51ba 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: 'agnostic', + 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/alerting/metric_threshold/metric_threshold_executor.ts b/x-pack/plugins/infra/server/lib/alerting/metric_threshold/metric_threshold_executor.ts index cf691f73bdc2c..e1c66b674f72d 100644 --- a/x-pack/plugins/infra/server/lib/alerting/metric_threshold/metric_threshold_executor.ts +++ b/x-pack/plugins/infra/server/lib/alerting/metric_threshold/metric_threshold_executor.ts @@ -6,7 +6,7 @@ import { mapValues } from 'lodash'; import { i18n } from '@kbn/i18n'; import { convertSavedObjectToSavedSourceConfiguration } from '../../sources/sources'; -import { infraSourceConfigurationSavedObjectType } from '../../sources/saved_object_mappings'; +import { infraSourceConfigurationSavedObjectName } from '../../sources/saved_object_type'; import { InfraDatabaseSearchResponse } from '../../adapters/framework/adapter_types'; import { createAfterKeyHandler } from '../../../utils/create_afterkey_handler'; import { getAllCompositeData } from '../../../utils/get_all_composite_data'; @@ -180,7 +180,7 @@ const getIndexPattern: ( ) => Promise = async function({ savedObjectsClient }, sourceId = 'default') { try { const sourceConfiguration = await savedObjectsClient.get( - infraSourceConfigurationSavedObjectType, + infraSourceConfigurationSavedObjectName, sourceId ); const { metricAlias } = convertSavedObjectToSavedSourceConfiguration( 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..d52f8336bc8ca 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: 'agnostic', + 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 0368c7bfd6db8..8860bdb1c7a51 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 { RequestHandlerContext, 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, @@ -107,7 +107,7 @@ export class InfraSources { const createdSourceConfiguration = convertSavedObjectToSavedSourceConfiguration( await requestContext.core.savedObjects.client.create( - infraSourceConfigurationSavedObjectType, + infraSourceConfigurationSavedObjectName, pickSavedSourceConfiguration(newSourceConfiguration) as any, { id: sourceId } ) @@ -124,7 +124,7 @@ export class InfraSources { public async deleteSourceConfiguration(requestContext: RequestHandlerContext, sourceId: string) { await requestContext.core.savedObjects.client.delete( - infraSourceConfigurationSavedObjectType, + infraSourceConfigurationSavedObjectName, sourceId ); } @@ -148,7 +148,7 @@ export class InfraSources { const updatedSourceConfiguration = convertSavedObjectToSavedSourceConfiguration( await requestContext.core.savedObjects.client.update( - infraSourceConfigurationSavedObjectType, + infraSourceConfigurationSavedObjectName, sourceId, pickSavedSourceConfiguration(updatedSourceConfigurationAttributes) as any, { @@ -206,7 +206,7 @@ export class InfraSources { sourceId: string ) { const savedObject = await savedObjectsClient.get( - infraSourceConfigurationSavedObjectType, + infraSourceConfigurationSavedObjectName, sourceId ); @@ -215,7 +215,7 @@ export class InfraSources { private async getAllSavedSourceConfigurations(requestContext: RequestHandlerContext) { const savedObjects = await requestContext.core.savedObjects.client.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 d4dfa60ac67a0..59d1381183cf3 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({ @@ -113,6 +116,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, -};