9fe6c33c0d
Prior to #13244, connect proxies and gateways could only be configured by an xDS session served by the local client agent. In an upcoming release, it will be possible to deploy a Consul service mesh without client agents. In this model, xDS sessions will be handled by the servers themselves, which necessitates load-balancing to prevent a single server from receiving a disproportionate amount of load and becoming overwhelmed. This introduces a simple form of load-balancing where Consul will attempt to achieve an even spread of load (xDS sessions) between all healthy servers. It does so by implementing a concurrent session limiter (limiter.SessionLimiter) and adjusting the limit according to autopilot state and proxy service registrations in the catalog. If a server is already over capacity (i.e. the session limit is lowered), Consul will begin draining sessions to rebalance the load. This will result in the client receiving a `RESOURCE_EXHAUSTED` status code. It is the client's responsibility to observe this response and reconnect to a different server. Users of the gRPC client connection brokered by the consul-server-connection-manager library will get this for free. The rate at which Consul will drain sessions to rebalance load is scaled dynamically based on the number of proxies in the catalog.
47 lines
1.7 KiB
Go
47 lines
1.7 KiB
Go
package consul
|
|
|
|
import (
|
|
"github.com/hashicorp/go-hclog"
|
|
"google.golang.org/grpc"
|
|
|
|
"github.com/hashicorp/consul-net-rpc/net/rpc"
|
|
|
|
"github.com/hashicorp/consul/agent/consul/stream"
|
|
"github.com/hashicorp/consul/agent/grpc-external/limiter"
|
|
"github.com/hashicorp/consul/agent/pool"
|
|
"github.com/hashicorp/consul/agent/router"
|
|
"github.com/hashicorp/consul/agent/rpc/middleware"
|
|
"github.com/hashicorp/consul/agent/token"
|
|
"github.com/hashicorp/consul/tlsutil"
|
|
)
|
|
|
|
type Deps struct {
|
|
EventPublisher *stream.EventPublisher
|
|
Logger hclog.InterceptLogger
|
|
TLSConfigurator *tlsutil.Configurator
|
|
Tokens *token.Store
|
|
Router *router.Router
|
|
ConnPool *pool.ConnPool
|
|
GRPCConnPool GRPCClientConner
|
|
LeaderForwarder LeaderForwarder
|
|
XDSStreamLimiter *limiter.SessionLimiter
|
|
// GetNetRPCInterceptorFunc, if not nil, sets the net/rpc rpc.ServerServiceCallInterceptor on
|
|
// the server side to record metrics around the RPC requests. If nil, no interceptor is added to
|
|
// the rpc server.
|
|
GetNetRPCInterceptorFunc func(recorder *middleware.RequestRecorder) rpc.ServerServiceCallInterceptor
|
|
// NewRequestRecorderFunc provides a middleware.RequestRecorder for the server to use; it cannot be nil
|
|
NewRequestRecorderFunc func(logger hclog.Logger, isLeader func() bool, localDC string) *middleware.RequestRecorder
|
|
EnterpriseDeps
|
|
}
|
|
|
|
type GRPCClientConner interface {
|
|
ClientConn(datacenter string) (*grpc.ClientConn, error)
|
|
ClientConnLeader() (*grpc.ClientConn, error)
|
|
SetGatewayResolver(func(string) string)
|
|
}
|
|
|
|
type LeaderForwarder interface {
|
|
// UpdateLeaderAddr updates the leader address in the local DC's resolver.
|
|
UpdateLeaderAddr(datacenter, addr string)
|
|
}
|