Skip to content

KAFKA-9768: Fix handling of rest.advertised.listener config#8360

Merged
kkonstantine merged 3 commits into
apache:trunkfrom
C0urante:kafka-9768
May 7, 2020
Merged

KAFKA-9768: Fix handling of rest.advertised.listener config#8360
kkonstantine merged 3 commits into
apache:trunkfrom
C0urante:kafka-9768

Conversation

@C0urante

@C0urante C0urante commented Mar 26, 2020

Copy link
Copy Markdown
Contributor

Jira

The rest.advertised.listener config is currently broken as setting it to http when listeners are configured for both https and http will cause the framework to choose whichever of the two listeners is listed first. The changes here attempt to fix this by checking not only that ServerConnector::getName begins with the specified protocol, but also that that protocol is immediately followed by an underscore, which the framework uses as a delimiter between the protocol and the remainder of the connector name.

An existing unit test for the RestServer::advertisedUrl method has been expanded to include a case that fails with the framework in its current state and passes with the changes in this PR.

See

connector.setName(String.format("%s_%s%d", PROTOCOL_HTTPS, hostname, port));
and
connector.setName(String.format("%s_%s%d", PROTOCOL_HTTP, hostname, port));
for how the framework sets the name for the ServerConnector instances it creates.

Committer Checklist (excluded from commit message)

  • Verify design and implementation
  • Verify test coverage and CI build status
  • Verify documentation (including upgrade notes)

@C0urante

Copy link
Copy Markdown
Contributor Author

@rhauch @kkonstantine would you mind taking a look at this when you have a chance?

@kkonstantine kkonstantine 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.

The fix seems adequate as a bugfix, although the name is not set by Jetty.

