Skip to content

Commit

Permalink
[Usage Collection] Remove unused UI Metric APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
afharo committed Feb 17, 2021
1 parent bc207ff commit b3f18ee
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 20 deletions.
11 changes: 8 additions & 3 deletions src/core/TESTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -853,8 +854,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 @@ -1074,6 +1077,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 @@ -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');
});
});
```
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 b3f18ee

Please sign in to comment.