From ae2290d288f9cb9e1ad969081e31de07fc5c6cde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Ferna=CC=81ndez=20Haro?= Date: Wed, 17 Feb 2021 11:34:05 +0100 Subject: [PATCH] [Usage Collection] Remove unused UI Metric APIs --- 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 a0fd0a6ffc25..ef6db57c1a99 100644 --- a/src/core/TESTING.md +++ b/src/core/TESTING.md @@ -830,6 +830,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'; @@ -853,8 +854,10 @@ export class MyPlugin implements Plugin { @@ -1090,8 +1095,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 36e34479ad2d..b53bffa87fd1 100644 --- a/src/plugins/data/public/public.api.md +++ b/src/plugins/data/public/public.api.md @@ -59,7 +59,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 c8f1ad903576..c5d17f4cf8d8 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 ade25424c225..e01b3f9bb422 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 72cefaf02649..268ed3316542 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 6d1eb751d907..79260b17e0c8 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