-
Notifications
You must be signed in to change notification settings - Fork 25k
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
Write deprecation logs to a data stream #58924
Write deprecation logs to a data stream #58924
Conversation
Pinging @elastic/es-core-infra (:Core/Infra/Logging) |
server/src/main/java/org/elasticsearch/common/logging/DeprecationLogger.java
Outdated
Show resolved
Hide resolved
I should add, the set of indexed fields in this PR may need to evolve, as it becomes clearer what we need to support the Upgrade Assistant. It should be a reasonable starting point however. |
server/src/main/java/org/elasticsearch/common/logging/DeprecationIndexingService.java
Outdated
Show resolved
Hide resolved
server/src/main/java/org/elasticsearch/common/logging/DeprecationIndexingService.java
Outdated
Show resolved
Hide resolved
|
||
private static final String DEPRECATION_ORIGIN = "deprecation"; | ||
|
||
public static final Setting<Boolean> WRITE_DEPRECATION_LOGS_TO_INDEX = Setting.boolSetting( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should the setting allow to flex between writing to a log, an index, or both ?
Moving to draft status while we reconsider some things. |
server/src/main/java/org/elasticsearch/common/logging/DeprecationIndexingService.java
Outdated
Show resolved
Hide resolved
server/src/main/java/org/elasticsearch/common/logging/DeprecationIndexingService.java
Outdated
Show resolved
Hide resolved
.../rest/src/main/java/org/elasticsearch/xpack/deprecation/TestDeprecationHeaderRestAction.java
Show resolved
Hide resolved
...deprecation/qa/rest/src/test/java/org/elasticsearch/xpack/deprecation/DeprecationHttpIT.java
Show resolved
Hide resolved
@elasticmachine update branch |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it looks really good now. Thank you for working on this.
I left two minor comments.
test/framework/src/main/java/org/elasticsearch/test/ESSingleNodeTestCase.java
Outdated
Show resolved
Hide resolved
import org.apache.logging.log4j.core.config.plugins.PluginFactory; | ||
import org.apache.logging.log4j.message.Message; | ||
|
||
@Plugin(name = "HeaderWarningAppender", category = Core.CATEGORY_NAME, elementType = Appender.ELEMENT_TYPE) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pugnascotia any views on creating a logger?
@elasticmachine update branch |
@rjernst @jakelandis CI is now green, can you please take another look? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left a couple comments, but overall, would it be possible to split this up? The change pretty large, and doing several things, which I think are semi unrelated concerns:
- Using log4j as backend of deprecation logs
- Using log4j as backend of header warnings
- Adding deprecation log messages from log4j to a data stream
@@ -9,6 +8,15 @@ esplugin { | |||
} | |||
archivesBaseName = 'x-pack-deprecation' | |||
|
|||
// add all sub-projects of the qa sub-project | |||
gradle.projectsEvaluated { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this necessary?
@@ -0,0 +1,8 @@ | |||
appender.header_warning.type = HeaderWarningAppender |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain why this file is needed?
import org.apache.logging.log4j.core.config.plugins.PluginFactory; | ||
import org.apache.logging.log4j.message.Message; | ||
|
||
@Plugin(name = "HeaderWarningAppender", category = Core.CATEGORY_NAME, elementType = Appender.ELEMENT_TYPE) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm failing to understand what the advantage is of using log4j for header warnings? In either case, the warnings are stored in the thread context still right? Is it for formatting?
If we are going to use it, then I think it should be hidden, like deprecation logging is behind DeprecationLogger. But with header warnings, we already have the HeaderWarning class, and the logger retrieved will be the same for all locations, so we could just do this statically? Using a logger for header warnings directly is odd because the log level doesn't actual matter?
I'm breaking up the PR as follows:
Regarding header warnings: although I thought carefully before reimplementing header warnings with log4j...now I'm not so sure. That part of the work was relatively straightforward, so now I'm thinking that we only go down that road if/when we think we really need to. |
The implementation for indexing deprecation logs to a data stream (#58924) relied on the Stack template for `logs-*-*`. This meant that if the user disabled the stack templates, the templates would also be unavailable for the deprecation logs. Change the implementation so that: * There is a separate template for deprecation logging * The data stream is marked as hidden * The data stream name is prefixed with a period (`.`)
The implementation for indexing deprecation logs to a data stream (elastic#58924) relied on the Stack template for `logs-*-*`. This meant that if the user disabled the stack templates, the templates would also be unavailable for the deprecation logs. Change the implementation so that: * There is a separate template for deprecation logging * The data stream is marked as hidden * The data stream name is prefixed with a period (`.`)
Backport of #64417. The implementation for indexing deprecation logs to a data stream (#58924) relied on the Stack template for `logs-*-*`. This meant that if the user disabled the stack templates, the templates would also be unavailable for the deprecation logs. Change the implementation so that: * There is a separate template for deprecation logging * The data stream is marked as hidden * The data stream name is prefixed with a period (`.`)
Closes #46106. Introduce a mechanism for writing deprecation logs to a data stream as well as to disk.
Test by running
./gradlew run
and then:This implementation reworks deprecation logging to rely on log4j by introducing filters and appenders, and a custom log level. The existing
deprecation
X-Pack plugin simply configures an extra appender to capture messages to an index. A "component" class manages most of the interface between the cluster and the appender.This approach can be extended for other types of logging, e.g. security by introducing further custom log levels.