Rework servers load-balancer to use the WRR
Co-authored-by: Kevin Pollet <pollet.kevin@gmail.com>
This commit is contained in:
parent
67d9c8da0b
commit
fadee5e87b
70 changed files with 2085 additions and 2211 deletions
|
@ -62,13 +62,13 @@ func FromContext(ctx context.Context) (Capture, error) {
|
|||
// Capture is the object populated by the capture middleware,
|
||||
// holding probes that allow to gather information about the request and response.
|
||||
type Capture struct {
|
||||
rr *readCounter
|
||||
rw responseWriter
|
||||
rr *readCounter
|
||||
crw *captureResponseWriter
|
||||
}
|
||||
|
||||
// NeedsReset returns whether the given http.ResponseWriter is the capture's probe.
|
||||
func (c *Capture) NeedsReset(rw http.ResponseWriter) bool {
|
||||
return c.rw != rw
|
||||
return c.crw.rw != rw
|
||||
}
|
||||
|
||||
// Reset returns a new handler that renews the Capture's probes, and inserts
|
||||
|
@ -83,18 +83,18 @@ func (c *Capture) Reset(next http.Handler) http.Handler {
|
|||
c.rr = readCounter
|
||||
newReq.Body = readCounter
|
||||
}
|
||||
c.rw = newResponseWriter(rw)
|
||||
c.crw = &captureResponseWriter{rw: rw}
|
||||
|
||||
next.ServeHTTP(c.rw, newReq)
|
||||
next.ServeHTTP(c.crw, newReq)
|
||||
})
|
||||
}
|
||||
|
||||
func (c *Capture) ResponseSize() int64 {
|
||||
return c.rw.Size()
|
||||
return c.crw.Size()
|
||||
}
|
||||
|
||||
func (c *Capture) StatusCode() int {
|
||||
return c.rw.Status()
|
||||
return c.crw.Status()
|
||||
}
|
||||
|
||||
// RequestSize returns the size of the request's body if it applies,
|
||||
|
@ -123,22 +123,7 @@ func (r *readCounter) Close() error {
|
|||
return r.source.Close()
|
||||
}
|
||||
|
||||
var _ middlewares.Stateful = &responseWriterWithCloseNotify{}
|
||||
|
||||
type responseWriter interface {
|
||||
http.ResponseWriter
|
||||
Size() int64
|
||||
Status() int
|
||||
}
|
||||
|
||||
func newResponseWriter(rw http.ResponseWriter) responseWriter {
|
||||
capt := &captureResponseWriter{rw: rw}
|
||||
if _, ok := rw.(http.CloseNotifier); !ok {
|
||||
return capt
|
||||
}
|
||||
|
||||
return &responseWriterWithCloseNotify{capt}
|
||||
}
|
||||
var _ middlewares.Stateful = &captureResponseWriter{}
|
||||
|
||||
// captureResponseWriter is a wrapper of type http.ResponseWriter
|
||||
// that tracks response status and size.
|
||||
|
@ -189,13 +174,3 @@ func (crw *captureResponseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error)
|
|||
|
||||
return nil, nil, fmt.Errorf("not a hijacker: %T", crw.rw)
|
||||
}
|
||||
|
||||
type responseWriterWithCloseNotify struct {
|
||||
*captureResponseWriter
|
||||
}
|
||||
|
||||
// CloseNotify returns a channel that receives at most a
|
||||
// single value (true) when the client connection has gone away.
|
||||
func (r *responseWriterWithCloseNotify) CloseNotify() <-chan bool {
|
||||
return r.rw.(http.CloseNotifier).CloseNotify()
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue