Skip to content
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

KAFKA-16093: Fix spurious REST-related warnings on Connect startup #15149

Merged
merged 5 commits into from Jan 10, 2024

Conversation

C0urante
Copy link
Contributor

@C0urante C0urante commented Jan 8, 2024

Jira

Committer Checklist (excluded from commit message)

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

Copy link
Contributor

@gharris1727 gharris1727 left a comment

Choose a reason for hiding this comment

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

Oh my... I thought these warnings were here to stay! I've seen them so many times that I couldn't understand what they meant, even though they are very direct about what is incorrect.

Thank you so much for fixing this!

Copy link
Contributor

@gharris1727 gharris1727 left a comment

Choose a reason for hiding this comment

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

LGTM, thanks Chris! No more nuisance stderr from tests!

@C0urante
Copy link
Contributor Author

C0urante commented Jan 9, 2024

Thanks @gharris1727!

I wanted to take a stab at fixing these errors "correctly", i.e., by registering classes instead of instances with the regular and admin ResourceConfig. I've pushed a commit that does this; it's a bit lengthier, but it does work. Let me know what you think; happy to revert and stick with the hack if we'd rather minimize the diff.

adminResources.forEach(adminResourceConfig::register);
adminResourceConfig.register(ConnectExceptionMapper.class);
adminResourceConfig.property(ServerProperties.WADL_FEATURE_DISABLE, true);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This fixes another spurious warning message that gets emitted if the worker is configured with the admin.listeners property.

Copy link
Contributor

Choose a reason for hiding this comment

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

this is some light duplication, perhaps the ResourceConfig constructor and the 4 lines accompanying it (request timeout, jackson, exception mapper, and wadl feature disable) can be deduplicated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call, done. I've also cleaned up the configuration of the adminResourceConfig to hopefully prevent other kinds of duplication-related issues in the future; LMKWYT

@gharris1727 gharris1727 self-requested a review January 9, 2024 17:10
Copy link
Contributor

@gharris1727 gharris1727 left a comment

Choose a reason for hiding this comment

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

I really like this approach, and I agree it's the non-hacky way forward. TIL about AbstractBinder and the dependency injection mechanism that Jersey provides.

In particular I like removing ConnectResource, and making the RestRequestTimeout object mutable instead of having all of the resources themselves mutable.

@@ -159,7 +163,8 @@ public class ConnectorsResourceTest {
public void setUp() throws NoSuchMethodException {
when(serverConfig.topicTrackingEnabled()).thenReturn(true);
when(serverConfig.topicTrackingResetEnabled()).thenReturn(true);
connectorsResource = new ConnectorsResource(herder, serverConfig, restClient);
RestRequestTimeout requestTimeout = () -> RestServer.DEFAULT_REST_REQUEST_TIMEOUT_MS;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: unused

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch, thanks 👍

adminResources.forEach(adminResourceConfig::register);
adminResourceConfig.register(ConnectExceptionMapper.class);
adminResourceConfig.property(ServerProperties.WADL_FEATURE_DISABLE, true);
Copy link
Contributor

Choose a reason for hiding this comment

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

this is some light duplication, perhaps the ResourceConfig constructor and the 4 lines accompanying it (request timeout, jackson, exception mapper, and wadl feature disable) can be deduplicated.

- Deduplicate RestServer instantiation and configuration of ResourceConfig instances
- Remove unused RestRequestTimeout instance from ConnectorsResourceTest
- Fix failing ConnectRestServerTest suite
Copy link
Contributor

@gharris1727 gharris1727 left a comment

Choose a reason for hiding this comment

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

LGTM, thanks Chris!

Copy link
Collaborator

@vamossagar12 vamossagar12 left a comment

Choose a reason for hiding this comment

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

Thanks for looking into these log messages! Added some nit level comments.

@@ -41,18 +41,11 @@ public class HerderRequestHandler {

private final RestClient restClient;

private volatile long requestTimeoutMs;
private final RestRequestTimeout requestTimeout;
Copy link
Collaborator

Choose a reason for hiding this comment

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

The field requestTimeoutMs was made volatile as part of here. I don't think we need it now, but just wanted to understand why was it added over there (you can skip the explanation if it's too complex :) )

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This field is final, it wouldn't make sense to mark it volatile.

The underlying mutable value that it returns from timeoutMs() is still marked volatile in the only non-test implementation here.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I didn't intend to mark the final field as volatile. I wanted to know why the field was marked as volatile in the old PR since you had made the change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, gotcha. The intent was to make it thread-safe since it's likely that writes and reads to/of that value will take place on different threads.

Comment on lines +70 to +78
private class Binder extends AbstractBinder {
@Override
protected void configure() {
bind(herder).to(Herder.class);
bind(restClient).to(RestClient.class);
bind(config).to(RestServerConfig.class);
}
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: We could probably move the class definition to the bottom so that all configureXXXResources method are together

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is true, but not a blocker.

Comment on lines -52 to -54
if (requestTimeoutMs < 1) {
throw new IllegalArgumentException("REST request timeout must be positive");
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I am not sure if this validation was needed in the past as well, but now I don't see it being present. Do you think it's needed?

Copy link
Contributor Author

@C0urante C0urante Jan 10, 2024

Choose a reason for hiding this comment

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

I removed it for two reasons:

  1. This code path is only ever used in testing code
  2. It's unclear that the validation would be safer than allowing negative values. At least on my machine, negative values don't cause any issues with, e.g., ConvertingFutureCallback::get.

*/
package org.apache.kafka.connect.runtime.rest;

public interface RestRequestTimeout {
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: Mark this interface as @FunctionalInterface?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I could see some benefit to this, but it's also not a blocker.

It's also debatable, since this interface may change in the future and we don't want to imply that it can only have exactly one abstract method.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ok. Makes sense.

@C0urante
Copy link
Contributor Author

Thanks @gharris1727!

@vamossagar12 I appreciate the review but none of these seem like blocking comments. Please try to use the "request changes" button sparingly. Thanks!

Test failures appear unrelated and all come from known flaky tests. Merging...

@C0urante C0urante merged commit dbf00bc into apache:trunk Jan 10, 2024
1 check failed
@C0urante C0urante deleted the kafka-16093 branch January 10, 2024 14:03
C0urante added a commit that referenced this pull request Jan 10, 2024
…15149)

Reviewers: Sagar Rao <sagarmeansocean@gmail.com>, Greg Harris <greg.harris@aiven.io>
@vamossagar12
Copy link
Collaborator

@C0urante , hmm okay. I understand those weren't blocker comments and I called them as nits.

showuon pushed a commit to showuon/kafka that referenced this pull request Jan 22, 2024
…pache#15149)

Reviewers: Sagar Rao <sagarmeansocean@gmail.com>, Greg Harris <greg.harris@aiven.io>
yyu1993 pushed a commit to yyu1993/kafka that referenced this pull request Feb 15, 2024
…pache#15149)

Reviewers: Sagar Rao <sagarmeansocean@gmail.com>, Greg Harris <greg.harris@aiven.io>
clolov pushed a commit to clolov/kafka that referenced this pull request Apr 5, 2024
…pache#15149)

Reviewers: Sagar Rao <sagarmeansocean@gmail.com>, Greg Harris <greg.harris@aiven.io>
C0urante added a commit that referenced this pull request May 8, 2024
…15149)

Reviewers: Sagar Rao <sagarmeansocean@gmail.com>, Greg Harris <greg.harris@aiven.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
3 participants