-
Notifications
You must be signed in to change notification settings - Fork 24.9k
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
Header warning logging refactoring #55941
Conversation
Pinging @elastic/es-core-infra (:Core/Infra/Logging) |
/** | ||
* Logs a message, adding a formatted warning message as a response header on the thread context. | ||
*/ | ||
public void headerWarnAndLog(String msg, Object... params) { |
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 we make this just logAndHeader
I think that is different enough from info
, warn
etc. and you can always look up at the type of logger.
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 we also expose a log
and a header
method ? log = logfile, warn = header
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.
ninja edit - s/warn/header (in case the comments here don't line up with the contents in the email updates)
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.
agree - log and header method will be useful too. Not sure about the header method name though #55941 (comment)
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.
hm at the same time there is no usage for just log/header on its own at the moment.
maybe let's keep that class small for now and add methods as the need arise?
} | ||
} | ||
|
||
public void log(String msg, Object... params) { |
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 this be header
instead of log ?
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.
hm not sure about this one. Wouldn't some verb be better here? addHeader? addHeaderWarning?
or maybe simply log as it is now. The class name and the field name should express the intent
} else { | ||
return ch; | ||
} | ||
public void deprecatedAndMaybeLog(final String key, final String msg, final Object... params) { |
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.
@jakelandis I am also considering renaming these as deprecatedAndMaybe is not clear enough
I think this should be just throttleLogAndWarnOnHeader
and logAndWarnOnHeader
the destination -deprecation log - is clear from the name of the field and class
We discussed this a bit more in person and came to the following conclusions. This refactoring servers two purposes a) expose the ability to emit HTTP warnings back to the client outside of deprecations e.g. #55699 b) provide a means to expose compatibility logging which is very similar to deprecation logging, but slightly different. a) This PR will pull apart the HTTP warming emitter code and allow users to use it separately from the deprecation logger. Something like b) Deprecation logs and compatibility logs and highly related. A deprecation message might say
This allow for easy separation of the messages (as opposed to smashing the two texts to the same message), and does not occur any additional over head of managing yet another log file. To help developers introduce a compatibility message into the deprecation we plan to introduce a fluent api similar to :
So when a developer needs to add a compatibility message, it is easy as adding to the existing deprecrationLogger . note - The above is a proposal and the final outcome may deviate |
@@ -367,8 +366,7 @@ public ClusterState addIndexTemplateV2(final ClusterState currentState, final bo | |||
.map(e -> e.getKey() + " => " + e.getValue()) | |||
.collect(Collectors.joining(",")), | |||
name); | |||
logger.warn(warning); | |||
deprecationLogger.deprecatedAndMaybeLog("index_template_pattern_overlap", warning); | |||
warningLogger.logAndAddWarning(warning); |
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.
this is the usage of the refactoring from this PR.
this log line always log - to server - and adds a warning.
The type might be a bit confusing. Maybe this should 2 lines:
- to log to a server file - regular logger
- add a warning to a headers
@jakelandis wdyt?
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.
++ for 2 lines. We should also probably make ThrottlingAndHeaderWarningLogger
package private.
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.
Changes are looking good. A couple minor comments.
@@ -67,6 +67,7 @@ | |||
|
|||
@Override | |||
public void setUp() throws Exception { | |||
assert "false".equals(System.getProperty("tests.security.manager")) : "-Dtests.security.manager=false has to be set"; |
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.
did this slip in, or is it intentional ?
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.
probably not directly related to the refactoring, but it is useful when running this test from intellij to get that reminder. not obvious from just a failure message why the test failed
@@ -367,8 +366,7 @@ public ClusterState addIndexTemplateV2(final ClusterState currentState, final bo | |||
.map(e -> e.getKey() + " => " + e.getValue()) | |||
.collect(Collectors.joining(",")), | |||
name); | |||
logger.warn(warning); | |||
deprecationLogger.deprecatedAndMaybeLog("index_template_pattern_overlap", warning); | |||
warningLogger.logAndAddWarning(warning); |
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.
++ for 2 lines. We should also probably make ThrottlingAndHeaderWarningLogger
package private.
server/src/main/java/org/elasticsearch/common/logging/DeprecationLogger.java
Show resolved
Hide resolved
server/src/main/java/org/elasticsearch/common/logging/DeprecationLogger.java
Show resolved
Hide resolved
* This class wraps both <code>HeaderWarningLogger</code> and <code>ThrottlingLogger</code> | ||
* which is a common use case across Elasticsearch | ||
*/ | ||
public class ThrottlingAndHeaderWarningLogger { |
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 we make this package private ?
*/ | ||
//TODO fix this | ||
@SuppressLoggerChecks(reason = "safely delegates to logger") | ||
public void logAndAddWarning(String msg, Object... params) { |
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.
as discussed in person, i think this can be removed since we only want to expose the Deprecation logger and the Header warning logger. We want to avoid general usaage of this class and if a user wants to always header warn they can use that method and throttling to the main server log is something that that requires more consideration.
} | ||
} | ||
|
||
void log(Message message) { |
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 think with the following comment: https://github.com/elastic/elasticsearch/pull/55941/files#r421840660 we can make this private.
args = new Object[] { "world", 43, "another argument" }; | ||
} | ||
logger.info(message, args); | ||
// public void checkArgumentsProvidedInConstructor() { |
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.
don't forget to uncomment :)
@elasticmachine run elasticsearch-ci/2 |
@jakelandis I updated the PR as per comments. Re discussion on test cases - The additional throttling test cases for throttling are in |
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.
LGTM ( a couple optional minor doc comments )
|
||
/** | ||
* This is a simplistic logger that adds warning messages to HTTP headers. | ||
* It uses ThreadContext - which is assumed to be one per JVM (except for tests) - to store warning headers. |
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.
This comment (uses ThreadContext ...) is abit confusing. What do I need to do with that knowledge ?
Can you add a usage section to the doc ?
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.
agree, ThreadContext is an implementation detail. I will reword that javadoc
throw new IllegalStateException("Removing unknown ThreadContext not allowed!"); | ||
} | ||
} | ||
private final ThrottlingAndHeaderWarningLogger deprecationLogger; |
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 beef up the class level doc a little bit ? Just a quick mention that it does a throttle log (and what it throttling ..or link to the throttling class) and a warning message. Also a small usage in the description would be great.
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.
good idea, added usage and more detailed javadoc.
Splitting DeprecationLogger into two. HeaderWarningLogger - responsible for adding a response warning headers and ThrottlingLogger - responsible for limiting the duplicated log entries for the same key (previously deprecateAndMaybeLog). Introducing A ThrottlingAndHeaderWarningLogger which is a base for other common logging usages where both response warning header and logging throttling was needed. relates elastic#55699 relates elastic#52369
Splitting DeprecationLogger into two. HeaderWarningLogger - responsible for adding a response warning headers and ThrottlingLogger - responsible for limiting the duplicated log entries for the same key (previously deprecateAndMaybeLog). Introducing A ThrottlingAndHeaderWarningLogger which is a base for other common logging usages where both response warning header and logging throttling was needed. relates #55699 relates #52369 backports #55941
Splitting DeprecationLogger into two. HeaderWarningLogger - responsible for adding a response warning headers and ThrottlingLogger - responsible for limiting the duplicated log entries for the same key (previously deprecateAndMaybeLog).
Introducing A ThrottlingAndHeaderWarningLogger which is a base for other common logging usages where both response warning header and logging throttling was needed.
relates #55699
relates #52369