-
Notifications
You must be signed in to change notification settings - Fork 8
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
agent/http: refactor proxy for simpler error handling #271
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @roobre Overall, the changes make sense and improve the code, except for the usage of a channel for waiting. I suggest an alternative approach that I think is simpler to reason about.
pkg/agent/protocol/http/proxy.go
Outdated
}() | ||
} | ||
// proxy proxies a request to the upstream URL. | ||
// Request is performed immediately, but response won't be copied to the client until wait has been consumed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find confusing this wait channel. I think it obscures the purpose of the proxy which should in my opinion only do one thing.
I suggest that instead of passing this argument, you use a wrapper function that waits before (or after) the given delay and then calls a function passed as an argument, given that both proxy
and fault
has the same signature.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The main purpose of the wait channel is to allow to start waiting after the request has been made. This way, the latency to the upstream service is "included" in the fault latency. I wasn't able to figure out a way of doing this with a wrapper, as this wait necessarily needs to happen after performing the request, but before writing the response.
Do you have an idea for how to get rid of the channel but maintain this feature?
Otherwise, we can just drop the feature and always sleep before initiating the request upstream.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have any off the top of my head, but at the very least, I would pass the delay and make the wait inside the functions instead of passing a channel. That makes the purpose of the argument clear. I don't see any advantage on using a channel.
pkg/agent/protocol/http/proxy.go
Outdated
_, _ = io.Copy(rw, response.Body) | ||
} | ||
|
||
// fault consumes wait and then writes to rw the configured error code and body. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment here. I find this wait argument confusing and cannot see how it improves or simplifies the code or the error handling.
bc492c1
to
4c63bff
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Made a couple of comments about the naming of some functions because I find them odd.
5acc9cd
to
d42d0b5
Compare
d42d0b5
to
0517bd8
Compare
Rebased and squashed, feel free to merge if you don't have further concerns @pablochacin. |
This reverts commit 72c4e48.
Description
This PR introduces a small refactor in the HTTP proxy, so it is easier to read the logic behind delays, faults, and proxies.
Fixes #252
Checklist:
make lint
) and all checks pass.make test
) and all tests pass.make e2e-xxx
foragent
,disruptors
,kubernetes
orcluster
related changes)