KAFKA-15563: Provide informative error messages when Connect REST requests time out#14562
Conversation
|
@gharris1727 @yashmayya I'd be interested in your thoughts on this one if/when you have time. I've heard several complaints from Kafka Connect users about REST requests timing out and want to make that easier on everyone involved, but I'm also conscious that if we're not careful about this kind of change, it can present a serious maintenance burden on the project. I've tried to implement this in a way to reduce impact on the signal-to-noise ratio in critical parts of the codebase (i.e., |
|
I've run into some issues with integration tests on Jenkins. I'm experimenting now with some potential fixes, and the rest of the PR should still be ready for review in the meantime. We should make sure that there's at least one (if not several) Jenkins run with no Connect integration test failures that appear caused by these changes before merging. |
|
Hey @C0urante thanks for taking this on! This is certainly an interesting first pass at the problem, and I share your concerns about the maintenance burden and SNR. One of the things that I think may be causing some friction for the implementation is that the granularity of the Stages doesn't match the granularity of the actual tick thread & herder requests. What I mean to say is that one function has multiple different stages associated with it, instead of there being a 1:1 relationship. Perhaps the design could be simpler if each code-block was given a description of what it did statically, like a new String argument to addRequest. This would be significantly less granular than the current implementation, but we could refactor the control flow of current requests into multiple smaller requests to improve the granularity. This could also be beneficial for the structure of the herder tick thread depending on how we refactor it. We could either wait to implement the improved error messages after such a refactor, or land the low granularity error messages with a plan to improve them. Refactoring the herder requests into smaller sub-units may also be too involved and have even worse ROI, i'm not sure. Also just some smells that I picked up on:
|
|
Thanks Greg. To be clear, this isn't really a first pass--it's the first published one :) With regards to giving each request a single scope--this would fail to capture blocking operations outside of the request (such as other requests, ensuring group membership, and reading to the end of the config topic). I suppose we could do something similar where we decompose As far as breaking down herder requests into several smaller requests goes, I don't think it's wise to do this when not absolutely necessary. The only reason we added that kind of decomposition in #8069 was to avoid blocking on interactions with connector plugins that could otherwise disable the herder's work thread. If there are functional benefits to decomposing operations further, then we can and should explore those, but the risk of regression alone outweighs the benefits of doing that solely for cosmetic benefits, not to mention the additional implementation complexity and hit in readability. I don't think this rules out the possibility of trying to add some more scope-based structure to herder requests so that, for example, every request is a series of single-scope method invocations, but I'm also not sure that that approach is realistic since it may increase the odds of inaccurate error messages. I'm also trying to optimize for user benefit with our error messages here. Telling someone that the worker is blocked reading to the end of the config topic is useful; telling someone that the worker is blocked while deleting a connector is less useful, especially if that error message is delivered in response to the request that triggered connector deletion. If we do opt for a different approach, I'd like it if we could add fine-grained error messages with the first PR, and not as a follow-up item. With regards to the so-called "smells":
I explored this approach initially, but it comes with a pretty severe drawback: there's no guarantee that a request that took too long timed out because it was blocked on the herder thread. Connector validation is the biggest example of this, though there's also connector restarts, which currently block on the connector actually completing startup. In cases like these, it could be misleading to users to tell them what the herder thread is doing when that information has no bearing on why their request timed out.
I'm happy to do some benchmarking if we're worried about the performance impact of this approach. I'm personally a little skeptical that setting a new value for the
I think the key point here is that we need to be careful to record stages for potentially-slow operations, which I've tried to do here. But it's true that in the future, if we move things around and forget to wrap a blocking operation with, e.g., a
Aha! I think the last sentence is actually a great, succinct way of justifying this approach. The first reaction most people have to a timeout message like this is to assume (or hope, or pray) that it's a transient problem, and issue one or more requests to retry the operation. The idea here is to provide more and more benefit as the number of retries increase. If you see a single timeout error and then the next request succeeds, it doesn't matter too much why the first one timed out. On the other hand, if your worker is borked and every request is hanging, then this approach (especially with the granularity it provides and the emphasis it makes on capturing potentially-blocking operations) gives a nice head start to diagnosing the problem without having to pore through worker logs first. Still, if we want to be even more informative, we could augment the currently-proposed error message not just with the current stage, but a history of stages and their start (and possibly end) times. IMO this is a bit much for the first patch and it'd be nice to wait for user feedback to see if it's actually necessary, but I wouldn't be opposed to it if others (including you) feel differently. Overall, I think it might be helpful to provide a few principles I've tried to satisfy with this approach and see if they're agreeable:
|
This is a much better way to put it, and captures what I was going for :)
👍
I don't think there would be a functional change, but I think that readability could be improved. I do understand your concern about regressions, and I worry if this code has become too difficult and risky to change to attempt such refactors. It will only get worse as time goes on.
Thanks for this clarification. A request can be blocked on various threads during it's lifetime, not just the herder tick thread.
I completely agree, this single operation should be lightweight such that we can perform thousands of them and not meaningfully change the runtime of the overall request. You could do benchmarking to prove that, but I don't think you have to spend the time doing that if you change the asymptotic behavior.
I should have clarified: it's quadratic in the number of requests, not the stages per request. Here's the situation: If the requests all come in at once, and the Q=N initially, then this happens: So the longer the queue is, the more work the herder has to do. It's a very weak positive feedback loop. I think you can eliminate it with a layer of indirection. If instead of storing a Stage in the callback, you could store a Supplier that retrieves the tickThreadStage. You would set the supplier once when the request is added to the queue, and evaluate the supplier when a timeout occurs. setTickThreadStage doesn't need to update each of the individual requests, because if a timeout occurs they will retrieve the latest one via the getter. Once a request leaves the queue, it can change the Supplier to no longer blame the tick thread for timeouts.
I think this is reasonable, and I'll leave it up to you if you want to implement it. Modeling a "Stage" as an interval of time rather than a single instant seems natural, even if the REST error will mostly only see in-progress intervals.
Sure, we can push full traces to an optional follow-up. Full traces would be more resource intensive and possibly too verbose for the REST API. |
|
Okay, I've pushed a couple new commits that:
I know that this doesn't cover everything we discussed, but I did give the rest a try. I explored an approach where we defined broader tick thread stages (declaring them in Instead, I've tried for an approach where the tick thread stages are defined as narrowly as possible, and only around operations that we can reasonably anticipate will block. This does slightly increase the odds of a stage being completed when a request times out, but since the information about that stage isn't lost anymore, the fallout from that scenario is limited. I also experimented with the I've also verified with three consecutive Jenkins runs that the new integration test should finally be flake-free. Let me know what you think; hoping that this is closer to acceptable, though I suspect there's still work left to be done (including adding more unit testing coverage). |
|
@gharris1727 @yashmayya would either of you have a moment to take a look at this one? Hoping to merge in time for 3.7.0 if possible. Thanks! |
gharris1727
left a comment
There was a problem hiding this comment.
Thanks Chris!
I like the augmentation of the BlockingConnectorTest, and the additional ConnectWorkerIntegrationTest.
The new error messages in HerderRequestHandler and ConnectorPluginsResource are also very clear and to the point.
| assertNotNull(e.getMessage()); | ||
| assertTrue( | ||
| "Message '" + e.getMessage() + "' does not match expected format", | ||
| e.getMessage().contains("Request timed out. The worker is currently flushing updates to the status topic") |
There was a problem hiding this comment.
Is this the only error message possible when shutting down kafka, or the most common?
I would expect that an error about ensuring membership in the cluster could appear.
There was a problem hiding this comment.
Surprisingly, this is actually the first operation that will block indefinitely if the Kafka cluster goes down.
We proactively revoke all connectors and tasks on the worker if we're unable to reach the Kafka group coordinator for long enough, which in turn causes the worker to flush the status store, which blocks until Kafka becomes available again.
I'd be worried about this (the herder thread getting blocked, which is usually pretty awful), but for a system designed to integrate with Kafka, it doesn't seem so bad or so unreasonable for our availability to be tied to the targeted Kafka cluster's.
I've augmented the stage description to hopefully shed a little more light on the issue
There was a problem hiding this comment.
Ah I see. So the polling the group coordinator for up to ... or until interrupted stage is only temporary and flushing updates to the status topic is permanent, so it'll always eventually get stuck on this stage.
Do you think it's possible for the preceeding Thread.sleep() to cause a flake here, if the worker is in the "polling the group coordinator" stage for too long? Perhaps we could replace the sleep with a wait-until-condition that repeatedly makes the request until the flushing status store error appears.
There was a problem hiding this comment.
Ah, good idea! Added assert-with-retry logic to the assertTimeoutException utility method.
I've also tweaked how we track stages when the herder is polling the group coordinator. Previously, when the WorkerGroupMember and WorkerCoordinator methods only accepted a Runnable, those stages would never be closed. Now, those methods accept a Supplier<UncheckedCloseable> that, at the moment, always returns a Distributed.TickThreadStage, which can be used with a try-with-resources block to automatically register and complete tick thread stages.
I know that I've used UncheckedCloseable incorrectly in the past; I believe this time doesn't suffer from any of the issues my previous usages did. But if the result is still undesirable, we can explore alternatives like introducing a new interface.
- Permit negative stage timestamps - Warn on invalid stage completion times instead of throwing exceptions - Revert unnecessary change to AbstractHerderTest - Improve stage tracking for connector config validation in AbstractHerder - Fix broken cases in DistributedHerderTest suite
gharris1727
left a comment
There was a problem hiding this comment.
LGTM, thanks for the improvement Chris!
I hope this will lead to faster time-to-remediate for incidents involving unresponsive workers, and facilitate giving feedback to the framework & plugin developers about improving consistently slow operations.
| // Set to 1 instead of 0 as another workaround for KAFKA-15693, which can cause | ||
| // connectors and tasks to be unassigned indefinitely if the scheduled rebalance delay | ||
| // is set to 0 |
There was a problem hiding this comment.
I've just noticed that this part is no longer necessary since we've merged a fix for KAFKA-15693.
I'll remove this comment and change the value to zero. If the test continues to pass on Jenkins, should be safe to merge.
|
Thanks Greg! I've made one final tweak to the integration tests. Hoping this doesn't affect test stability; will merge if things look alright on Jenkins. |
|
All CI failures appear unrelated, merging. |
…uests time out (apache#14562) Reviewers: Greg Harris <greg.harris@aiven.io>
…uests time out (apache#14562) Reviewers: Greg Harris <greg.harris@aiven.io>
…uests time out (apache#14562) Reviewers: Greg Harris <greg.harris@aiven.io>
…uests time out (apache#14562) Reviewers: Greg Harris <greg.harris@aiven.io>
Jira
There are three common scenarios when Kafka Connect REST requests time out:
Connector::validate) has blockedThis PR adds error messages to REST requests that help capture which operations are causing the worker to be unable to respond in time. The error messages include a description of the action the worker is blocked on, and a human-readable timestamp of when that action began.
Some rejected alternatives:
ConfigProviderinstances)During review, it may be helpful to focus on these files first (as they contain the internal API for recording and reporting callback stages):
HerderRequestHandlerandConnectorPluginsResource(same change applied across both files)CallbackConvertingFutureCallbackStageStagedTimeoutExceptionTemporaryStageCommitter Checklist (excluded from commit message)