Skip to content

Commit

Permalink
Config flag for enabling/disabling telemetry collection
Browse files Browse the repository at this point in the history
  • Loading branch information
dgieselaar committed Mar 23, 2020
1 parent 72b7ae9 commit bf7a247
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 47 deletions.
5 changes: 4 additions & 1 deletion x-pack/legacy/plugins/apm/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@ export const apm: LegacyPluginInitializer = kibana => {
autocreateApmIndexPattern: Joi.boolean().default(true),

// service map
serviceMapEnabled: Joi.boolean().default(true)
serviceMapEnabled: Joi.boolean().default(true),

// telemetry
telemetryCollectionEnabled: Joi.boolean().default(true)
}).default();
},

Expand Down
6 changes: 4 additions & 2 deletions x-pack/plugins/apm/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ export const config = {
enabled: schema.boolean({ defaultValue: true }),
transactionGroupBucketSize: schema.number({ defaultValue: 100 }),
maxTraceItems: schema.number({ defaultValue: 1000 })
})
}),
telemetryCollectionEnabled: schema.boolean({ defaultValue: true })
})
};

Expand Down Expand Up @@ -62,7 +63,8 @@ export function mergeConfigs(
'xpack.apm.ui.maxTraceItems': apmConfig.ui.maxTraceItems,
'xpack.apm.ui.transactionGroupBucketSize':
apmConfig.ui.transactionGroupBucketSize,
'xpack.apm.autocreateApmIndexPattern': apmConfig.autocreateApmIndexPattern
'xpack.apm.autocreateApmIndexPattern': apmConfig.autocreateApmIndexPattern,
'xpack.apm.telemetryCollectionEnabled': apmConfig.telemetryCollectionEnabled
};
}

Expand Down
28 changes: 15 additions & 13 deletions x-pack/plugins/apm/server/lib/apm_telemetry/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,19 +109,21 @@ export async function createApmTelemetry({
});

usageCollector.registerCollector(collector);
}

export function scheduleApmTelemetryTasks(
taskManager: TaskManagerStartContract
) {
taskManager.ensureScheduled({
id: APM_TELEMETRY_TASK_NAME,
taskType: APM_TELEMETRY_TASK_NAME,
schedule: {
interval: '720m'
},
scope: ['apm'],
params: {},
state: {}
core.getStartServices().then(([coreStart, pluginsStart]) => {
const { taskManager: taskManagerStart } = pluginsStart as {
taskManager: TaskManagerStartContract;
};

taskManagerStart.ensureScheduled({
id: APM_TELEMETRY_TASK_NAME,
taskType: APM_TELEMETRY_TASK_NAME,
schedule: {
interval: '720m'
},
scope: ['apm'],
params: {},
state: {}
});
});
}
46 changes: 15 additions & 31 deletions x-pack/plugins/apm/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,13 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import {
PluginInitializerContext,
Plugin,
CoreSetup,
CoreStart
} from 'src/core/server';
import { PluginInitializerContext, Plugin, CoreSetup } from 'src/core/server';
import { Observable, combineLatest, AsyncSubject } from 'rxjs';
import { map, take } from 'rxjs/operators';
import { Server } from 'hapi';
import { once } from 'lodash';
import { UsageCollectionSetup } from '../../../../src/plugins/usage_collection/server';
import {
TaskManagerSetupContract,
TaskManagerStartContract
} from '../../task_manager/server';
import { TaskManagerSetupContract } from '../../task_manager/server';
import { APMOSSPluginSetup } from '../../../../src/plugins/apm_oss/server';
import { createApmAgentConfigurationIndex } from './lib/settings/agent_configuration/create_agent_config_index';
import { createApmCustomLinkIndex } from './lib/settings/custom_link/create_custom_link_index';
Expand All @@ -29,10 +21,7 @@ import { tutorialProvider } from './tutorial';
import { CloudSetup } from '../../cloud/server';
import { getInternalSavedObjectsClient } from './lib/helpers/get_internal_saved_objects_client';
import { LicensingPluginSetup } from '../../licensing/public';
import {
createApmTelemetry,
scheduleApmTelemetryTasks
} from './lib/apm_telemetry';
import { createApmTelemetry } from './lib/apm_telemetry';

export interface LegacySetup {
server: Server;
Expand Down Expand Up @@ -68,7 +57,17 @@ export class APMPlugin implements Plugin<APMPluginContract> {
map(([apmOssConfig, apmConfig]) => mergeConfigs(apmOssConfig, apmConfig))
);

if (plugins.taskManager && plugins.usageCollection) {
this.legacySetup$.subscribe(__LEGACY => {
createApmApi().init(core, { config$: mergedConfig$, logger, __LEGACY });
});

const currentConfig = await mergedConfig$.pipe(take(1)).toPromise();

if (
plugins.taskManager &&
plugins.usageCollection &&
currentConfig['xpack.apm.telemetryCollectionEnabled']
) {
createApmTelemetry({
core,
config$: mergedConfig$,
Expand All @@ -78,12 +77,6 @@ export class APMPlugin implements Plugin<APMPluginContract> {
});
}

this.legacySetup$.subscribe(__LEGACY => {
createApmApi().init(core, { config$: mergedConfig$, logger, __LEGACY });
});

const currentConfig = await mergedConfig$.pipe(take(1)).toPromise();

// create agent configuration index without blocking setup lifecycle
createApmAgentConfigurationIndex({
esClient: core.elasticsearch.dataClient,
Expand Down Expand Up @@ -126,16 +119,7 @@ export class APMPlugin implements Plugin<APMPluginContract> {
};
}

public async start(
core: CoreStart,
plugins: {
taskManager?: TaskManagerStartContract;
}
) {
if (plugins.taskManager) {
scheduleApmTelemetryTasks(plugins.taskManager);
}
}
public async start() {}

public stop() {}
}

0 comments on commit bf7a247

Please sign in to comment.