From b7968e67374076b7bf31599b5a725d2cfd6dc7b1 Mon Sep 17 00:00:00 2001 From: Przemyslaw Gomulka Date: Mon, 18 Oct 2021 16:13:06 +0200 Subject: [PATCH] [7.x] Add category field to deprecation logs (#77550) Deprecation logs in 7.x are using ESJsonLayout and it requires additional fields to be declared in a log4j config in order to emit values to logs. This commit adds category field to deprecation log pattern context: in 8.0 we use ECSLayout which do not require to declare additional fields upfront. In 7.x we have to declare them in the logging config. The PR introducing categories in master #67443. A backport to 7.x which missed this field #68061 --- distribution/src/config/log4j2.properties | 2 +- .../org/elasticsearch/common/logging/JsonLoggerTests.java | 6 ++++++ .../common/logging/json_layout/log4j2.properties | 4 ++-- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/distribution/src/config/log4j2.properties b/distribution/src/config/log4j2.properties index 0e834735e9761..926d206664855 100644 --- a/distribution/src/config/log4j2.properties +++ b/distribution/src/config/log4j2.properties @@ -63,7 +63,7 @@ appender.deprecation_rolling.name = deprecation_rolling appender.deprecation_rolling.fileName = ${sys:es.logs.base_path}${sys:file.separator}${sys:es.logs.cluster_name}_deprecation.json appender.deprecation_rolling.layout.type = ESJsonLayout appender.deprecation_rolling.layout.type_name = deprecation.elasticsearch -appender.deprecation_rolling.layout.esmessagefields=x-opaque-id,key +appender.deprecation_rolling.layout.esmessagefields=x-opaque-id,key,category appender.deprecation_rolling.filter.rate_limit.type = RateLimitingFilter appender.deprecation_rolling.filePattern = ${sys:es.logs.base_path}${sys:file.separator}${sys:es.logs.cluster_name}_deprecation-%i.json.gz diff --git a/qa/logging-config/src/test/java/org/elasticsearch/common/logging/JsonLoggerTests.java b/qa/logging-config/src/test/java/org/elasticsearch/common/logging/JsonLoggerTests.java index 3f5f00c267a83..3417b06d8b918 100644 --- a/qa/logging-config/src/test/java/org/elasticsearch/common/logging/JsonLoggerTests.java +++ b/qa/logging-config/src/test/java/org/elasticsearch/common/logging/JsonLoggerTests.java @@ -150,6 +150,7 @@ public void testParseFieldEmittingDeprecatedLogs() throws Exception { allOf( hasEntry("type", "deprecation.elasticsearch"), hasEntry("level", "CRITICAL"), + hasEntry("category", "api"), hasEntry("component", "o.e.d.x.ParseField"), hasEntry("cluster.name", "elasticsearch"), hasEntry("node.name", "sample-name"), @@ -161,6 +162,7 @@ public void testParseFieldEmittingDeprecatedLogs() throws Exception { allOf( hasEntry("type", "deprecation.elasticsearch"), hasEntry("level", "CRITICAL"), + hasEntry("category", "api"), hasEntry("component", "o.e.d.x.ParseField"), hasEntry("cluster.name", "elasticsearch"), hasEntry("node.name", "sample-name"), @@ -200,6 +202,7 @@ public void testDeprecatedMessage() throws Exception { allOf( hasEntry("type", "deprecation.elasticsearch"), hasEntry("level", "CRITICAL"), + hasEntry("category", "other"), hasEntry("component", "o.e.d.test"), hasEntry("cluster.name", "elasticsearch"), hasEntry("node.name", "sample-name"), @@ -347,6 +350,7 @@ public void testDuplicateLogMessages() throws Exception { allOf( hasEntry("type", "deprecation.elasticsearch"), hasEntry("level", "CRITICAL"), + hasEntry("category", "other"), hasEntry("component", "o.e.d.test"), hasEntry("cluster.name", "elasticsearch"), hasEntry("node.name", "sample-name"), @@ -381,6 +385,7 @@ public void testDuplicateLogMessages() throws Exception { allOf( hasEntry("type", "deprecation.elasticsearch"), hasEntry("level", "CRITICAL"), + hasEntry("category", "other"), hasEntry("component", "o.e.d.test"), hasEntry("cluster.name", "elasticsearch"), hasEntry("node.name", "sample-name"), @@ -390,6 +395,7 @@ public void testDuplicateLogMessages() throws Exception { allOf( hasEntry("type", "deprecation.elasticsearch"), hasEntry("level", "CRITICAL"), + hasEntry("category", "other"), hasEntry("component", "o.e.d.test"), hasEntry("cluster.name", "elasticsearch"), hasEntry("node.name", "sample-name"), diff --git a/qa/logging-config/src/test/resources/org/elasticsearch/common/logging/json_layout/log4j2.properties b/qa/logging-config/src/test/resources/org/elasticsearch/common/logging/json_layout/log4j2.properties index 91395921ceccc..ce639619e56ca 100644 --- a/qa/logging-config/src/test/resources/org/elasticsearch/common/logging/json_layout/log4j2.properties +++ b/qa/logging-config/src/test/resources/org/elasticsearch/common/logging/json_layout/log4j2.properties @@ -14,7 +14,7 @@ appender.deprecated.name = deprecated appender.deprecated.fileName = ${sys:es.logs.base_path}${sys:file.separator}${sys:es.logs.cluster_name}_deprecated.json appender.deprecated.layout.type = ESJsonLayout appender.deprecated.layout.type_name = deprecation.elasticsearch -appender.deprecated.layout.esmessagefields = x-opaque-id,key +appender.deprecated.layout.esmessagefields = x-opaque-id,key,category appender.deprecated.filter.rate_limit.type = RateLimitingFilter appender.deprecation_rolling_old.type = File @@ -28,7 +28,7 @@ appender.deprecatedconsole.type = Console appender.deprecatedconsole.name = deprecatedconsole appender.deprecatedconsole.layout.type = ESJsonLayout appender.deprecatedconsole.layout.type_name = deprecation.elasticsearch -appender.deprecatedconsole.layout.esmessagefields = x-opaque-id,key +appender.deprecatedconsole.layout.esmessagefields = x-opaque-id,key,category appender.deprecatedconsole.filter.rate_limit.type = RateLimitingFilter appender.index_search_slowlog_rolling.type = File