From d2f217c53e38ca424fff6a8a3a139a3fbd5653bd Mon Sep 17 00:00:00 2001 From: Luke Elmers Date: Fri, 15 Oct 2021 16:53:19 -0600 Subject: [PATCH 1/3] Add deprecation for the default pattern layout. --- .../deprecation/core_deprecations.test.ts | 48 +++++++++++++++++++ .../config/deprecation/core_deprecations.ts | 40 ++++++++++++++++ 2 files changed, 88 insertions(+) diff --git a/src/core/server/config/deprecation/core_deprecations.test.ts b/src/core/server/config/deprecation/core_deprecations.test.ts index 223aae21dfd78..1483dc336bbf4 100644 --- a/src/core/server/config/deprecation/core_deprecations.test.ts +++ b/src/core/server/config/deprecation/core_deprecations.test.ts @@ -481,4 +481,52 @@ describe('core deprecations', () => { `); }); }); + + describe('using default pattern layout', () => { + it('warns when console appender is used', () => { + const { messages } = applyCoreDeprecations({ + logging: { + root: { + appenders: ['default', 'console', 'test'], + }, + }, + }); + expect(messages).toMatchInlineSnapshot(` + Array [ + "It looks like you are using Kibana's built-in \`console\` appender, which uses the \\"pattern\\" layout by default. In 8.0, the default layout will switch to JSON, which is ECS-compliant. If you are relying on the default pattern layout for log ingestion, be sure to explicitly configure this in your Kibana configuration to prevent any disruption when upgrading to 8.0.", + ] + `); + }); + + it('does not warn when console appender is not used', () => { + const { messages } = applyCoreDeprecations({ + logging: { + root: { + level: 'warn', + }, + }, + }); + expect(messages).toMatchInlineSnapshot(`Array []`); + }); + + it('does not warn when console appender is overwritten', () => { + const { messages } = applyCoreDeprecations({ + logging: { + appenders: { + console: { + type: 'console', + layout: { + type: 'pattern', + pattern: 'testing', + }, + }, + }, + root: { + appenders: ['default', 'console'], + }, + }, + }); + expect(messages).toMatchInlineSnapshot(`Array []`); + }); + }); }); diff --git a/src/core/server/config/deprecation/core_deprecations.ts b/src/core/server/config/deprecation/core_deprecations.ts index 1cf67f479f9b3..b33278af898b5 100644 --- a/src/core/server/config/deprecation/core_deprecations.ts +++ b/src/core/server/config/deprecation/core_deprecations.ts @@ -592,6 +592,45 @@ const logFilterDeprecation: ConfigDeprecation = ( } }; +const patternLayoutDefaultLoggingDeprecation: ConfigDeprecation = ( + settings, + fromPath, + addDeprecation, + { branch } +) => { + if ( + settings.logging?.root?.appenders?.includes('console') && + settings.logging?.appenders?.console === undefined + ) { + addDeprecation({ + configPath: 'logging.root.appenders', + level: 'warning', + documentationUrl: `https://github.com/elastic/kibana/blob/${branch}/src/core/server/logging/README.mdx#configuration`, + title: i18n.translate('core.deprecations.loggingPatternLayoutDefault.deprecationTitle', { + defaultMessage: `Kibana's default log format is changing to ECS JSON`, + }), + message: i18n.translate('core.deprecations.loggingPatternLayoutDefault.deprecationMessage', { + defaultMessage: + "It looks like you are using Kibana's built-in `console` appender, " + + 'which uses the "pattern" layout by default. In 8.0, the default layout ' + + 'will switch to JSON, which is ECS-compliant. If you are relying on the ' + + 'default pattern layout for log ingestion, be sure to explicitly configure this ' + + 'in your Kibana configuration to prevent any disruption when upgrading to 8.0.', + }), + correctiveActions: { + manualSteps: [ + i18n.translate('core.deprecations.loggingPatternLayoutDefault.manualSteps1', { + defaultMessage: `[recommended] Update your log ingestion configuration to use ECS format.`, + }), + i18n.translate('core.deprecations.loggingPatternLayoutDefault.manualSteps2', { + defaultMessage: `Alternatively, you can preserve the existing format by configuring a custom appender with \`layout.type: 'pattern'\``, + }), + ], + }, + }); + } +}; + export const coreDeprecationProvider: ConfigDeprecationProvider = ({ unusedFromRoot, renameFromRoot, @@ -651,4 +690,5 @@ export const coreDeprecationProvider: ConfigDeprecationProvider = ({ logEventsLogDeprecation, logEventsErrorDeprecation, logFilterDeprecation, + patternLayoutDefaultLoggingDeprecation, ]; From e96a2a7eefc57dcdfdc2214b29628bc39895d3f7 Mon Sep 17 00:00:00 2001 From: Luke Elmers Date: Mon, 18 Oct 2021 17:35:22 -0600 Subject: [PATCH 2/3] Update logic to include loggers & also use default appender. --- .../deprecation/core_deprecations.test.ts | 68 ++++++++++++------- .../config/deprecation/core_deprecations.ts | 11 ++- 2 files changed, 54 insertions(+), 25 deletions(-) diff --git a/src/core/server/config/deprecation/core_deprecations.test.ts b/src/core/server/config/deprecation/core_deprecations.test.ts index 1483dc336bbf4..cb59fef9ba3a9 100644 --- a/src/core/server/config/deprecation/core_deprecations.test.ts +++ b/src/core/server/config/deprecation/core_deprecations.test.ts @@ -483,30 +483,52 @@ describe('core deprecations', () => { }); describe('using default pattern layout', () => { - it('warns when console appender is used', () => { - const { messages } = applyCoreDeprecations({ - logging: { - root: { - appenders: ['default', 'console', 'test'], - }, - }, - }); - expect(messages).toMatchInlineSnapshot(` - Array [ - "It looks like you are using Kibana's built-in \`console\` appender, which uses the \\"pattern\\" layout by default. In 8.0, the default layout will switch to JSON, which is ECS-compliant. If you are relying on the default pattern layout for log ingestion, be sure to explicitly configure this in your Kibana configuration to prevent any disruption when upgrading to 8.0.", - ] - `); - }); + ['default', 'console'].forEach((appender) => { + describe(appender, () => { + it(`warns when ${appender} appender is used in root`, () => { + const { messages } = applyCoreDeprecations({ + logging: { + root: { + appenders: [appender, 'test'], + }, + }, + }); + expect(messages).toMatchInlineSnapshot(` + Array [ + "It looks like you are using Kibana's built-in \`console\` appender, which uses the \\"pattern\\" layout by default. In 8.0, the default layout will switch to JSON, which is ECS-compliant. If you are relying on the default pattern layout for log ingestion, be sure to explicitly configure this in your Kibana configuration to prevent any disruption when upgrading to 8.0.", + ] + `); + }); - it('does not warn when console appender is not used', () => { - const { messages } = applyCoreDeprecations({ - logging: { - root: { - level: 'warn', - }, - }, + it(`warns when ${appender} appender is used in loggers`, () => { + const { messages } = applyCoreDeprecations({ + logging: { + loggers: [ + { + name: 'my-logger', + appenders: [appender], + }, + ], + }, + }); + expect(messages).toMatchInlineSnapshot(` + Array [ + "It looks like you are using Kibana's built-in \`console\` appender, which uses the \\"pattern\\" layout by default. In 8.0, the default layout will switch to JSON, which is ECS-compliant. If you are relying on the default pattern layout for log ingestion, be sure to explicitly configure this in your Kibana configuration to prevent any disruption when upgrading to 8.0.", + ] + `); + }); + + it(`does not warn when ${appender} appender is not used in root`, () => { + const { messages } = applyCoreDeprecations({ + logging: { + root: { + level: 'warn', + }, + }, + }); + expect(messages).toMatchInlineSnapshot(`Array []`); + }); }); - expect(messages).toMatchInlineSnapshot(`Array []`); }); it('does not warn when console appender is overwritten', () => { @@ -522,7 +544,7 @@ describe('core deprecations', () => { }, }, root: { - appenders: ['default', 'console'], + appenders: ['console'], }, }, }); diff --git a/src/core/server/config/deprecation/core_deprecations.ts b/src/core/server/config/deprecation/core_deprecations.ts index b33278af898b5..c0018c11f36f2 100644 --- a/src/core/server/config/deprecation/core_deprecations.ts +++ b/src/core/server/config/deprecation/core_deprecations.ts @@ -8,6 +8,7 @@ import { i18n } from '@kbn/i18n'; import { ConfigDeprecationProvider, ConfigDeprecation } from '@kbn/config'; +import { LoggingConfigType } from '../../logging'; const kibanaPathConf: ConfigDeprecation = (settings, fromPath, addDeprecation) => { if (process.env?.KIBANA_PATH_CONF) { @@ -598,9 +599,15 @@ const patternLayoutDefaultLoggingDeprecation: ConfigDeprecation = ( addDeprecation, { branch } ) => { + const usesAppender = (name: string) => + settings.logging?.root?.appenders?.includes(name) || + settings.logging?.loggers?.some((logger: LoggingConfigType['loggers'][number]) => + logger.appenders?.includes(name) + ); + if ( - settings.logging?.root?.appenders?.includes('console') && - settings.logging?.appenders?.console === undefined + (usesAppender('default') && settings.logging?.appenders?.default === undefined) || + (usesAppender('console') && settings.logging?.appenders?.console === undefined) ) { addDeprecation({ configPath: 'logging.root.appenders', From c6dab7e24868ab3cbdfb2ff00a6778dc8d8b5774 Mon Sep 17 00:00:00 2001 From: Luke Elmers Date: Mon, 18 Oct 2021 19:56:26 -0600 Subject: [PATCH 3/3] Add ECS link. --- src/core/server/config/deprecation/core_deprecations.test.ts | 4 ++-- src/core/server/config/deprecation/core_deprecations.ts | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/core/server/config/deprecation/core_deprecations.test.ts b/src/core/server/config/deprecation/core_deprecations.test.ts index cb59fef9ba3a9..407295c8ab57f 100644 --- a/src/core/server/config/deprecation/core_deprecations.test.ts +++ b/src/core/server/config/deprecation/core_deprecations.test.ts @@ -495,7 +495,7 @@ describe('core deprecations', () => { }); expect(messages).toMatchInlineSnapshot(` Array [ - "It looks like you are using Kibana's built-in \`console\` appender, which uses the \\"pattern\\" layout by default. In 8.0, the default layout will switch to JSON, which is ECS-compliant. If you are relying on the default pattern layout for log ingestion, be sure to explicitly configure this in your Kibana configuration to prevent any disruption when upgrading to 8.0.", + "It looks like you are using Kibana's built-in \`console\` appender, which uses the \\"pattern\\" layout by default. In 8.0, the default layout will switch to JSON, which is ECS-compliant. If you are relying on the default pattern layout for log ingestion, be sure to explicitly configure this in your Kibana configuration to prevent any disruption when upgrading to 8.0. For more info on ECS, see https://elastic.co/what-is/ecs.", ] `); }); @@ -513,7 +513,7 @@ describe('core deprecations', () => { }); expect(messages).toMatchInlineSnapshot(` Array [ - "It looks like you are using Kibana's built-in \`console\` appender, which uses the \\"pattern\\" layout by default. In 8.0, the default layout will switch to JSON, which is ECS-compliant. If you are relying on the default pattern layout for log ingestion, be sure to explicitly configure this in your Kibana configuration to prevent any disruption when upgrading to 8.0.", + "It looks like you are using Kibana's built-in \`console\` appender, which uses the \\"pattern\\" layout by default. In 8.0, the default layout will switch to JSON, which is ECS-compliant. If you are relying on the default pattern layout for log ingestion, be sure to explicitly configure this in your Kibana configuration to prevent any disruption when upgrading to 8.0. For more info on ECS, see https://elastic.co/what-is/ecs.", ] `); }); diff --git a/src/core/server/config/deprecation/core_deprecations.ts b/src/core/server/config/deprecation/core_deprecations.ts index c0018c11f36f2..fce0f6b0d9ecf 100644 --- a/src/core/server/config/deprecation/core_deprecations.ts +++ b/src/core/server/config/deprecation/core_deprecations.ts @@ -622,7 +622,8 @@ const patternLayoutDefaultLoggingDeprecation: ConfigDeprecation = ( 'which uses the "pattern" layout by default. In 8.0, the default layout ' + 'will switch to JSON, which is ECS-compliant. If you are relying on the ' + 'default pattern layout for log ingestion, be sure to explicitly configure this ' + - 'in your Kibana configuration to prevent any disruption when upgrading to 8.0.', + 'in your Kibana configuration to prevent any disruption when upgrading to 8.0. ' + + 'For more info on ECS, see https://elastic.co/what-is/ecs.', }), correctiveActions: { manualSteps: [