Add some deprecation optimizations#37597
Conversation
This commit optimizes some of the performance issues from using deprecation logging: - we optimize encoding the deprecation value - we optimize formatting the deprecation string - we optimize away getting the current time (by using cached startup time)
|
Pinging @elastic/es-core-infra |
|
@elasticmachine run gradle build tests 1 |
danielmitterdorfer
left a comment
There was a problem hiding this comment.
Thanks for tackling this. I left a few comments.
| * We want a fast path check to avoid creating the string builder and copying characters if needed. So we walk the string looking | ||
| * for either of the characters that we need to escape. If we find a character that needs escaping, we start over and | ||
| */ | ||
| boolean encodingNeeded = false; |
There was a problem hiding this comment.
I think this variable should be name escapingNeeded as this method is concerned with escaping special characters but not encoding (which is done separately)?
| return String.format(Locale.ROOT, WARNING_FORMAT, escapeAndEncode(s), RFC_7231_DATE_TIME.format(ZonedDateTime.now(GMT))); | ||
| return WARNING_PREFIX + " " | ||
| + "\"" + escapeAndEncode(s) + "\"" + " " | ||
| + "\"" + STARTUP_TIME + "\""; |
There was a problem hiding this comment.
maybe rewrite as
return WARNING_PREFIX + " \"" + escapeAndEncode(s) + "\" \"" + STARTUP_TIME + "\"";
Or did you think it is too subtle to miss the required spaces in between? Either way, I don't feel too strongly about it.
There was a problem hiding this comment.
Yes, what is here is clearer IMO, and the compiler will fold the constants anyway (so fold " " and "\"" into " \"", and "\"" and " " and "\"" into "\" \"" so that the number of invocations to StringBuilder#append will be reduced).
| return String.format(Locale.ROOT, WARNING_FORMAT, escapeAndEncode(s), RFC_7231_DATE_TIME.format(ZonedDateTime.now(GMT))); | ||
| return WARNING_PREFIX + " " | ||
| + "\"" + escapeAndEncode(s) + "\"" + " " | ||
| + "\"" + STARTUP_TIME + "\""; |
There was a problem hiding this comment.
I also find it a bit odd to always use STARTUP_TIME as the value for warn-date but on the other hand I did not find anything in RFC 7234 that forbids doing that.
There was a problem hiding this comment.
Ultimately I want to remove the warn-date from the header. It's not required by the specification (it's optional). However, removing it requires coordinating with Kibana which parses these warning headers for displaying in Console (elastic/kibana#10470). So here I eliminate the performance issue to show the advantages (otherwise, it does show up in profiling output, ~15%).
There was a problem hiding this comment.
I'm fine with that, it just puzzled me in the beginning.
| @@ -157,14 +157,13 @@ public void deprecatedAndMaybeLog(final String key, final String msg, final Obje | |||
| * arbitrary token; here we use the Elasticsearch version and build hash. The warn text must be quoted. The warn-date is an optional | |||
| * quoted field that can be in a variety of specified date formats; here we use RFC 1123 format. | |||
There was a problem hiding this comment.
Only semi-related to your PR but I think the RFC mentioned in this comment is wrong and it should say "RFC 7231 format" instead of "RFC 1123 format".
| public static String formatWarning(final String s) { | ||
| return String.format(Locale.ROOT, WARNING_FORMAT, escapeAndEncode(s), RFC_7231_DATE_TIME.format(ZonedDateTime.now(GMT))); | ||
| return WARNING_PREFIX + " " | ||
| + "\"" + escapeAndEncode(s) + "\"" + " " |
There was a problem hiding this comment.
Unrelated to your PR: While I am not aware that any RFC specifies a maximum field length for HTTP headers there are practical limits and I wonder whether we should enforce one (in a follow-up) as deprecation messages might be long?
|
@elasticmachine run gradle build tests 2 |
1 similar comment
|
@elasticmachine run gradle build tests 2 |
|
@elasticmachine run gradle builds tests 2 |
|
@elasticmachine run gradle build tests 2 |
1 similar comment
|
@elasticmachine run gradle build tests 2 |
This commit optimizes some of the performance issues from using deprecation logging: - we optimize encoding the deprecation value - we optimize formatting the deprecation string - we optimize away getting the current time (by using cached startup time)
* elastic/master: (104 commits) Permission for restricted indices (elastic#37577) Remove Watcher Account "unsecure" settings (elastic#36736) Add cache cleaning task for ML snapshot (elastic#37505) Update jdk used by the docker builds (elastic#37621) Remove an unused constant in PutMappingRequest. Update get users to allow unknown fields (elastic#37593) Do not add index event listener if CCR disabled (elastic#37432) Add local session timeouts to leader node (elastic#37438) Add some deprecation optimizations (elastic#37597) refactor inner geogrid classes to own class files (elastic#37596) Remove obsolete deprecation checks (elastic#37510) ML: Add support for single bucket aggs in Datafeeds (elastic#37544) ML: creating ML State write alias and pointing writes there (elastic#37483) Deprecate types in the put mapping API. (elastic#37280) [ILM] Add unfollow action (elastic#36970) Packaging: Update marker used to allow ELASTIC_PASSWORD (elastic#37243) Fix setting openldap realm ssl config Document the need for JAVA11_HOME (elastic#37589) SQL: fix object extraction from sources (elastic#37502) Nit in settings.gradle for Eclipse ...
| doesNotNeedEncoding.set(i); | ||
| } | ||
| assert !doesNotNeedEncoding.get('%'); | ||
| assert doesNotNeedEncoding.get('%') == false : doesNotNeedEncoding; |
This commit optimizes some of the performance issues from using deprecation logging:
Relates #35754
Relates #37530