diff --git a/docs/developer/plugin-list.asciidoc b/docs/developer/plugin-list.asciidoc index 477ef07db23a5..541887f04d016 100644 --- a/docs/developer/plugin-list.asciidoc +++ b/docs/developer/plugin-list.asciidoc @@ -536,6 +536,10 @@ Plugin server-side only. Plugin has three main functions: |In order to make ongoing maintenance of log collection easy we want to introduce the concept of data set quality, where users can easily get an overview on the data sets they have with information such as integration, size, last activity, among others. +|{kib-repo}blob/{branch}/x-pack/plugins/data_usage/README.md[dataUsage] +|Serverless only plugin for users to view data usage + + |{kib-repo}blob/{branch}/x-pack/plugins/data_visualizer/README.md[dataVisualizer] |The data_visualizer plugin enables you to explore the fields in your data. diff --git a/package.json b/package.json index e2bcbc9fd7760..4d8274aa36d7e 100644 --- a/package.json +++ b/package.json @@ -421,6 +421,7 @@ "@kbn/data-search-plugin": "link:test/plugin_functional/plugins/data_search", "@kbn/data-service": "link:packages/kbn-data-service", "@kbn/data-stream-adapter": "link:packages/kbn-data-stream-adapter", + "@kbn/data-usage-plugin": "link:x-pack/plugins/data_usage", "@kbn/data-view-editor-plugin": "link:src/plugins/data_view_editor", "@kbn/data-view-field-editor-example-plugin": "link:examples/data_view_field_editor_example", "@kbn/data-view-field-editor-plugin": "link:src/plugins/data_view_field_editor", diff --git a/packages/kbn-management/cards_navigation/src/consts.tsx b/packages/kbn-management/cards_navigation/src/consts.tsx index 73bc2638c4e98..16e655c5510ad 100644 --- a/packages/kbn-management/cards_navigation/src/consts.tsx +++ b/packages/kbn-management/cards_navigation/src/consts.tsx @@ -72,6 +72,14 @@ export const appDefinitions: Record = { icon: 'documents', }, + [AppIds.DATA_USAGE]: { + category: appCategories.DATA, + description: i18n.translate('management.landing.withCardNavigation.dataUsageDescription', { + defaultMessage: 'View data usage and retention.', + }), + icon: 'documents', + }, + [AppIds.RULES]: { category: appCategories.ALERTS, description: i18n.translate('management.landing.withCardNavigation.rulesDescription', { diff --git a/packages/kbn-management/cards_navigation/src/types.ts b/packages/kbn-management/cards_navigation/src/types.ts index e53aadabc9eaa..5c14bc0755f1c 100644 --- a/packages/kbn-management/cards_navigation/src/types.ts +++ b/packages/kbn-management/cards_navigation/src/types.ts @@ -31,6 +31,7 @@ export enum AppIds { API_KEYS = 'api_keys', DATA_QUALITY = 'data_quality', SPACES = 'spaces', + DATA_USAGE = 'data_usage', } // Create new type that is a union of all the appId values diff --git a/packages/kbn-optimizer/limits.yml b/packages/kbn-optimizer/limits.yml index 116a087af89f6..da5ba0500eeb9 100644 --- a/packages/kbn-optimizer/limits.yml +++ b/packages/kbn-optimizer/limits.yml @@ -29,6 +29,7 @@ pageLoadAssetSize: data: 454087 dataQuality: 19384 datasetQuality: 52000 + dataUsage: 30000 dataViewEditor: 28082 dataViewFieldEditor: 42021 dataViewManagement: 5300 diff --git a/tsconfig.base.json b/tsconfig.base.json index 4b290135f106f..f5b2b4bbfea1f 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -702,6 +702,8 @@ "@kbn/data-service/*": ["packages/kbn-data-service/*"], "@kbn/data-stream-adapter": ["packages/kbn-data-stream-adapter"], "@kbn/data-stream-adapter/*": ["packages/kbn-data-stream-adapter/*"], + "@kbn/data-usage-plugin": ["x-pack/plugins/data_usage"], + "@kbn/data-usage-plugin/*": ["x-pack/plugins/data_usage/*"], "@kbn/data-view-editor-plugin": ["src/plugins/data_view_editor"], "@kbn/data-view-editor-plugin/*": ["src/plugins/data_view_editor/*"], "@kbn/data-view-field-editor-example-plugin": ["examples/data_view_field_editor_example"], diff --git a/x-pack/.i18nrc.json b/x-pack/.i18nrc.json index a36cc693a6b71..8082fa6f8ede2 100644 --- a/x-pack/.i18nrc.json +++ b/x-pack/.i18nrc.json @@ -31,6 +31,7 @@ "xpack.dashboard": "plugins/dashboard_enhanced", "xpack.dataQuality": "plugins/data_quality", "xpack.datasetQuality": "plugins/observability_solution/dataset_quality", + "xpack.dataUsage": "plugins/data_usage", "xpack.discover": "plugins/discover_enhanced", "xpack.crossClusterReplication": "plugins/cross_cluster_replication", "xpack.elasticAssistant": "packages/kbn-elastic-assistant", diff --git a/x-pack/plugins/data_usage/README.md b/x-pack/plugins/data_usage/README.md new file mode 100755 index 0000000000000..7c0056ff5780d --- /dev/null +++ b/x-pack/plugins/data_usage/README.md @@ -0,0 +1,3 @@ +# dataUsage +Serverless only plugin for users to view data usage + diff --git a/x-pack/plugins/data_usage/common/index.ts b/x-pack/plugins/data_usage/common/index.ts new file mode 100644 index 0000000000000..4b6f899b58d37 --- /dev/null +++ b/x-pack/plugins/data_usage/common/index.ts @@ -0,0 +1,13 @@ +/* + * 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 { i18n } from '@kbn/i18n'; + +export const PLUGIN_ID = 'data_usage'; +export const PLUGIN_NAME = i18n.translate('xpack.dataUsage.name', { + defaultMessage: 'Data Usage', +}); diff --git a/x-pack/plugins/data_usage/jest.config.js b/x-pack/plugins/data_usage/jest.config.js new file mode 100644 index 0000000000000..f73ddf7ec31ee --- /dev/null +++ b/x-pack/plugins/data_usage/jest.config.js @@ -0,0 +1,15 @@ +/* + * 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. + */ + +module.exports = { + preset: '@kbn/test', + rootDir: '../../..', + roots: ['/x-pack/plugins/data_usage'], + coverageDirectory: '/target/kibana-coverage/jest/x-pack/plugins/data_usage', + coverageReporters: ['text', 'html'], + collectCoverageFrom: ['/x-pack/plugins/datas_usage/{common,public}/**/*.{ts,tsx}'], +}; diff --git a/x-pack/plugins/data_usage/kibana.jsonc b/x-pack/plugins/data_usage/kibana.jsonc new file mode 100644 index 0000000000000..9b0f2d193925e --- /dev/null +++ b/x-pack/plugins/data_usage/kibana.jsonc @@ -0,0 +1,16 @@ +{ + "type": "plugin", + "id": "@kbn/data-usage-plugin", + "owner": ["@elastic/obs-ai-assistant", "@elastic/security-solution"], + "plugin": { + "id": "dataUsage", + "server": true, + "browser": true, + "configPath": ["xpack", "dataUsage"], + "requiredPlugins": ["home", "management", "features", "share"], + "optionalPlugins": [], + "requiredBundles": [ + "kibanaReact", + ], + } +} diff --git a/x-pack/plugins/data_usage/public/application.tsx b/x-pack/plugins/data_usage/public/application.tsx new file mode 100644 index 0000000000000..1e6c35c4b8f0a --- /dev/null +++ b/x-pack/plugins/data_usage/public/application.tsx @@ -0,0 +1,83 @@ +/* + * 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 { CoreStart } from '@kbn/core/public'; +import { ManagementAppMountParams } from '@kbn/management-plugin/public'; +import React from 'react'; +import ReactDOM from 'react-dom'; +import { KibanaRenderContextProvider } from '@kbn/react-kibana-context-render'; +import { Route, Router, Routes } from '@kbn/shared-ux-router'; +import { useExecutionContext } from '@kbn/kibana-react-plugin/public'; +import { PerformanceContextProvider } from '@kbn/ebt-tools'; +import { useKibanaContextForPluginProvider } from './utils/use_kibana'; +import { DataUsageStartDependencies, DataUsagePublicStart } from './types'; +import { PLUGIN_ID } from '../common'; + +export const renderApp = ( + core: CoreStart, + plugins: DataUsageStartDependencies, + pluginStart: DataUsagePublicStart, + params: ManagementAppMountParams +) => { + ReactDOM.render( + , + params.element + ); + + return () => { + ReactDOM.unmountComponentAtNode(params.element); + }; +}; + +const AppWithExecutionContext = ({ + core, + params, +}: { + core: CoreStart; + params: ManagementAppMountParams; +}) => { + const { executionContext } = core; + + useExecutionContext(executionContext, { + type: 'application', + page: PLUGIN_ID, + }); + + return ( + + + +
Data Usage
} /> +
+
+
+ ); +}; + +interface AppProps { + core: CoreStart; + plugins: DataUsageStartDependencies; + pluginStart: DataUsagePublicStart; + params: ManagementAppMountParams; +} + +const App = ({ core, plugins, pluginStart, params }: AppProps) => { + const KibanaContextProviderForPlugin = useKibanaContextForPluginProvider( + core, + plugins, + pluginStart, + params + ); + + return ( + + + + + + ); +}; diff --git a/x-pack/plugins/data_usage/public/index.ts b/x-pack/plugins/data_usage/public/index.ts new file mode 100644 index 0000000000000..e18b801a6a38f --- /dev/null +++ b/x-pack/plugins/data_usage/public/index.ts @@ -0,0 +1,25 @@ +/* + * 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 { PluginInitializer, PluginInitializerContext } from '@kbn/core/public'; +import type { + DataUsagePublicSetup, + DataUsagePublicStart, + DataUsageSetupDependencies, + DataUsageStartDependencies, + ConfigSchema, +} from './types'; +import { DataUsagePlugin } from './plugin'; + +export type { DataUsagePublicSetup, DataUsagePublicStart } from './types'; + +export const plugin: PluginInitializer< + DataUsagePublicSetup, + DataUsagePublicStart, + DataUsageSetupDependencies, + DataUsageStartDependencies +> = (pluginInitializerContext: PluginInitializerContext) => new DataUsagePlugin(); diff --git a/x-pack/plugins/data_usage/public/plugin.ts b/x-pack/plugins/data_usage/public/plugin.ts new file mode 100644 index 0000000000000..aa3b02c2b671b --- /dev/null +++ b/x-pack/plugins/data_usage/public/plugin.ts @@ -0,0 +1,55 @@ +/* + * 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 { CoreSetup, CoreStart, Plugin } from '@kbn/core/public'; +import { ManagementAppMountParams } from '@kbn/management-plugin/public'; +import { + DataUsagePublicSetup, + DataUsagePublicStart, + DataUsageStartDependencies, + DataUsageSetupDependencies, +} from './types'; +import { PLUGIN_ID, PLUGIN_NAME } from '../common'; + +export class DataUsagePlugin + implements + Plugin< + DataUsagePublicSetup, + DataUsagePublicStart, + DataUsageSetupDependencies, + DataUsageStartDependencies + > +{ + public setup( + core: CoreSetup, + plugins: DataUsageSetupDependencies + ): DataUsagePublicSetup { + const { management } = plugins; + management.sections.section.data.registerApp({ + id: PLUGIN_ID, + title: PLUGIN_NAME, + order: 6, + keywords: ['data usage', 'usage'], + async mount(params: ManagementAppMountParams) { + const [{ renderApp }, [coreStart, pluginsStartDeps, pluginStart]] = await Promise.all([ + import('./application'), + core.getStartServices(), + ]); + + return renderApp(coreStart, pluginsStartDeps, pluginStart, params); + }, + }); + + return {}; + } + + public start(_core: CoreStart): DataUsagePublicStart { + return {}; + } + + public stop() {} +} diff --git a/x-pack/plugins/data_usage/public/types.ts b/x-pack/plugins/data_usage/public/types.ts new file mode 100644 index 0000000000000..e65865dc31821 --- /dev/null +++ b/x-pack/plugins/data_usage/public/types.ts @@ -0,0 +1,27 @@ +/* + * 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 { ManagementSetup, ManagementStart } from '@kbn/management-plugin/public'; +import { SharePluginSetup, SharePluginStart } from '@kbn/share-plugin/public'; + +// eslint-disable-next-line @typescript-eslint/no-empty-interface +export interface DataUsagePublicSetup {} + +// eslint-disable-next-line @typescript-eslint/no-empty-interface +export interface DataUsagePublicStart {} + +export interface DataUsageSetupDependencies { + management: ManagementSetup; + share: SharePluginSetup; +} + +export interface DataUsageStartDependencies { + management: ManagementStart; + share: SharePluginStart; +} +// eslint-disable-next-line @typescript-eslint/no-empty-interface +export interface ConfigSchema {} diff --git a/x-pack/plugins/data_usage/public/utils/use_kibana.tsx b/x-pack/plugins/data_usage/public/utils/use_kibana.tsx new file mode 100644 index 0000000000000..9575a8b8bbd21 --- /dev/null +++ b/x-pack/plugins/data_usage/public/utils/use_kibana.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 { CoreStart } from '@kbn/core/public'; +import { + createKibanaReactContext, + KibanaReactContextValue, + useKibana, +} from '@kbn/kibana-react-plugin/public'; +import { ManagementAppMountParams } from '@kbn/management-plugin/public'; +import { useMemo } from 'react'; +import { DataUsageStartDependencies, DataUsagePublicStart } from '../types'; + +export type PluginKibanaContextValue = CoreStart & + DataUsageStartDependencies & + DataUsagePublicStart & { + appParams: ManagementAppMountParams; + }; + +export const createKibanaContextForPlugin = ( + core: CoreStart, + plugins: DataUsageStartDependencies, + pluginStart: DataUsagePublicStart, + appParams: ManagementAppMountParams +) => { + return createKibanaReactContext({ + ...core, + ...plugins, + ...pluginStart, + appParams, + }); +}; + +export const useKibanaContextForPlugin = + useKibana as () => KibanaReactContextValue; + +export const useKibanaContextForPluginProvider = ( + core: CoreStart, + plugins: DataUsageStartDependencies, + pluginStart: DataUsagePublicStart, + appParams: ManagementAppMountParams +) => { + const { Provider } = useMemo( + () => createKibanaContextForPlugin(core, plugins, pluginStart, appParams), + [appParams, core, pluginStart, plugins] + ); + + return Provider; +}; diff --git a/x-pack/plugins/data_usage/server/config.ts b/x-pack/plugins/data_usage/server/config.ts new file mode 100644 index 0000000000000..6453cce4f4d56 --- /dev/null +++ b/x-pack/plugins/data_usage/server/config.ts @@ -0,0 +1,14 @@ +/* + * 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 { schema, type TypeOf } from '@kbn/config-schema'; + +export const config = schema.object({ + enabled: schema.boolean({ defaultValue: false }), +}); + +export type DataUsageConfig = TypeOf; diff --git a/x-pack/plugins/data_usage/server/index.ts b/x-pack/plugins/data_usage/server/index.ts new file mode 100644 index 0000000000000..3aa49a184d003 --- /dev/null +++ b/x-pack/plugins/data_usage/server/index.ts @@ -0,0 +1,36 @@ +/* + * 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 { + PluginInitializer, + PluginInitializerContext, + PluginConfigDescriptor, +} from '@kbn/core/server'; +import { DataUsageConfig } from './config'; + +import { DataUsagePlugin } from './plugin'; +import type { + DataUsageServerSetup, + DataUsageServerStart, + DataUsageSetupDependencies, + DataUsageStartDependencies, +} from './types'; + +import { config as configSchema } from './config'; + +export type { DataUsageServerSetup, DataUsageServerStart }; + +export const config: PluginConfigDescriptor = { + schema: configSchema, +}; + +export const plugin: PluginInitializer< + DataUsageServerSetup, + DataUsageServerStart, + DataUsageSetupDependencies, + DataUsageStartDependencies +> = async (pluginInitializerContext: PluginInitializerContext) => + await new DataUsagePlugin(pluginInitializerContext); diff --git a/x-pack/plugins/data_usage/server/plugin.ts b/x-pack/plugins/data_usage/server/plugin.ts new file mode 100644 index 0000000000000..8ab49d5104fff --- /dev/null +++ b/x-pack/plugins/data_usage/server/plugin.ts @@ -0,0 +1,40 @@ +/* + * 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 { CoreSetup, CoreStart, Plugin, PluginInitializerContext } from '@kbn/core/server'; +import type { Logger } from '@kbn/logging'; +import { DataUsageConfig } from './config'; +import type { + DataUsageServerSetup, + DataUsageServerStart, + DataUsageSetupDependencies, + DataUsageStartDependencies, +} from './types'; + +export class DataUsagePlugin + implements + Plugin< + DataUsageServerSetup, + DataUsageServerStart, + DataUsageSetupDependencies, + DataUsageStartDependencies + > +{ + logger: Logger; + constructor(context: PluginInitializerContext) { + this.logger = context.logger.get(); + } + setup(coreSetup: CoreSetup, pluginsSetup: DataUsageSetupDependencies): DataUsageServerSetup { + return {}; + } + + start(coreStart: CoreStart, pluginsStart: DataUsageStartDependencies): DataUsageServerStart { + return {}; + } + + public stop() {} +} diff --git a/x-pack/plugins/data_usage/server/types.ts b/x-pack/plugins/data_usage/server/types.ts new file mode 100644 index 0000000000000..9f43ae2d3c298 --- /dev/null +++ b/x-pack/plugins/data_usage/server/types.ts @@ -0,0 +1,16 @@ +/* + * 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. + */ + +/* eslint-disable @typescript-eslint/no-empty-interface*/ + +export interface DataUsageSetupDependencies {} + +export interface DataUsageStartDependencies {} + +export interface DataUsageServerSetup {} + +export interface DataUsageServerStart {} diff --git a/x-pack/plugins/data_usage/tsconfig.json b/x-pack/plugins/data_usage/tsconfig.json new file mode 100644 index 0000000000000..ebc023568cf88 --- /dev/null +++ b/x-pack/plugins/data_usage/tsconfig.json @@ -0,0 +1,26 @@ +{ + "extends": "../../../tsconfig.base.json", + "compilerOptions": { + "outDir": "target/types" + }, + "include": [ + "index.ts", + "common/**/*", + "public/**/*", + "server/**/*", + "../../../typings/**/*" + ], + "kbn_references": [ + "@kbn/core", + "@kbn/i18n", + "@kbn/kibana-react-plugin", + "@kbn/management-plugin", + "@kbn/react-kibana-context-render", + "@kbn/shared-ux-router", + "@kbn/ebt-tools", + "@kbn/share-plugin", + "@kbn/config-schema", + "@kbn/logging", + ], + "exclude": ["target/**/*"] +} diff --git a/yarn.lock b/yarn.lock index ec91f65be0692..c5d22a571d4e6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4675,6 +4675,10 @@ version "0.0.0" uid "" +"@kbn/data-usage-plugin@link:x-pack/plugins/data_usage": + version "0.0.0" + uid "" + "@kbn/data-view-editor-plugin@link:src/plugins/data_view_editor": version "0.0.0" uid ""