feat(client): include request URI context in ApiError (#949)#1997
feat(client): include request URI context in ApiError (#949)#1997goodbsw wants to merge 4 commits into
Conversation
Signed-off-by: Seungweon Baek <ops@caffy.io>
56d493a to
a3815a4
Compare
…anges Signed-off-by: Seungweon Baek <goodbsw@gmail.com>
a3815a4 to
ec70b63
Compare
|
Thanks for picking this up, nice write-up! Quick heads-up before this goes further: there's already a PR for #949 with some maintainer review on it, #1973. Might be worth syncing up so we don't end up with two different takes on the same thing. Couple of things from that thread that probably apply here too: clux suggested reusing the existing BaseUri middleware for this. His review on #1973 (comment) basically says: hook into the existing BaseUri tower layer instead of adding a separate mechanism just for error context. The extensions sidecar here kind of goes the opposite way. There's also a subtle gap with grabbing request.uri() at the client layer. BaseUri rewrites the URI inside the tower stack, so before the stack you only have the relative path. For a rancher-style cluster ( One more: this flips Error::Api from a tuple to a struct variant, which is a breaking change. #1973 keeps Error::Api(Status) as-is and just adds the URI to the debug logs, so probably worth a deliberate call on whether we want the breaking version or not. Anyway, might be worth syncing with @AkashKumar7902 on #1973 and landing one approach. Happy to help review whichever way it goes 👍 |
|
Thanks for the incredibly detailed and insightful review @doxxx93! You made an excellent point regarding the Rancher-style proxy clusters ( Since #1973 is already making solid progress with maintainer feedback, I’ll sync up with @AkashKumar7902 over there. I’d love to see if we can ensure that #1973 hooks into the I'll head over to #1973 to collaborate and make sure we land the best approach for #949. Thanks again for guiding me in the right direction! 🤝 |
Motivation
When handling API errors (such as 404 Not Found, 409 Conflict, etc.) returned by the Kubernetes API server, the current
Error::Apivariant only wraps the rawStatusobject. This makes debugging highly problematic in large-scale infrastructure environments because the error context does not indicate which specific URI/endpoint failed.For instance, when a service mesh or external client receives an unhelpful API error, troubleshooting requires cross-referencing external logs since the exact request path is completely lost. This PR resolves #949 by injecting the missing request URI directly into the
Error::Apivariant.Solution
To bypass the architectural constraint where the
Responseobject independently lacks request context metadata, we implemented a sidecar metadata pocket mechanism utilizing HTTP response extensions:Error::ApiVariant Refactoring (kube-client/src/error.rs)Apivariant from a tuple struct to a struct variant:Api { source: Box<Status>, uri: http::Uri }.Context Injection in Client Pipeline (
kube-client/src/client/mod.rs)Client::send, cloned the originalrequest.uri()before the request ownership is moved.response.extensions_mut().insert(req_uri).handle_api_errors, extracted thehttp::Uritype back from the extensions map and successfully packed it into the newError::Apistruct layout.Watch API Stream Support & Test Realignment
request_eventsby applying themovekeyword to propagatereq_uriacross async boundaries cleanly.lib.rs,entry.rs,core_methods.rs).test result: ok).