diff --git a/src/plugins/telemetry/schema/oss_plugins.json b/src/plugins/telemetry/schema/oss_plugins.json index a5172c01b1dad..49e431324a49e 100644 --- a/src/plugins/telemetry/schema/oss_plugins.json +++ b/src/plugins/telemetry/schema/oss_plugins.json @@ -13,6 +13,19 @@ } } }, + "search": { + "properties": { + "successCount": { + "type": "number" + }, + "errorCount": { + "type": "number" + }, + "averageDuration": { + "type": "long" + } + } + }, "sample-data": { "properties": { "installed": { diff --git a/x-pack/plugins/discover_enhanced/common/config.ts b/x-pack/plugins/discover_enhanced/common/config.ts new file mode 100644 index 0000000000000..1ee329ea8d115 --- /dev/null +++ b/x-pack/plugins/discover_enhanced/common/config.ts @@ -0,0 +1,9 @@ +/* + * 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. + */ + +export interface Config { + actions: { exploreDataInChart: { enabled: boolean } }; +} diff --git a/x-pack/plugins/discover_enhanced/common/index.ts b/x-pack/plugins/discover_enhanced/common/index.ts new file mode 100644 index 0000000000000..876fca26dc6f4 --- /dev/null +++ b/x-pack/plugins/discover_enhanced/common/index.ts @@ -0,0 +1,7 @@ +/* + * 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. + */ + +export * from './config'; diff --git a/x-pack/plugins/discover_enhanced/kibana.json b/x-pack/plugins/discover_enhanced/kibana.json index 531a84cd4c0e0..da95a0f21a020 100644 --- a/x-pack/plugins/discover_enhanced/kibana.json +++ b/x-pack/plugins/discover_enhanced/kibana.json @@ -5,7 +5,7 @@ "server": true, "ui": true, "requiredPlugins": ["uiActions", "embeddable", "discover"], - "optionalPlugins": ["share", "kibanaLegacy"], + "optionalPlugins": ["share", "kibanaLegacy", "usageCollection"], "configPath": ["xpack", "discoverEnhanced"], "requiredBundles": ["kibanaUtils", "data"] } diff --git a/x-pack/plugins/discover_enhanced/public/plugin.ts b/x-pack/plugins/discover_enhanced/public/plugin.ts index 9e66925132a7d..f1273ab00bdd4 100644 --- a/x-pack/plugins/discover_enhanced/public/plugin.ts +++ b/x-pack/plugins/discover_enhanced/public/plugin.ts @@ -28,6 +28,7 @@ import { ACTION_EXPLORE_DATA_CHART, ExploreDataChartActionContext, } from './actions'; +import { Config } from '../common'; declare module '../../../../src/plugins/ui_actions/public' { export interface ActionContextMapping { @@ -55,10 +56,10 @@ export interface DiscoverEnhancedStartDependencies { export class DiscoverEnhancedPlugin implements Plugin { - public readonly config: { actions: { exploreDataInChart: { enabled: boolean } } }; + public readonly config: Config; constructor(protected readonly context: PluginInitializerContext) { - this.config = context.config.get(); + this.config = context.config.get(); } setup( diff --git a/x-pack/plugins/discover_enhanced/server/index.ts b/x-pack/plugins/discover_enhanced/server/index.ts index e361b9fb075ed..461a2616efdb3 100644 --- a/x-pack/plugins/discover_enhanced/server/index.ts +++ b/x-pack/plugins/discover_enhanced/server/index.ts @@ -4,9 +4,9 @@ * you may not use this file except in compliance with the Elastic License. */ +import { PluginInitializerContext } from '../../../../src/core/server'; +import { DiscoverEnhancedPlugin } from './plugin'; + export { config } from './config'; -export const plugin = () => ({ - setup() {}, - start() {}, -}); +export const plugin = (context: PluginInitializerContext) => new DiscoverEnhancedPlugin(context); diff --git a/x-pack/plugins/discover_enhanced/server/plugin.ts b/x-pack/plugins/discover_enhanced/server/plugin.ts new file mode 100644 index 0000000000000..9d80a6dc7dcd1 --- /dev/null +++ b/x-pack/plugins/discover_enhanced/server/plugin.ts @@ -0,0 +1,58 @@ +/* + * 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 { Observable } from 'rxjs'; +import { take } from 'rxjs/operators'; +import { + CoreSetup, + CoreStart, + Plugin, + PluginInitializerContext, +} from '../../../../src/core/server'; +import { UsageCollectionSetup } from '../../../../src/plugins/usage_collection/server'; +import { Config } from '../common'; + +interface SetupDependencies { + usageCollection?: UsageCollectionSetup; +} + +interface StartDependencies { + usageCollection?: unknown; +} + +export class DiscoverEnhancedPlugin + implements Plugin { + private config$: Observable; + + constructor(protected readonly context: PluginInitializerContext) { + this.config$ = context.config.create(); + } + + public setup(core: CoreSetup, { usageCollection }: SetupDependencies) { + if (!!usageCollection) { + const collector = usageCollection.makeUsageCollector<{ + exploreDataInChartActionEnabled: boolean; + }>({ + type: 'discoverEnhanced', + schema: { + exploreDataInChartActionEnabled: { + type: 'boolean', + }, + }, + isReady: () => true, + fetch: async () => { + const config = await this.config$.pipe(take(1)).toPromise(); + return { + exploreDataInChartActionEnabled: config.actions.exploreDataInChart.enabled, + }; + }, + }); + usageCollection.registerCollector(collector); + } + } + + public start(core: CoreStart) {} +} diff --git a/x-pack/plugins/telemetry_collection_xpack/schema/xpack_plugins.json b/x-pack/plugins/telemetry_collection_xpack/schema/xpack_plugins.json index fd21b70660bb6..5280f094e3a5d 100644 --- a/x-pack/plugins/telemetry_collection_xpack/schema/xpack_plugins.json +++ b/x-pack/plugins/telemetry_collection_xpack/schema/xpack_plugins.json @@ -7,6 +7,13 @@ } } }, + "discoverEnhanced": { + "properties": { + "exploreDataInChartActionEnabled": { + "type": "boolean" + } + } + }, "app_search": { "properties": { "ui_viewed": {