mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
[Usage Collection] Remove unused UI Metric APIs (#91620)
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
parent
f0a9b7af45
commit
fd9e159816
7 changed files with 18 additions and 36 deletions
|
@ -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<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 {};
|
||||
}
|
||||
|
@ -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', () => {
|
||||
|
@ -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');
|
||||
});
|
||||
});
|
||||
```
|
||||
|
|
|
@ -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';
|
||||
|
|
|
@ -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 {}
|
||||
|
||||
|
|
|
@ -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 {}
|
||||
}
|
||||
|
|
|
@ -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>;
|
||||
|
@ -33,9 +33,7 @@ const createSetupContract = (): Setup => {
|
|||
),
|
||||
},
|
||||
applicationUsageTracker: applicationUsageTrackerMock,
|
||||
allowTrackUserAgent: jest.fn(),
|
||||
reportUiCounter: jest.fn(),
|
||||
METRIC_TYPE,
|
||||
};
|
||||
|
||||
return setupContract;
|
||||
|
|
|
@ -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<UsageCollectionSetup, UsageCollectionStart> {
|
||||
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<UsageCollectionSetup, Usage
|
|||
),
|
||||
},
|
||||
applicationUsageTracker,
|
||||
allowTrackUserAgent: (allow: boolean) => {
|
||||
this.trackUserAgent = allow;
|
||||
},
|
||||
reportUiCounter: this.reporter.reportUiCounter,
|
||||
METRIC_TYPE,
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -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,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -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';
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue