KAFKA-17164: Enforce 'application.server' <server>:<port> format at config level.#22202
KAFKA-17164: Enforce 'application.server' <server>:<port> format at config level.#22202chickenchickenlove wants to merge 6 commits into
Conversation
|
Hi, @Nikita-Shupletsov ! It’s been a while since we last spoke. |
nileshkumar3
left a comment
There was a problem hiding this comment.
@chickenchickenlove thanks for the PR. I have a very minor comment.
|
|
||
| final String endPoint = (String) value; | ||
|
|
||
| if (endPoint.isEmpty()) { |
There was a problem hiding this comment.
This is redundant , Utils.isBlank(endPoint) covers this.
|
@nileshkumar3 Thanks for the time to take a look! |
Nikita-Shupletsov
left a comment
There was a problem hiding this comment.
Thank you for the PR!
left a few comments
|
|
||
| private static final ConfigDef.Validator INSTANCE = new ApplicationServerConfigValidator(); | ||
|
|
||
| public static ConfigDef.Validator getInstance() { |
There was a problem hiding this comment.
is it worth having it as a singleton?
I checked a few places(e.g. https://github.com/apache/kafka/blob/trunk/connect/runtime/src/main/java/org/apache/kafka/connect/runtime/TopicCreationConfig.java#L128) and it looks like we don't really do that anywhere else
| import org.apache.kafka.common.config.ConfigException; | ||
| import org.apache.kafka.common.utils.Utils; | ||
|
|
||
| import static org.apache.kafka.common.utils.Utils.getHost; |
There was a problem hiding this comment.
nit: some methods from this class are imported statically, some are called via Utils.method
| final Integer port; | ||
| try { | ||
| port = getPort(endPoint); | ||
| } catch (final NumberFormatException e) { |
There was a problem hiding this comment.
do we need to catch NumberFormatException? looks like HOST_PORT_PATTERN already checks that it's exclusively digits
There was a problem hiding this comment.
The pattern only says the port looks like digits. Integer.parseInt still errors if that number is too big for a int.
There was a problem hiding this comment.
When a very large number is provided as the port number, HOST_PORT_PATTERN.matcher(...) operates normally. However, when Integer.parseInt() is called on such a large number, a NumberFormatException is thrown.
While HostInfo would have previously thrown a NumberFormatException for large numbers as well, we now catch the NumberFormatException in order to throw a ConfigException, as described in the KIP.
There was a problem hiding this comment.
it makes sense. would it make sense to tighten the regex instead?
There was a problem hiding this comment.
It might be better, but I would prefer to do it in other PR.
This is because Utils.getPort(...) is not only used for HostInfo but also QuorumConfig, etc.
If we want to tighten the regex, I think another KIP is required.
There was a problem hiding this comment.
I am not sure about a KIP for a change that, effectively, fixes a bug.
@mjsax could you please chime in? thank you
There was a problem hiding this comment.
If we want to tighten the regex, I think another KIP is required.
I don't think so. I think the simplest fix would be, to push the try-catch into getPort() and let it return null if a NumberFormatException gets thrown? This would still align to the intended semantics of getPort() to return null if the port is not valid.
This would really just be a simple bug-fix (and messing with the regex-ex is always a mess, so maybe just catching the exception is simpler).
There was a problem hiding this comment.
I see.
Thanks for your comments, Nikita and mjsax!
I'll keep it as it is.
|
@Nikita-Shupletsov |
| import org.apache.kafka.common.config.ConfigException; | ||
| import org.apache.kafka.common.utils.Utils; | ||
|
|
||
|
|
There was a problem hiding this comment.
nit: extra empty line
|
@Nikita-Shupletsov |
Nikita-Shupletsov
left a comment
There was a problem hiding this comment.
LGTM. thank you!
| final Integer port; | ||
| try { | ||
| port = getPort(endPoint); | ||
| } catch (final NumberFormatException e) { |
There was a problem hiding this comment.
I am not sure about a KIP for a change that, effectively, fixes a bug.
@mjsax could you please chime in? thank you
|
@mjsax |
mjsax
left a comment
There was a problem hiding this comment.
Thanks for the PR. Overall LGTM.
Just wondering, if HostInfo#buildFromEndpoint() and the new validator (both duplicate the same code) could be unified?
| } | ||
|
|
||
| @ParameterizedTest | ||
| @ValueSource(strings = {"dummy:host", "dummy:9999999999999999999999999", "dummy", "dummy:", ":port"}) |
There was a problem hiding this comment.
Should we add ":8080" as one more test? Maybe also ":" ?
There was a problem hiding this comment.
Thanks for your comments.
I've added them!
| final Integer port; | ||
| try { | ||
| port = getPort(endPoint); | ||
| } catch (final NumberFormatException e) { |
There was a problem hiding this comment.
If we want to tighten the regex, I think another KIP is required.
I don't think so. I think the simplest fix would be, to push the try-catch into getPort() and let it return null if a NumberFormatException gets thrown? This would still align to the intended semantics of getPort() to return null if the port is not valid.
This would really just be a simple bug-fix (and messing with the regex-ex is always a mess, so maybe just catching the exception is simpler).
|
@mjsax
I've addressed it! |
mjsax
left a comment
There was a problem hiding this comment.
Thanks for the PR. LGTM.
As the PR is ready for merging, it will go into 4.4.0 release. Good callout to also update the upgrade guide section accordingly. Can merge after the docs update was added to this PR.
4c42ecc to
62e9071
Compare
|
@mjsax |
Description
This PR implement
KIP-1245,
which enforces the
application.serverhost:port format duringStreamsConfigconstruction.Changes
ConfigDef.Validatorforapplication.serverto fail fast oninvalid values in
StreamsConfiginstead of later inHostInfo.StreamsConfigTestcase to use a validapplication.servervalue.application.servervalues.Reviewers: Matthias J. Sax matthias@confluent.io