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

Spike: Use retry middleware with reverse proxy #64

Closed
wants to merge 13 commits into from

Conversation

alpe
Copy link
Contributor

@alpe alpe commented Jan 22, 2024

Same middleware as in #51 but set up for the reverse proxy

log.Printf("Proxying request to host %v: %v\n", host, id)
newReverseProxy(host).ServeHTTP(w, proxyRequest)
proxy := newReverseProxy(host)
NewRetryMiddleware(h.retriesOnErr, proxy).ServeHTTP(w, proxyRequest)
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 how the middleware is integrated with the reverse proxy


// NewDiscardableResponseWriter creates a new instance of the response writer delegator.
// It takes a http.ResponseWriter and a function to determine by the status code if content should be written or discarded (for retry).
func NewDiscardableResponseWriter(writer http.ResponseWriter, isDiscardable func(status int) bool) XResponseWriter {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think wrapping the http.ResponseWriter comes with thorns. You can lose functionality if you don't implement all of the interfaces that ResponseWriter can be: https://go.dev/play/p/3B0yYC8kTvf

This is one the reasons I think that the middleware pattern in Go typically leads to more code than necessary. In the case of Lingo where we have a single primary handler (the proxy) I think that the middleware approach leads to more a more verbose/complicated solution than leaning on helper functions.

Copy link
Contributor

Choose a reason for hiding this comment

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

Bringing benefits being customizable discussion here: #63

@alpe alpe changed the title Use retry middleware with reverse proxy Spike: Use retry middleware with reverse proxy Feb 5, 2024
@alpe
Copy link
Contributor Author

alpe commented Feb 7, 2024

Closing this now in favour of #61

@alpe alpe closed this Feb 7, 2024
nstogner added a commit that referenced this pull request Feb 15, 2024
Allow for retrying failed requests to backends. Default to 1 retry per
lingo-request.

Fixes #48 

Builds on work done by @alpe in #64 and #51.

Co-authored-by: Alex Peters <alpe@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants