Skip to content

Commit

Permalink
[ML] Re-enabling file upload telemetry (#60418) (#60479)
Browse files Browse the repository at this point in the history
* [ML] Re-enabling file upload telemetry

* small refactor

* removing exported function

* removing commented out code

* removing commented out include

* cleaning up types
  • Loading branch information
jgowdyelastic committed Mar 18, 2020
1 parent 32ba66a commit 98fdd3d
Show file tree
Hide file tree
Showing 14 changed files with 217 additions and 275 deletions.
13 changes: 0 additions & 13 deletions x-pack/plugins/ml/mappings.json

This file was deleted.

3 changes: 3 additions & 0 deletions x-pack/plugins/ml/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { i18n } from '@kbn/i18n';
import { Plugin, CoreStart, CoreSetup, AppMountParameters } from 'kibana/public';
import { ManagementSetup } from 'src/plugins/management/public';
import { SharePluginStart } from 'src/plugins/share/public';
import { UsageCollectionSetup } from 'src/plugins/usage_collection/server';

import { DataPublicPluginStart } from 'src/plugins/data/public';
import { SecurityPluginSetup } from '../../security/public';
Expand All @@ -24,6 +25,7 @@ export interface MlSetupDependencies {
security: SecurityPluginSetup;
licensing: LicensingPluginSetup;
management: ManagementSetup;
usageCollection: UsageCollectionSetup;
}

export class MlPlugin implements Plugin<Setup, Start> {
Expand All @@ -47,6 +49,7 @@ export class MlPlugin implements Plugin<Setup, Start> {
security: pluginsSetup.security,
licensing: pluginsSetup.licensing,
management: pluginsSetup.management,
usageCollection: pluginsSetup.usageCollection,
},
{
element: params.element,
Expand Down
15 changes: 0 additions & 15 deletions x-pack/plugins/ml/server/lib/ml_telemetry/index.ts

This file was deleted.

This file was deleted.

128 changes: 0 additions & 128 deletions x-pack/plugins/ml/server/lib/ml_telemetry/ml_telemetry.test.ts

This file was deleted.

72 changes: 0 additions & 72 deletions x-pack/plugins/ml/server/lib/ml_telemetry/ml_telemetry.ts

This file was deleted.

8 changes: 8 additions & 0 deletions x-pack/plugins/ml/server/lib/telemetry/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

export { initMlTelemetry } from './ml_usage_collector';
export { updateTelemetry } from './telemetry';
15 changes: 15 additions & 0 deletions x-pack/plugins/ml/server/lib/telemetry/internal_repository.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { SavedObjectsServiceStart, ISavedObjectsRepository } from 'kibana/server';

let internalRepository: ISavedObjectsRepository | null = null;
export const setInternalRepository = (
createInternalRepository: SavedObjectsServiceStart['createInternalRepository']
) => {
internalRepository = createInternalRepository();
};
export const getInternalRepository = () => internalRepository;
25 changes: 25 additions & 0 deletions x-pack/plugins/ml/server/lib/telemetry/mappings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { SavedObjectsType } from 'src/core/server';
import { TELEMETRY_DOC_ID } from './telemetry';

export const mlTelemetryMappingsType: SavedObjectsType = {
name: TELEMETRY_DOC_ID,
hidden: false,
namespaceAgnostic: true,
mappings: {
properties: {
file_data_visualizer: {
properties: {
index_creation_count: {
type: 'long',
},
},
},
},
},
};
32 changes: 32 additions & 0 deletions x-pack/plugins/ml/server/lib/telemetry/ml_usage_collector.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { CoreSetup } from 'kibana/server';

import { UsageCollectionSetup } from 'src/plugins/usage_collection/server';
import { getTelemetry, initTelemetry } from './telemetry';
import { mlTelemetryMappingsType } from './mappings';
import { setInternalRepository } from './internal_repository';

const TELEMETRY_TYPE = 'mlTelemetry';

export function initMlTelemetry(coreSetup: CoreSetup, usageCollection: UsageCollectionSetup) {
coreSetup.savedObjects.registerType(mlTelemetryMappingsType);
registerMlUsageCollector(usageCollection);
coreSetup.getStartServices().then(([core]) => {
setInternalRepository(core.savedObjects.createInternalRepository);
});
}

function registerMlUsageCollector(usageCollection: UsageCollectionSetup): void {
const mlUsageCollector = usageCollection.makeUsageCollector({
type: TELEMETRY_TYPE,
isReady: () => true,
fetch: async () => (await getTelemetry()) || initTelemetry(),
});

usageCollection.registerCollector(mlUsageCollector);
}
Loading

0 comments on commit 98fdd3d

Please sign in to comment.