Skip to content

Commit

Permalink
[Usage Collection] Remove unused UI Metric APIs (#91620) (#92606)
Browse files Browse the repository at this point in the history
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>

Co-authored-by: Alejandro Fernández Haro <alejandro.haro@elastic.co>
  • Loading branch information
kibanamachine and afharo authored Feb 24, 2021
1 parent be1f3cc commit a12ae72
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 36 deletions.
11 changes: 8 additions & 3 deletions src/core/TESTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -846,8 +847,10 @@ export class MyPlugin implements Plugin<MyPluginSetup, MyPluginStart, MyPluginSe

// an example on using an optional dependency that will be tested
if (usageCollection) {
usageCollection.allowTrackUserAgent(true);
usageCollection.reportUiCounter('my_plugin', METRIC_TYPE.LOADED, 'my_event');
}
// or in a shorter version
usageCollection?.reportUiCounter('my_plugin', METRIC_TYPE.LOADED, 'my_event');

return {};
}
Expand Down Expand Up @@ -1067,6 +1070,8 @@ import { coreMock } from '../../../core/public/mocks';
import { dataPluginMock } from '../../data/public/mocks';
import { usageCollectionPluginMock } from '../../usage_collection/public/mocks';

import { METRIC_TYPE } from '@kbn/analytics';

import { MyPlugin } from './plugin';

describe('Plugin', () => {
Expand All @@ -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');
});
});
```
Expand Down
1 change: 0 additions & 1 deletion src/plugins/data/public/public.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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 {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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 {}
}
Expand Down
4 changes: 1 addition & 3 deletions src/plugins/usage_collection/public/mocks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<UsageCollectionSetup>;
Expand All @@ -33,9 +33,7 @@ const createSetupContract = (): Setup => {
),
},
applicationUsageTracker: applicationUsageTrackerMock,
allowTrackUserAgent: jest.fn(),
reportUiCounter: jest.fn(),
METRIC_TYPE,
};

return setupContract;
Expand Down
15 changes: 2 additions & 13 deletions src/plugins/usage_collection/public/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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'
Expand All @@ -57,7 +54,6 @@ export function isUnauthenticated(http: HttpSetup) {

export class UsageCollectionPlugin implements Plugin<UsageCollectionSetup, UsageCollectionStart> {
private applicationUsageTracker?: ApplicationUsageTracker;
private trackUserAgent: boolean = true;
private subscriptions: Subscription[] = [];
private reporter?: Reporter;
private config: PublicConfigType;
Expand Down Expand Up @@ -88,11 +84,7 @@ export class UsageCollectionPlugin implements Plugin<UsageCollectionSetup, Usage
),
},
applicationUsageTracker,
allowTrackUserAgent: (allow: boolean) => {
this.trackUserAgent = allow;
},
reportUiCounter: this.reporter.reportUiCounter,
METRIC_TYPE,
};
}

Expand All @@ -110,14 +102,11 @@ export class UsageCollectionPlugin implements Plugin<UsageCollectionSetup, Usage
);
}

if (this.trackUserAgent) {
this.reporter.reportUserAgent('kibana');
}
this.reporter.reportUserAgent('kibana');

return {
applicationUsageTracker: this.getPublicApplicationUsageTracker(),
reportUiCounter: this.reporter.reportUiCounter,
METRIC_TYPE,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* 2.0.
*/

import { METRIC_TYPE } from '@kbn/analytics';
import { UsageCollectionSetup } from 'src/plugins/usage_collection/public';

import { UIM_APP_NAME } from '../constants';
Expand All @@ -22,7 +23,7 @@ export class UiMetricService {
return;
}

const { reportUiCounter, METRIC_TYPE } = this.usageCollection;
const { reportUiCounter } = this.usageCollection;
reportUiCounter(UIM_APP_NAME, METRIC_TYPE.COUNT, name);
}

Expand Down

0 comments on commit a12ae72

Please sign in to comment.