From 3deb35f0a3d87d7c80a9d3a9ed6569061e5ce96f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Fern=C3=A1ndez=20Haro?= Date: Wed, 24 Feb 2021 12:21:40 +0000 Subject: [PATCH] [Usage Collection] Remove unused UI Metric APIs (#91620) Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> --- src/core/TESTING.md | 11 ++++++++--- src/plugins/data/public/public.api.md | 1 - .../delete_field_provider/get_delete_provider.tsx | 7 ++----- .../field_editor_flyout_content_container.tsx | 13 +++---------- src/plugins/usage_collection/public/mocks.tsx | 4 +--- src/plugins/usage_collection/public/plugin.tsx | 15 ++------------- .../public/application/services/ui_metric.ts | 3 ++- 7 files changed, 18 insertions(+), 36 deletions(-) diff --git a/src/core/TESTING.md b/src/core/TESTING.md index 0ae759f78c937..f1a33c871f40f 100644 --- a/src/core/TESTING.md +++ b/src/core/TESTING.md @@ -823,6 +823,7 @@ data. ```typescript // src/plugins/myplugin/public/plugin.ts +import { METRIC_TYPE } from '@kbn/analytics'; import { CoreSetup, CoreStart, Plugin } from 'kibana/public'; import { DataPublicPluginSetup, DataPublicPluginStart } from '../../data/public'; import { UsageCollectionSetup } from '../../usage_collection/public'; @@ -846,8 +847,10 @@ export class MyPlugin implements Plugin { @@ -1083,8 +1088,8 @@ describe('Plugin', () => { plugin.setup(coreSetup, setupDeps); - expect(usageCollectionSetup.allowTrackUserAgent).toHaveBeenCalledTimes(1); - expect(usageCollectionSetup.allowTrackUserAgent).toHaveBeenCalledWith(true); + expect(usageCollectionSetup.reportUiCounter).toHaveBeenCalledTimes(2); + expect(usageCollectionSetup.reportUiCounter).toHaveBeenCalledWith('my_plugin', METRIC_TYPE.LOADED, 'my_event'); }); }); ``` diff --git a/src/plugins/data/public/public.api.md b/src/plugins/data/public/public.api.md index 4fb7cc2850f0c..471ff93cac386 100644 --- a/src/plugins/data/public/public.api.md +++ b/src/plugins/data/public/public.api.md @@ -60,7 +60,6 @@ import { LocationDescriptorObject } from 'history'; import { Logger } from '@kbn/logging'; import { LogMeta } from '@kbn/logging'; import { MaybePromise } from '@kbn/utility-types'; -import { METRIC_TYPE } from '@kbn/analytics'; import { Moment } from 'moment'; import moment from 'moment'; import { NameList } from 'elasticsearch'; diff --git a/src/plugins/index_pattern_field_editor/public/components/delete_field_provider/get_delete_provider.tsx b/src/plugins/index_pattern_field_editor/public/components/delete_field_provider/get_delete_provider.tsx index c8f1ad9035761..c5d17f4cf8d8d 100644 --- a/src/plugins/index_pattern_field_editor/public/components/delete_field_provider/get_delete_provider.tsx +++ b/src/plugins/index_pattern_field_editor/public/components/delete_field_provider/get_delete_provider.tsx @@ -9,6 +9,7 @@ import React, { useCallback } from 'react'; import { i18n } from '@kbn/i18n'; +import { METRIC_TYPE } from '@kbn/analytics'; import { NotificationsStart } from 'src/core/public'; import { IndexPattern, UsageCollectionStart } from '../../shared_imports'; import { pluginName } from '../../constants'; @@ -33,11 +34,7 @@ export const getDeleteProvider = ( }); try { - usageCollection.reportUiCounter( - pluginName, - usageCollection.METRIC_TYPE.COUNT, - 'delete_runtime' - ); + usageCollection.reportUiCounter(pluginName, METRIC_TYPE.COUNT, 'delete_runtime'); // eslint-disable-next-line no-empty } catch {} diff --git a/src/plugins/index_pattern_field_editor/public/components/field_editor_flyout_content_container.tsx b/src/plugins/index_pattern_field_editor/public/components/field_editor_flyout_content_container.tsx index ade25424c2250..e01b3f9bb422c 100644 --- a/src/plugins/index_pattern_field_editor/public/components/field_editor_flyout_content_container.tsx +++ b/src/plugins/index_pattern_field_editor/public/components/field_editor_flyout_content_container.tsx @@ -9,6 +9,7 @@ import React, { useCallback, useEffect, useState, useMemo } from 'react'; import { DocLinksStart, NotificationsStart, CoreStart } from 'src/core/public'; import { i18n } from '@kbn/i18n'; +import { METRIC_TYPE } from '@kbn/analytics'; import { IndexPatternField, @@ -98,11 +99,7 @@ export const FieldEditorFlyoutContentContainer = ({ if (fieldTypeToProcess === 'runtime') { try { - usageCollection.reportUiCounter( - pluginName, - usageCollection.METRIC_TYPE.COUNT, - 'save_runtime' - ); + usageCollection.reportUiCounter(pluginName, METRIC_TYPE.COUNT, 'save_runtime'); // eslint-disable-next-line no-empty } catch {} // rename an existing runtime field @@ -116,11 +113,7 @@ export const FieldEditorFlyoutContentContainer = ({ }); } else { try { - usageCollection.reportUiCounter( - pluginName, - usageCollection.METRIC_TYPE.COUNT, - 'save_concrete' - ); + usageCollection.reportUiCounter(pluginName, METRIC_TYPE.COUNT, 'save_concrete'); // eslint-disable-next-line no-empty } catch {} } diff --git a/src/plugins/usage_collection/public/mocks.tsx b/src/plugins/usage_collection/public/mocks.tsx index 72cefaf026490..268ed3316542e 100644 --- a/src/plugins/usage_collection/public/mocks.tsx +++ b/src/plugins/usage_collection/public/mocks.tsx @@ -8,7 +8,7 @@ import React from 'react'; import { ApplicationUsageTracker } from '@kbn/analytics'; -import { UsageCollectionSetup, METRIC_TYPE } from '.'; +import { UsageCollectionSetup } from '.'; import { ApplicationUsageContext } from './components/track_application_view'; export type Setup = jest.Mocked; @@ -33,9 +33,7 @@ const createSetupContract = (): Setup => { ), }, applicationUsageTracker: applicationUsageTrackerMock, - allowTrackUserAgent: jest.fn(), reportUiCounter: jest.fn(), - METRIC_TYPE, }; return setupContract; diff --git a/src/plugins/usage_collection/public/plugin.tsx b/src/plugins/usage_collection/public/plugin.tsx index 6d1eb751d907a..79260b17e0c82 100644 --- a/src/plugins/usage_collection/public/plugin.tsx +++ b/src/plugins/usage_collection/public/plugin.tsx @@ -6,7 +6,7 @@ * Side Public License, v 1. */ -import { Reporter, METRIC_TYPE, ApplicationUsageTracker } from '@kbn/analytics'; +import { Reporter, ApplicationUsageTracker } from '@kbn/analytics'; import type { Subscription } from 'rxjs'; import React from 'react'; import type { @@ -35,15 +35,12 @@ export interface UsageCollectionSetup { components: { ApplicationUsageTrackingProvider: React.FC; }; - allowTrackUserAgent: (allow: boolean) => void; applicationUsageTracker: IApplicationUsageTracker; reportUiCounter: Reporter['reportUiCounter']; - METRIC_TYPE: typeof METRIC_TYPE; } export interface UsageCollectionStart { reportUiCounter: Reporter['reportUiCounter']; - METRIC_TYPE: typeof METRIC_TYPE; applicationUsageTracker: Pick< ApplicationUsageTracker, 'trackApplicationViewUsage' | 'flushTrackedView' | 'updateViewClickCounter' @@ -57,7 +54,6 @@ export function isUnauthenticated(http: HttpSetup) { export class UsageCollectionPlugin implements Plugin { private applicationUsageTracker?: ApplicationUsageTracker; - private trackUserAgent: boolean = true; private subscriptions: Subscription[] = []; private reporter?: Reporter; private config: PublicConfigType; @@ -88,11 +84,7 @@ export class UsageCollectionPlugin implements Plugin { - this.trackUserAgent = allow; - }, reportUiCounter: this.reporter.reportUiCounter, - METRIC_TYPE, }; } @@ -110,14 +102,11 @@ export class UsageCollectionPlugin implements Plugin