feat(client): wrap err with upstream information#2105
feat(client): wrap err with upstream information#2105mdenushev wants to merge 6 commits intovalyala:masterfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds upstream server information to errors returned by the HTTP client, making it easier to identify which upstream server caused an error during logging and debugging. The implementation wraps errors in a new ErrWithUpstream struct that includes the upstream address.
Key Changes:
- Introduced
ErrWithUpstreamstruct to wrap errors with upstream information - Updated error wrapping in
DoDeadlineandDomethods to include upstream address - Modified tests to use
errors.Is()for error checking instead of direct equality comparison
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| client.go | Added ErrWithUpstream type and wrapErrWithUpstream helper function; wrapped timeout and retry errors with upstream information |
| client_test.go | Updated error assertions from direct equality checks (err != ErrTimeout) to errors.Is() checks to support wrapped errors |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
The first argument to the |
No, only Response provides RemoteAddr func |
|
I'm not sure what to do with this. As you can see from the tests this is quite a backwards incompatible change, we usually don't do those. Can you think of another way to do this that is backwards compatible? |
|
I see 3 possible options here:
|
erikdubbelboer
left a comment
There was a problem hiding this comment.
I agree it's probably best to make this minor backwards incompatible change.
| req.timeout = time.Until(deadline) | ||
| if req.timeout <= 0 { | ||
| return ErrTimeout | ||
| return wrapErrWithUpstream(ErrTimeout, c.Addr) |
There was a problem hiding this comment.
I'm curious why you only wrap the error here? When someone uses this method they can just read c.Addr themselves? I thought this was about Client.RetryIfErr where you can't know the addr?
|
@erikdubbelboer Hi, sorry for silence, I have been thinking about implementing more backward compatible solution and I think the most backward compatible solution is to introduce |
|
Yes I'm ok with |
|
Created new PR #2176, so closing this one |
Currently, there is no way to get upstream information in
RetryIfErrfunction, but upstream information is very important for logging purposes.