Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrConnMgrClosed = errors.New("connection manager closed") MetricGRPCConnections = prometheus.NewGaugeVec(prometheus.GaugeOpts{ Name: "grpcconn_connections", Help: "The number of gRPC connections used by grpcconn.", }, []string{"remote_service", "peer"}) )
Functions ¶
func WithLogger ¶ added in v4.16.1
Types ¶
type Config ¶
type Config struct { RPCTimeout clock.Duration BackOffTimeout clock.Duration Zone string OverrideHostHeader string // NumConnections is the number of client connections to establish // per target endpoint // // NOTE: A single GRPC client opens a maximum of 100 HTTP/2 Connections // to an endpoint. Once those connections are saturated, it will queue // requests to be delivered once there is availability. The recommended // method of overcoming this limitation is establishing multiple GPRC client // connections. See https://grpc.io/docs/guides/performance/ NumConnections int }
type ConnFactory ¶
type ConnFactory[T any] interface { NewGRPCClient(cc grpc.ClientConnInterface) T GetServerListURL() string ServiceName() string ShouldDisposeOfConn(err error) bool }
ConnFactory creates gRPC client objects.
type ConnMgr ¶
type ConnMgr[T any] struct { // contains filtered or unexported fields }
ConnMgr automates gRPC `Connection` pooling. This is necessary for use cases requiring frequent stream creation and high stream concurrency to avoid reaching the default 100 stream per connection limit. ConnMgr resolves gRPC instance endpoints and connects to them. Both resolution and connection is performed on the background allowing any number of concurrent AcquireConn to result in only one reconnect event.
func NewConnMgr ¶
func NewConnMgr[T any](cfg *Config, httpClient *http.Client, connFactory ConnFactory[T], opts ...option[T]) *ConnMgr[T]
NewConnMgr instantiates a connection manager that maintains a gRPC connection pool.
func (*ConnMgr[T]) AcquireConn ¶
func (*ConnMgr[T]) TransCountInTests ¶
TransCountInTests returns the total number of pending read/write operations. It is only supposed to be used in tests, hence it is not exposed in Client interface.
type GenericResponse ¶
type GenericResponse struct {
Msg string `json:"message"`
}
type GetGRPCEndpointsRs ¶
type GetGRPCEndpointsRs struct { Servers []ServerSpec `json:"servers"` TTL int `json:"ttl"` // FIXME: Remove the following fields once all clients are upgraded. Endpoint string `json:"grpc_endpoint"` Zone string `json:"zone"` }
type IDPool ¶
type IDPool struct {
// contains filtered or unexported fields
}
IDPool maintains a pool of ID values that can be released and reused. This is handy to keep cardinality low as gRPC connections are periodically released and reconnected and require an id. This solves the problem of infinitely incrementing ids used in Prometheus metric labels causing infinite growth of historical metric values.