Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNoFallbackNodeFound = errors.New("no fallback node found - whole cluster seems offline")
ErrNoFallbackNodeFound happens when the fallback routine does not manage to find a TCP reachable node in alternative to the chosen one.
Functions ¶
func ConsistentHashReverseProxy ¶
func ConsistentHashReverseProxy(ctx context.Context, nodes []string) *httputil.ReverseProxy
ConsistentHashReverseProxy returns a new ReverseProxy that routes URLs to the scheme, host, and base path provided in by a consistent hash algorithm. If the target's path is "/base" and the incoming request was for "/dir", the target request will be for /base/dir. ConsistentHashReverseProxy does not rewrite the Host header.
Types ¶
type FallbackRoundTripper ¶
type FallbackRoundTripper struct {
// contains filtered or unexported fields
}
FallbackRoundTripper implements http.RoundTripper in a way that when an outgoing request does not manage to succeed with its original target host, it fallsback to a list of alternative hosts. Internally it keeps a list of dead hosts, and pings them until they are back online, diverting traffic back to them. This is meant to be used by ConsistentHashReverseProxy().
func NewRoundTripper ¶
func NewRoundTripper(ctx context.Context, nodes []string) *FallbackRoundTripper
NewRoundTripper creates a new FallbackRoundTripper and triggers the internal host TCP health checks.
func (*FallbackRoundTripper) RoundTrip ¶
RoundTrip implements http.RoundTrip. It tried to fullfil an *http.Request to its original target host, falling back to a list of nodes in case of failure. After the first failure, it consistently delivers traffic to the fallback host, until original host is back online. If no fallback node is available, it fails with ErrNoFallbackNodeFound. In case of cascaded failure, that is, the fallback node is also offline, it will look for another online host.