Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log deprecation warnings for plugins which will no longer be disable-able in 8.0 #111890

Closed
Closed
Show file tree
Hide file tree
Changes from 3 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
31 changes: 31 additions & 0 deletions packages/kbn-config/src/config_service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,37 @@ test('read "enabled" even if its schema is not present', async () => {
expect(isEnabled).toBe(true);
});

test('logs deprecation if schema is not present and "enabled" is used', async () => {
const initialConfig = {
foo: {
enabled: true,
},
};

const rawConfigProvider = rawConfigServiceMock.create({ rawConfig: initialConfig });
const configService = new ConfigService(rawConfigProvider, defaultEnv, logger);

await configService.isEnabledAtPath('foo');
expect(configService.getHandledDeprecatedConfigs()).toMatchInlineSnapshot(`
Array [
Array [
"foo",
Array [
Object {
"correctiveActions": Object {
"manualSteps": Array [
"Remove foo.enabled from your Kibana config.",
],
},
"message": "\\"foo.enabled\\" has been deprecated and will be removed in 8.0.",
"title": "Setting \\"foo.enabled\\" is deprecated",
},
],
],
]
`);
});

test('allows plugins to specify "enabled" flag via validation schema', async () => {
const initialConfig = {};

Expand Down
27 changes: 24 additions & 3 deletions packages/kbn-config/src/config_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,23 @@ export class ConfigService {
// if plugin hasn't got a config schema, we try to read "enabled" directly
const isEnabled = validatedConfig?.enabled ?? config.get(enabledPath);

// if we implicitly added an `enabled` config to a plugin without a schema,
// we log a deprecation warning, as this will not be supported in 8.0
if (validatedConfig?.enabled === undefined && isEnabled !== undefined) {
const deprecationPath = pathToString(enabledPath);
const deprecatedConfigDetails: DeprecatedConfigDetails = {
title: `Setting "${deprecationPath}" is deprecated`,
message: `"${deprecationPath}" has been deprecated and will be removed in 8.0.`,
correctiveActions: {
manualSteps: [`Remove ${deprecationPath} from your Kibana config.`],
},
};
this.addDeprecationProvider(namespace, () => [
(settings, fromPath, addDeprecation) => addDeprecation(deprecatedConfigDetails),
]);
this.markDeprecatedConfigAsHandled(namespace, deprecatedConfigDetails);
}

// not declared. consider that plugin is enabled by default
if (isEnabled === undefined) {
return true;
Expand Down Expand Up @@ -220,9 +237,7 @@ export class ConfigService {
if (!context.silent) {
deprecationMessages.push(context.message);
}
const handledDeprecatedConfig = this.handledDeprecatedConfigs.get(domainId) || [];
handledDeprecatedConfig.push(context);
this.handledDeprecatedConfigs.set(domainId, handledDeprecatedConfig);
this.markDeprecatedConfigAsHandled(domainId, context);
};

applyDeprecations(rawConfig, deprecations, createAddDeprecation);
Expand Down Expand Up @@ -260,6 +275,12 @@ export class ConfigService {
this.log.debug(`Marking config path as handled: ${path}`);
this.handledPaths.add(path);
}

private markDeprecatedConfigAsHandled(domainId: string, config: DeprecatedConfigDetails) {
const handledDeprecatedConfig = this.handledDeprecatedConfigs.get(domainId) || [];
handledDeprecatedConfig.push(config);
this.handledDeprecatedConfigs.set(domainId, handledDeprecatedConfig);
}
}

const createPluginEnabledPath = (configPath: string | string[]) => {
Expand Down
11 changes: 11 additions & 0 deletions src/plugins/apm_oss/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,17 @@ import { APMOSSPlugin } from './plugin';
const deprecations: ConfigDeprecationProvider = ({ unused }) => [
unused('fleetMode'),
unused('indexPattern'),
(settings, fromPath, addDeprecation) => {
if (settings.apm_oss?.enabled !== undefined) {
addDeprecation({
title: `Setting "${fromPath}.enabled" is deprecated`,
message: `"${fromPath}.enabled" has been deprecated and will be removed in 8.0.`,
correctiveActions: {
manualSteps: [`Remove ${fromPath}.enabled from your Kibana config.`],
},
});
}
},
lukeelmers marked this conversation as resolved.
Show resolved Hide resolved
];

export const config = {
Expand Down
15 changes: 15 additions & 0 deletions src/plugins/vis_types/pie/config.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
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import { schema, TypeOf } from '@kbn/config-schema';

export const configSchema = schema.object({
enabled: schema.boolean({ defaultValue: true }),
});

export type ConfigSchema = TypeOf<typeof configSchema>;
7 changes: 7 additions & 0 deletions src/plugins/vis_types/pie/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import { PluginConfigDescriptor } from 'src/core/server';
import { configSchema, ConfigSchema } from '../config';
import { VisTypePieServerPlugin } from './plugin';

export const config: PluginConfigDescriptor<ConfigSchema> = {
schema: configSchema,
};

export const plugin = () => new VisTypePieServerPlugin();
3 changes: 2 additions & 1 deletion src/plugins/vis_types/pie/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"include": [
"common/**/*",
"public/**/*",
"server/**/*"
"server/**/*",
"*.ts"
],
"references": [
{ "path": "../../../core/tsconfig.json" },
Expand Down
15 changes: 15 additions & 0 deletions src/plugins/vis_types/xy/config.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
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import { schema, TypeOf } from '@kbn/config-schema';

export const configSchema = schema.object({
enabled: schema.boolean({ defaultValue: true }),
});

export type ConfigSchema = TypeOf<typeof configSchema>;
2 changes: 1 addition & 1 deletion src/plugins/vis_types/xy/kibana.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"id": "visTypeXy",
"version": "kibana",
"ui": true,
"server": false,
"server": true,
"requiredPlugins": ["charts", "data", "expressions", "visualizations", "usageCollection"],
"requiredBundles": ["kibanaUtils", "visDefaultEditor"],
"extraPublicDirs": ["common/index"],
Expand Down
17 changes: 17 additions & 0 deletions src/plugins/vis_types/xy/server/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import { PluginConfigDescriptor } from 'src/core/server';
import { configSchema, ConfigSchema } from '../config';
import { VisTypeXYServerPlugin } from './plugin';

export const config: PluginConfigDescriptor<ConfigSchema> = {
schema: configSchema,
};

export const plugin = () => new VisTypeXYServerPlugin();
19 changes: 19 additions & 0 deletions src/plugins/vis_types/xy/server/plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import { Plugin } from 'src/core/server';

export class VisTypeXYServerPlugin implements Plugin {
public setup() {
return {};
}

public start() {
return {};
}
}
3 changes: 2 additions & 1 deletion src/plugins/vis_types/xy/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"include": [
"common/**/*",
"public/**/*",
"server/**/*"
"server/**/*",
"*.ts"
lukeelmers marked this conversation as resolved.
Show resolved Hide resolved
],
"references": [
{ "path": "../../../core/tsconfig.json" },
Expand Down