The name is a convention which is set by us in the same class (see Connector#setName). That's where the underscore is used as a delimiter. Unless I'm missing some log message, the connector name probably doesn't even need to contain the hostname and the port. In fact for the admin server, the connector name is just Admin.

We could consider setting the name to something that we'd match exactly and in a unique way with a mapping or enum to the protocol.
For example names Secured, Plain, Admin for https, http only and admin.

@C0urante

Copy link
Copy Markdown
Contributor Author

Yes @kkonstantine, I'd updated the description of the PR a few hours before you left your comment linking to the LOC in the RestServer class that determined the name for the Jetty Connector instances.

I don't see a significant advantage to adding an enum or changing how the Connector instances are named as long as we have a guarantee of correctness and a guard against regression, which we do in the form of unit tests for the advertised URL logic.

It would probably have been cleaner to implement this logic initially with an enum or some other strict mapping, but it'd probably introduce more risk than it'd be worth to do that now for what is intended to be a small bug fix.

@kkonstantine

Copy link
Copy Markdown
Contributor

As I mentioned, this fix looks sufficient to me to fix the bug and get backported at the moment.

The ideal solution, without going into implementation details, would be a way to have an exact match from protocol to connector, given that the connector name can be anything. Again, not suggested for this PR.

@C0urante have you checked whether this issue has a configuration workaround (whether the order of listeners matters) and whether it's a regression (and since when) or it's been like that since the ssl endpoint was introduced?

@C0urante

Copy link
Copy Markdown
Contributor Author

The ideal solution, without going into implementation details, would be a way to have an exact match from protocol to connector, given that the connector name can be anything. Again, not suggested for this PR.

Understood, I'm still skeptical that it'd be beneficial to perform this refactoring any time soon without any functional changes to the Connect REST server to warrant them. But if someone else wants to take on that work and they can do it without breaking anything, it'd certainly make the code base easier to read.

have you checked whether this issue has a configuration workaround (whether the order of listeners matters)

Yep, the order of listeners can be used as a workaround. Added to the ticket.

and whether it's a regression (and since when) or it's been like that since the ssl endpoint was introduced?

It's been like that since the SSL endpoint was introduced; the blame is a little misleading since @wicknicks did some work on the REST server to add the admin listener, but the bug was present before that work as well. Also added to the ticket, along with a specific version number (1.1.0).

@C0urante

C0urante commented Mar 26, 2020

Copy link
Copy Markdown
Contributor Author

Thanks for the discussion, @kkonstantine and @rhauch. I've added a Javadoc to the findConnector method that outlines its use, and an internal comment to that method explaining how the server connector names are used, how they're formatted, and that the logic for the method would need to be changed if the formatting for the server connector names were ever altered.

How does this look?

@kkonstantine

Copy link
Copy Markdown
Contributor

ok to test

@rhauch rhauch 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.

One more nit, just to clarify the intention in the test.

Co-Authored-By: Randall Hauch <rhauch@gmail.com>
@C0urante

C0urante commented Apr 1, 2020

Copy link
Copy Markdown
Contributor Author

Thanks @rhauch, I've accepted the suggestion.

@kkonstantine kkonstantine 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.

This LGTM now.

@kkonstantine

Copy link
Copy Markdown
Contributor

retest this please

@kkonstantine

Copy link
Copy Markdown
Contributor

Only a couple streams integration test failures in every jdk.
These are unrelated to this PR, so I'm merging.
Thanks for the fix @C0urante !

@kkonstantine
kkonstantine merged commit 29dd114 into apache:trunk May 7, 2020
kkonstantine pushed a commit that referenced this pull request May 7, 2020
The rest.advertised.listener config is currently broken as setting it to http when listeners are configured for both https and http will cause the framework to choose whichever of the two listeners is listed first. The changes here attempt to fix this by checking not only that ServerConnector::getName begins with the specified protocol, but also that that protocol is immediately followed by an underscore, which the framework uses as a delimiter between the protocol and the remainder of the connector name.

An existing unit test for the RestServer::advertisedUrl method has been expanded to include a case that fails with the framework in its current state and passes with the changes in this commit. 

* KAFKA-9768: Fix handling of rest.advertised.listener config
* KAFKA-9768: Add comments on server connector names
* KAFKA-9768: Update RestServerTest comment

Co-authored-by: Randall Hauch <rhauch@gmail.com>

Reviewers: Randall Hauch <rhauch@gmail.com>, Konstantine Karantasis <konstantine@confluent.io>, Andrew Choi <andchoi@linkedin.com>
kkonstantine pushed a commit that referenced this pull request May 7, 2020
The rest.advertised.listener config is currently broken as setting it to http when listeners are configured for both https and http will cause the framework to choose whichever of the two listeners is listed first. The changes here attempt to fix this by checking not only that ServerConnector::getName begins with the specified protocol, but also that that protocol is immediately followed by an underscore, which the framework uses as a delimiter between the protocol and the remainder of the connector name.

An existing unit test for the RestServer::advertisedUrl method has been expanded to include a case that fails with the framework in its current state and passes with the changes in this commit. 

* KAFKA-9768: Fix handling of rest.advertised.listener config
* KAFKA-9768: Add comments on server connector names
* KAFKA-9768: Update RestServerTest comment

Co-authored-by: Randall Hauch <rhauch@gmail.com>

Reviewers: Randall Hauch <rhauch@gmail.com>, Konstantine Karantasis <konstantine@confluent.io>, Andrew Choi <andchoi@linkedin.com>
Kvicii pushed a commit to Kvicii/kafka that referenced this pull request May 7, 2020
* 'trunk' of github.com:apache/kafka: (87 commits)
  KAFKA-9865: Expose output topic names from TopologyTestDriver (apache#8483)
  MINOR - Increase the number of Trogdor Histogram buckets to 10000 (apache#8627)
  KAFKA-9768: Fix handling of rest.advertised.listener config (apache#8360)
  KAFKA-9419: Fix possible integer overflow in CircularIterator (apache#7950)
  MINOR: Only add 'Data' suffix for generated request/response/header types (apache#8625)
  KAFKA-9947; Ensure proper shutdown of services in `TransactionsBounceTest` (apache#8602)
  KAFKA-6342; Remove unused workaround for JSON parsing of non-escaped strings (apache#8591)
  MINOR: Pass `-release 8` to scalac and upgrade to Gradle 6.4 (apache#8538)
  KAFKA-9946; Partition deletion event should only be sent if deletion was requested in the StopReplica request (apache#8609)
  MINOR: Improve TopologyTestDriver JavaDocs (apache#8619)
  MINOR: MockAdminClient should return InvalidReplicationFactorException if brokers.size < replicationFactor
  KAFKA-9748: Add Streams eos-beta integration test (apache#8496)
  KAFKA-9731: Disable immediate fetch response for hw propagation if replica selector is not defined (apache#8607)
  HOTFIX: set correct numIterations in shouldAllowConcurrentAccesses
  MINOR: Clean up some test dependencies on ConfigCommand and TopicCommand (apache#8527)
  KAFKA-9918; SslEngineFactory is NOT closed when channel is closing (apache#8551)
  KAFKA-9798: Send one round synchronously before starting the async producer (apache#8565)
  MINOR: Annotate KafkaAdminClientTest.testAlterClientQuotas() with @test
  KAFKA-9589: Enable testLogAppendTimeNonCompressedV2 and fix bug in helper method (apache#8533)
  MINOR: Use min/max function when possible (apache#8577)
  ...

# Conflicts:
#	core/src/main/scala/kafka/log/Log.scala
#	gradle/dependencies.gradle
#	gradle/wrapper/gradle-wrapper.properties
#	gradlew
qq619618919 pushed a commit to qq619618919/kafka that referenced this pull request May 12, 2020
)

The rest.advertised.listener config is currently broken as setting it to http when listeners are configured for both https and http will cause the framework to choose whichever of the two listeners is listed first. The changes here attempt to fix this by checking not only that ServerConnector::getName begins with the specified protocol, but also that that protocol is immediately followed by an underscore, which the framework uses as a delimiter between the protocol and the remainder of the connector name.

An existing unit test for the RestServer::advertisedUrl method has been expanded to include a case that fails with the framework in its current state and passes with the changes in this commit. 

* KAFKA-9768: Fix handling of rest.advertised.listener config
* KAFKA-9768: Add comments on server connector names
* KAFKA-9768: Update RestServerTest comment

Co-authored-by: Randall Hauch <rhauch@gmail.com>

Reviewers: Randall Hauch <rhauch@gmail.com>, Konstantine Karantasis <konstantine@confluent.io>, Andrew Choi <andchoi@linkedin.com>
jwijgerd pushed a commit to buxapp/kafka that referenced this pull request May 14, 2020
)

The rest.advertised.listener config is currently broken as setting it to http when listeners are configured for both https and http will cause the framework to choose whichever of the two listeners is listed first. The changes here attempt to fix this by checking not only that ServerConnector::getName begins with the specified protocol, but also that that protocol is immediately followed by an underscore, which the framework uses as a delimiter between the protocol and the remainder of the connector name.

An existing unit test for the RestServer::advertisedUrl method has been expanded to include a case that fails with the framework in its current state and passes with the changes in this commit. 

* KAFKA-9768: Fix handling of rest.advertised.listener config
* KAFKA-9768: Add comments on server connector names
* KAFKA-9768: Update RestServerTest comment

Co-authored-by: Randall Hauch <rhauch@gmail.com>

Reviewers: Randall Hauch <rhauch@gmail.com>, Konstantine Karantasis <konstantine@confluent.io>, Andrew Choi <andchoi@linkedin.com>
@C0urante
C0urante deleted the kafka-9768 branch February 27, 2022 03:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants