Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/platform/plugins/shared/telemetry/moon.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ dependsOn:
- '@kbn/logging'
- '@kbn/core-security-server'
- '@kbn/telemetry-config'
- '@kbn/config'
tags:
- plugin
- prod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,24 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import { applyDeprecations, configDeprecationFactory } from '@kbn/config';
import { configDeprecationsMock } from '@kbn/core/server/mocks';
import { config } from './config';

const applyConfigDeprecations = (telemetrySettings: Record<string, unknown> = {}) => {
const deprecationContext = configDeprecationsMock.createContext();
const deprecations = config.deprecations!(configDeprecationFactory);
const { config: migrated } = applyDeprecations(
{ telemetry: telemetrySettings },
deprecations.map((deprecation) => ({
deprecation,
path: 'telemetry',
context: deprecationContext,
}))
);
return migrated as Record<string, Record<string, unknown>>;
};

describe('config', () => {
const baseContext = {
dist: true,
Expand Down Expand Up @@ -62,4 +78,51 @@ describe('config', () => {
}
);
});

describe('deprecations: telemetry.enabled', () => {
describe('when telemetry.enabled is set to a falsy value, the plugin stays enabled and telemetry is opted out', () => {
test.each([false, 'false', 'False', 'FALSE'])(
'migrates telemetry.enabled: %p → removes enabled, sets optIn and allowChangingOptInStatus to false',
(enabledValue) => {
const migrated = applyConfigDeprecations({ enabled: enabledValue });

expect(migrated.telemetry.enabled).toBeUndefined();
expect(migrated.telemetry.optIn).toBe(false);
expect(migrated.telemetry.allowChangingOptInStatus).toBe(false);
}
);

test.each([false, 'false', 'False', 'FALSE'])(
'also disables tracing and metrics when telemetry.enabled: %p',
(enabledValue) => {
const migrated = applyConfigDeprecations({ enabled: enabledValue });

const telemetry = migrated.telemetry as Record<string, Record<string, unknown>>;
expect(telemetry.tracing?.enabled).toBe(false);
expect(telemetry.metrics?.enabled).toBe(false);
}
);
});

describe('when telemetry.enabled is absent or truthy, the deprecation does not fire', () => {
test('does not modify config when telemetry.enabled is not set', () => {
const migrated = applyConfigDeprecations({});

expect(migrated.telemetry.enabled).toBeUndefined();
expect(migrated.telemetry.optIn).toBeUndefined();
expect(migrated.telemetry.allowChangingOptInStatus).toBeUndefined();
});

test.each([true, 'true', 'True', 'TRUE'])(
'does not modify config when telemetry.enabled: %p',
(enabledValue) => {
const migrated = applyConfigDeprecations({ enabled: enabledValue });

expect(migrated.telemetry.enabled).toBe(enabledValue);
expect(migrated.telemetry.optIn).toBeUndefined();
expect(migrated.telemetry.allowChangingOptInStatus).toBeUndefined();
}
);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,11 @@ export const config: PluginConfigDescriptor<TelemetryConfigType> = {
},
deprecations: () => [
(cfg) => {
if (cfg.telemetry?.enabled === false) {
const raw = cfg.telemetry?.enabled;
const isDisabling =
raw === false || (typeof raw === 'string' && raw.toLowerCase() === 'false');

if (isDisabling) {
return {
set: [
{ path: 'telemetry.optIn', value: false },
Expand Down
1 change: 1 addition & 0 deletions src/platform/plugins/shared/telemetry/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"@kbn/logging",
"@kbn/core-security-server",
"@kbn/telemetry-config",
"@kbn/config",
],
"exclude": [
"target/**/*",
Expand Down
Loading