From 4d94fa85572595ecadcf915c8d0a0b2714d5f9b6 Mon Sep 17 00:00:00 2001 From: mgiota Date: Wed, 11 May 2022 11:01:28 +0200 Subject: [PATCH 1/7] add application usage to observability --- x-pack/plugins/observability/kibana.json | 3 +- .../public/application/index.tsx | 58 ++++++++++--------- x-pack/plugins/observability/public/plugin.ts | 1 + 3 files changed, 35 insertions(+), 27 deletions(-) diff --git a/x-pack/plugins/observability/kibana.json b/x-pack/plugins/observability/kibana.json index 2ba9572dfd243..6cadc6403ad17 100644 --- a/x-pack/plugins/observability/kibana.json +++ b/x-pack/plugins/observability/kibana.json @@ -41,7 +41,8 @@ "embeddable", "kibanaReact", "kibanaUtils", - "lens" + "lens", + "usageCollection" ], "extraPublicDirs": [ "common" diff --git a/x-pack/plugins/observability/public/application/index.tsx b/x-pack/plugins/observability/public/application/index.tsx index bab6c03b5cf54..3c54f620d5679 100644 --- a/x-pack/plugins/observability/public/application/index.tsx +++ b/x-pack/plugins/observability/public/application/index.tsx @@ -76,35 +76,41 @@ export const renderApp = ({ // ensure all divs are .kbnAppWrappers element.classList.add(APP_WRAPPER_CLASS); + const ApplicationUsageTrackingProvider = + plugins.usageCollection?.components.ApplicationUsageTrackingProvider ?? React.Fragment; ReactDOM.render( - - - + + - - - - - - - - - - - - - - - - , + + + + + + + + + + + + + + + + + + , element ); return () => { diff --git a/x-pack/plugins/observability/public/plugin.ts b/x-pack/plugins/observability/public/plugin.ts index cb8dcaf2dd7e4..d2dc816252e47 100644 --- a/x-pack/plugins/observability/public/plugin.ts +++ b/x-pack/plugins/observability/public/plugin.ts @@ -55,6 +55,7 @@ export interface ObservabilityPublicPluginsSetup { } export interface ObservabilityPublicPluginsStart { + usageCollection: any; cases: CasesUiStart; embeddable: EmbeddableStart; home?: HomePublicPluginStart; From 7da73a7408cea5f5456725972641757d34fdb9e0 Mon Sep 17 00:00:00 2001 From: mgiota Date: Wed, 11 May 2022 11:07:21 +0200 Subject: [PATCH 2/7] wrap Alerts page in a TrackApplicationView component --- x-pack/plugins/observability/public/routes/index.tsx | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/x-pack/plugins/observability/public/routes/index.tsx b/x-pack/plugins/observability/public/routes/index.tsx index 528dbfee06f9d..3f9af7c1f352d 100644 --- a/x-pack/plugins/observability/public/routes/index.tsx +++ b/x-pack/plugins/observability/public/routes/index.tsx @@ -7,6 +7,7 @@ import * as t from 'io-ts'; import React from 'react'; +import { TrackApplicationView } from '@kbn/usage-collection-plugin/public'; import { casesPath } from '../../common'; import { CasesPage } from '../pages/cases'; import { AlertsPage } from '../pages/alerts/containers/alerts_page'; @@ -67,7 +68,16 @@ export const routes = { }, '/alerts': { handler: () => { - return ; + return ( + // TODO define viewIds in a config file + /** + * The prop viewId is used as a unique identifier for your plugin. + * The Application Id is automatically attached to the tracked usage, based on the ID used when registering your app via core.application.register + */ + + + + ); }, params: { // Technically gets a '_a' param by using Kibana URL state sync helpers From 40eb2c47698cf7192b303bcdb525efeefb1ea451 Mon Sep 17 00:00:00 2001 From: mgiota Date: Wed, 11 May 2022 11:18:22 +0200 Subject: [PATCH 3/7] define alerting pages in a config file --- x-pack/plugins/observability/public/config/index.ts | 6 ++++++ x-pack/plugins/observability/public/routes/index.tsx | 8 ++------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/x-pack/plugins/observability/public/config/index.ts b/x-pack/plugins/observability/public/config/index.ts index fc6300acc4716..950e76c1f0a3c 100644 --- a/x-pack/plugins/observability/public/config/index.ts +++ b/x-pack/plugins/observability/public/config/index.ts @@ -7,3 +7,9 @@ export { paths } from './paths'; export { translations } from './translations'; + +export enum AlertingPages { + alerts = 'alerts', + case = 'cases', + rules = 'rules', +} diff --git a/x-pack/plugins/observability/public/routes/index.tsx b/x-pack/plugins/observability/public/routes/index.tsx index 3f9af7c1f352d..b25dca030b0ea 100644 --- a/x-pack/plugins/observability/public/routes/index.tsx +++ b/x-pack/plugins/observability/public/routes/index.tsx @@ -17,6 +17,7 @@ import { OverviewPage } from '../pages/overview'; import { jsonRt } from './json_rt'; import { ObservabilityExploratoryView } from '../components/shared/exploratory_view/obsv_exploratory_view'; import { RulesPage } from '../pages/rules'; +import { AlertingPages } from '../config'; export type RouteParams = DecodeParams; @@ -69,12 +70,7 @@ export const routes = { '/alerts': { handler: () => { return ( - // TODO define viewIds in a config file - /** - * The prop viewId is used as a unique identifier for your plugin. - * The Application Id is automatically attached to the tracked usage, based on the ID used when registering your app via core.application.register - */ - + ); From 31a9e7ead8fe2516ac98727122315d6c1d161c18 Mon Sep 17 00:00:00 2001 From: mgiota Date: Wed, 11 May 2022 16:53:45 +0200 Subject: [PATCH 4/7] add UsageCollectionSetup contract --- x-pack/plugins/observability/public/plugin.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/x-pack/plugins/observability/public/plugin.ts b/x-pack/plugins/observability/public/plugin.ts index d2dc816252e47..0352865549430 100644 --- a/x-pack/plugins/observability/public/plugin.ts +++ b/x-pack/plugins/observability/public/plugin.ts @@ -33,6 +33,7 @@ import { } from '@kbn/triggers-actions-ui-plugin/public'; import { KibanaFeature } from '@kbn/features-plugin/common'; +import { UsageCollectionSetup } from '@kbn/usage-collection-plugin/public'; import { ConfigSchema } from '.'; import { observabilityAppId, observabilityFeatureId, casesPath } from '../common'; import { createLazyObservabilityPageTemplate } from './components/shared'; @@ -55,7 +56,7 @@ export interface ObservabilityPublicPluginsSetup { } export interface ObservabilityPublicPluginsStart { - usageCollection: any; + usageCollection: UsageCollectionSetup; cases: CasesUiStart; embeddable: EmbeddableStart; home?: HomePublicPluginStart; From 98cae48bccc633a244d7de393318e0848b7ba604 Mon Sep 17 00:00:00 2001 From: mgiota Date: Wed, 11 May 2022 22:38:24 +0200 Subject: [PATCH 5/7] pass useCollection in the renderApp --- x-pack/plugins/observability/public/application/index.tsx | 7 +++++-- x-pack/plugins/observability/public/plugin.ts | 2 ++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/x-pack/plugins/observability/public/application/index.tsx b/x-pack/plugins/observability/public/application/index.tsx index 3c54f620d5679..c48a663fefe5b 100644 --- a/x-pack/plugins/observability/public/application/index.tsx +++ b/x-pack/plugins/observability/public/application/index.tsx @@ -18,6 +18,7 @@ import { RedirectAppLinks, } from '@kbn/kibana-react-plugin/public'; import { Storage } from '@kbn/kibana-utils-plugin/public'; +import { UsageCollectionSetup } from '@kbn/usage-collection-plugin/public'; import { ConfigSchema } from '..'; import type { LazyObservabilityPageTemplateProps } from '../components/shared/page_template/lazy_page_template'; import { DatePickerContextProvider } from '../context/date_picker_context'; @@ -54,6 +55,7 @@ export const renderApp = ({ observabilityRuleTypeRegistry, ObservabilityPageTemplate, kibanaFeatures, + usageCollection, }: { config: ConfigSchema; core: CoreStart; @@ -62,6 +64,7 @@ export const renderApp = ({ appMountParameters: AppMountParameters; ObservabilityPageTemplate: React.ComponentType; kibanaFeatures: KibanaFeature[]; + usageCollection: UsageCollectionSetup; }) => { const { element, history, theme$ } = appMountParameters; const i18nCore = core.i18n; @@ -76,9 +79,9 @@ export const renderApp = ({ // ensure all divs are .kbnAppWrappers element.classList.add(APP_WRAPPER_CLASS); - const ApplicationUsageTrackingProvider = - plugins.usageCollection?.components.ApplicationUsageTrackingProvider ?? React.Fragment; + const ApplicationUsageTrackingProvider = + usageCollection?.components.ApplicationUsageTrackingProvider ?? React.Fragment; ReactDOM.render( diff --git a/x-pack/plugins/observability/public/plugin.ts b/x-pack/plugins/observability/public/plugin.ts index 0352865549430..434bce3c576bf 100644 --- a/x-pack/plugins/observability/public/plugin.ts +++ b/x-pack/plugins/observability/public/plugin.ts @@ -53,6 +53,7 @@ export interface ObservabilityPublicPluginsSetup { data: DataPublicPluginSetup; triggersActionsUi: TriggersAndActionsUIPublicPluginSetup; home?: HomePublicPluginSetup; + usageCollection: UsageCollectionSetup; } export interface ObservabilityPublicPluginsStart { @@ -171,6 +172,7 @@ export class Plugin observabilityRuleTypeRegistry, ObservabilityPageTemplate: navigation.PageTemplate, kibanaFeatures, + usageCollection: pluginsSetup.usageCollection, }); }; From 86ea203e850ea19e3182e7f3a2c0e97e4415e342 Mon Sep 17 00:00:00 2001 From: mgiota Date: Thu, 12 May 2022 00:02:07 +0200 Subject: [PATCH 6/7] fix failing tests --- .../observability/public/application/application.test.tsx | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/x-pack/plugins/observability/public/application/application.test.tsx b/x-pack/plugins/observability/public/application/application.test.tsx index a03f007c2d751..9cf0998e5d7c7 100644 --- a/x-pack/plugins/observability/public/application/application.test.tsx +++ b/x-pack/plugins/observability/public/application/application.test.tsx @@ -83,6 +83,12 @@ describe('renderApp', () => { observabilityRuleTypeRegistry: createObservabilityRuleTypeRegistryMock(), ObservabilityPageTemplate: KibanaPageTemplate, kibanaFeatures: [], + usageCollection: { + components: { + ApplicationUsageTrackingProvider: (props) => null, + }, + reportUiCounter: jest.fn(), + }, }); unmount(); }).not.toThrowError(); From 68997745d47edf588d9ef997d5e16a4aa5db23dc Mon Sep 17 00:00:00 2001 From: mgiota Date: Thu, 12 May 2022 10:01:05 +0200 Subject: [PATCH 7/7] application usage for cases and rules --- x-pack/plugins/observability/public/config/index.ts | 2 +- x-pack/plugins/observability/public/routes/index.tsx | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/x-pack/plugins/observability/public/config/index.ts b/x-pack/plugins/observability/public/config/index.ts index 950e76c1f0a3c..34d783180750b 100644 --- a/x-pack/plugins/observability/public/config/index.ts +++ b/x-pack/plugins/observability/public/config/index.ts @@ -10,6 +10,6 @@ export { translations } from './translations'; export enum AlertingPages { alerts = 'alerts', - case = 'cases', + cases = 'cases', rules = 'rules', } diff --git a/x-pack/plugins/observability/public/routes/index.tsx b/x-pack/plugins/observability/public/routes/index.tsx index b25dca030b0ea..573eb0b7308e4 100644 --- a/x-pack/plugins/observability/public/routes/index.tsx +++ b/x-pack/plugins/observability/public/routes/index.tsx @@ -62,7 +62,11 @@ export const routes = { }, [casesPath]: { handler: () => { - return ; + return ( + + + + ); }, params: {}, exact: false, @@ -96,7 +100,11 @@ export const routes = { }, '/alerts/rules': { handler: () => { - return ; + return ( + + + + ); }, params: {}, exact: true,