Skip to content

KAFKA-17164: Enforce 'application.server' <server>:<port> format at config level.#22202

Open
chickenchickenlove wants to merge 6 commits into
apache:trunkfrom
chickenchickenlove:KAFKA-17164
Open

KAFKA-17164: Enforce 'application.server' <server>:<port> format at config level.#22202
chickenchickenlove wants to merge 6 commits into
apache:trunkfrom
chickenchickenlove:KAFKA-17164

Conversation

@chickenchickenlove

@chickenchickenlove chickenchickenlove commented May 4, 2026

Copy link
Copy Markdown
Contributor

Description

This PR implement
KIP-1245,
which enforces the application.server host:port format during
StreamsConfig construction.

Changes

  • Add a ConfigDef.Validator for application.server to fail fast on
    invalid values in StreamsConfig instead of later in HostInfo.
  • Update an existing StreamsConfigTest case to use a valid
    application.server value.
  • Add test coverage for valid and invalid application.server values.

Reviewers: Matthias J. Sax matthias@confluent.io

@github-actions github-actions Bot added streams triage PRs from the community small Small PRs labels May 4, 2026
@chickenchickenlove

Copy link
Copy Markdown
Contributor Author

Hi, @Nikita-Shupletsov !

It’s been a while since we last spoke.
I opened a PR for KIP-1245, which we discussed earlier!
When you get a chance, please take a look 🙇‍♂️

@nileshkumar3 nileshkumar3 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chickenchickenlove thanks for the PR. I have a very minor comment.


final String endPoint = (String) value;

if (endPoint.isEmpty()) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is redundant , Utils.isBlank(endPoint) covers this.

@chickenchickenlove

Copy link
Copy Markdown
Contributor Author

@nileshkumar3 Thanks for the time to take a look!
I've addressed it based on your comments.
When you get a chance, please take another look.

@Nikita-Shupletsov Nikita-Shupletsov left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the PR!
left a few comments


private static final ConfigDef.Validator INSTANCE = new ApplicationServerConfigValidator();

public static ConfigDef.Validator getInstance() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to catch NumberFormatException? looks like HOST_PORT_PATTERN already checks that it's exclusively digits

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pattern only says the port looks like digits. Integer.parseInt still errors if that number is too big for a int.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it makes sense. would it make sense to tighten the regex instead?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure about a KIP for a change that, effectively, fixes a bug.
@mjsax could you please chime in? thank you

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see.
Thanks for your comments, Nikita and mjsax!
I'll keep it as it is.

@github-actions github-actions Bot removed the triage PRs from the community label May 5, 2026
@chickenchickenlove

Copy link
Copy Markdown
Contributor Author

@Nikita-Shupletsov
Thanks for the time to take a look into this PR.
I've addressed it based on your comments!
When you get a chance, please take another look!

import org.apache.kafka.common.config.ConfigException;
import org.apache.kafka.common.utils.Utils;


Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: extra empty line

@chickenchickenlove

Copy link
Copy Markdown
Contributor Author

@Nikita-Shupletsov
Thanks for your quick feedback!
I've removed empty line and left reply for your comments!
When you get a chance, please take a look! 🙇‍♂️

@Nikita-Shupletsov Nikita-Shupletsov left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. thank you!

final Integer port;
try {
port = getPort(endPoint);
} catch (final NumberFormatException e) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure about a KIP for a change that, effectively, fixes a bug.
@mjsax could you please chime in? thank you

@nileshkumar3 nileshkumar3 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks.

@chickenchickenlove

Copy link
Copy Markdown
Contributor Author

@mjsax
Sorry to bother you.
When you get a chance, could you take a look?

@mjsax mjsax left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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"})

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add ":8080" as one more test? Maybe also ":" ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your comments.
I've added them!

final Integer port;
try {
port = getPort(endPoint);
} catch (final NumberFormatException e) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

@chickenchickenlove

Copy link
Copy Markdown
Contributor Author

@mjsax
Thanks for the review!

Just wondering, if HostInfo#buildFromEndpoint() and the new validator (both duplicate the same code) could be unified?

I've addressed it!
I have a question.
Could you let me know which release this KIP is planned for?
I'd like to update docs/streams/upgrade-guide.md accordingly for that release.

@mjsax mjsax left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@mjsax mjsax added the kip Requires or implements a KIP label Jun 19, 2026
@chickenchickenlove

Copy link
Copy Markdown
Contributor Author

@mjsax
Thanks for your comments!
I've added it to docs sections.
Also, I've rebased on the latest trunk because CI was failed due to 1 password error.
When you get a chance, please take another look. 🙇‍♂️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kip Requires or implements a KIP small Small PRs streams

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants