- Notifications
You must be signed in to change notification settings - Fork 25.6k
Deprecation message for lenient Boolean parsing #137885
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
base: main
Are you sure you want to change the base?
Conversation
| Pinging @elastic/es-core-infra (Team:Core/Infra) |
| Hi @mamazzol, I've created a changelog YAML for you. Note that since this PR is labelled |
| Hi @mamazzol, I've updated the changelog YAML for you. |
mosche left a 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.
Thanks @mamazzol, a couple of points below.
That's a lot less places than I feared to see 😅 And I think some of these could actually be lenient for good.
| @SuppressForbidden(reason = "wrap lenient parsing of booleans for deprecation logging.") | ||
| public static boolean parseBoolean(String value) { | ||
| if ("true".equals(value) == false && "false".equals(value) == false) { | ||
| String key = "Boolean#parseBoolean"; |
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 mentioned above, this isn't too actionable for customers and would just result in large amount of support cases. I think we have to mention the following parts in the deprecation warning
- where exactly it happened
- what the wrong value is
- what the correct value looks like (true / false)
| + "This is discouraged in Elasticsearch as it treats all values different than 'true' as false. " | ||
| + "The strict method from Booleans util class should be used instead."; |
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 we need to direct this message more to customers, and more clearly advise them what to use instead. Maybe something like this
Usage of lenient booleans for [{}] [setting | header | system property] such as [{}] was deprecated. Future releases of Elasticsearch may only accept `true` or `false`. | | ||
| @SuppressForbidden(reason = "wrap lenient parsing of booleans for deprecation logging.") | ||
| public static boolean parseBoolean(String value) { | ||
| if ("true".equals(value) == false && "false".equals(value) == false) { |
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.
Booleans.isBoolean(value) == false?
| @SuppressForbidden( | ||
| reason = "TODO Deprecate any lenient usage of Boolean#parseBoolean https://github.com/elastic/elasticsearch/issues/128993" | ||
| ) | ||
| private static boolean getDetectMissingParamsOption(Map<String, String> options) { |
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.
@jdconrad Do you know if options is exposed to users. Could we just switch to strict boolean parsing here?
| ) | ||
| private static boolean parseBoolean(String value) { | ||
| return Boolean.parseBoolean(value); | ||
| return Booleans.parseBoolean(value); |
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.
@jdconrad Do you know if params is exposed to users. Could we just switch to strict boolean parsing here?
| ) | ||
| private static boolean useG1GC() { | ||
| return Boolean.parseBoolean(JvmInfo.jvmInfo().useG1GC()); | ||
| return org.elasticsearch.common.util.Booleans.parseBoolean(JvmInfo.jvmInfo().useG1GC()); |
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.
| String useG1GC = "unknown"; |
Based on above, we probably should use Booleans.parseBooleanLenient
| ) | ||
| private static boolean preferIPv6Addresses() { | ||
| return Boolean.parseBoolean(System.getProperty("java.net.preferIPv6Addresses", "false")); | ||
| return Booleans.parseBoolean(System.getProperty("java.net.preferIPv6Addresses", "false")); |
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.
The JVM does lenient parsing for these, should actually be fine to match that behavior here and switch to parseBooleanLenient
| import org.elasticsearch.common.logging.DeprecationLogger; | ||
| import org.elasticsearch.core.SuppressForbidden; | ||
| | ||
| public class Booleans { |
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.
Naming this similar to the "proper" Booleans.parseBoolean might lead to confusion (particularly for reviewers), and potentially we'd end up introducing deprecations in new places for no reason.
i can't think of a great name, though.... maybe LenientBooleans.parseAndCheckForDeprecatedUsage or something in that direction
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 should also be annotated with UpdateForV10 so we remember to remove the deprecated behavior for the next major.
| Hi @mamazzol, I've updated the changelog YAML for you. Note that since this PR is labelled |
| ) | ||
| private static boolean getErrorTraceHeader(ThreadPool threadPool) { | ||
| return Boolean.parseBoolean(threadPool.getThreadContext().getHeaderOrDefault("error_trace", "false")); | ||
| return Booleans.parseBoolean(threadPool.getThreadContext().getHeaderOrDefault("error_trace", "false")); |
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.
Having a closer look, this should already be validated by the rest controller, see in RestRequest and ThreadContext. I think we can switch to strict parsing here.
@Override public boolean paramAsBoolean(String key, boolean defaultValue) { String rawParam = param(key); // Treat empty string as true because that allows the presence of the url parameter to mean "turn this on" if (rawParam != null && rawParam.length() == 0) { return true; } else { return Booleans.parseBoolean(rawParam, defaultValue); } } public void setErrorTraceTransportHeader(RestRequest r) { // set whether data nodes should send back stack trace based on the `error_trace` query parameter if (r.paramAsBoolean("error_trace", RestController.ERROR_TRACE_DEFAULT)) { // We only set it if error_trace is true (defaults to false) to avoid sending useless bytes putHeader("error_trace", "true"); } }| pr: 137885 | ||
| summary: Deprecation message for lenient Boolean parsing | ||
| area: Infra/Logging | ||
| type: deprecation | ||
| issues: [] | ||
| deprecation: | ||
| title: Deprecation message for lenient Boolean parsing | ||
| area: Infra/Logging | ||
| details: Please describe the details of this change for the release notes. You can | ||
| use asciidoc. | ||
| impact: Please describe the impact of this change to users |
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.
Just a sketch, depending on the final impl ...
| pr: 137885 | |
| summary: Deprecation message for lenient Boolean parsing | |
| area: Infra/Logging | |
| type: deprecation | |
| issues: [] | |
| deprecation: | |
| title: Deprecation message for lenient Boolean parsing | |
| area: Infra/Logging | |
| details: Please describe the details of this change for the release notes. You can | |
| use asciidoc. | |
| impact: Please describe the impact of this change to users | |
| pr: 137885 | |
| summary: Add deprecation for usage of lenient booleans for analysis boolean setting (3rd party plugins) and boolean system properties. | |
| area: Infra/Logging | |
| type: deprecation | |
| issues: | |
| - 128993 | |
| deprecation: | |
| title: Add deprecation for usage of lenient booleans for analysis boolean setting (3rd party plugins) and boolean system properties. | |
| area: Infra/Logging | |
| details: Usage of lenient booleans was deprecated for analysis boolean setting in external plugins using the stable plugin API and various boolean system properties. | |
| impact: Usage of lenient booleans other than `true` or `false` will result in deprecations logs and corresponding header warnings. Future releases of ES may only accept strict boolean values `true` or `false. |
Wrapping user-facing usages of Boolean.parseBoolean in a util method to send a deprecation log.
#128993