Documentation
¶
Index ¶
- Variables
- type GRPCClient
- type GRPCClientFactory
- type GRPCHealthCheck
- type GRPCPool
- func (p *GRPCPool) AddHost(url string, port int) error
- func (p *GRPCPool) DisableHost(id string)
- func (p *GRPCPool) EnableHost(id string)
- func (p *GRPCPool) Exec(req interface{}) (interface{}, error)
- func (p *GRPCPool) ExecSticky(hostID string, req interface{}) (interface{}, string, error)
- func (p *GRPCPool) ExecSynced(req interface{}) (interface{}, string, error)
- func (p *GRPCPool) GetAllHosts() []string
- func (p *GRPCPool) HandleInfoRequest(w http.ResponseWriter, r *http.Request)
- func (p *GRPCPool) SetHostSyncStatus(id string, synced bool)
- type HTTPError
- type HTTPHealthCheck
- type HTTPHostOptions
- type HTTPPool
- func (p *HTTPPool) AddHost(url string, port int, opt *HTTPHostOptions) error
- func (p *HTTPPool) DisableHost(id string)
- func (p *HTTPPool) EnableHost(id string)
- func (p *HTTPPool) ExecHTTP(method, path string, body, target interface{}) error
- func (p *HTTPPool) ExecHTTPSticky(hostID, method, path string, body, target interface{}) (string, error)
- func (p *HTTPPool) ExecHTTPSynced(method, path string, body, target interface{}) (string, error)
- func (p *HTTPPool) ExecRPC(req *rpc.Request) (*rpc.Response, error)
- func (p *HTTPPool) ExecRPCBulk(reqs []*rpc.Request) ([]*rpc.Response, error)
- func (p *HTTPPool) ExecRPCFromArgs(method string, params ...interface{}) (*rpc.Response, error)
- func (p *HTTPPool) ExecRPCFromArgsSynced(method string, params ...interface{}) (*rpc.Response, error)
- func (p *HTTPPool) ExecRPCSynced(req *rpc.Request) (*rpc.Response, error)
- func (p *HTTPPool) GetAllHosts() []string
- func (p *HTTPPool) HandleInfoRequest(w http.ResponseWriter, r *http.Request)
- func (p *HTTPPool) SetHostSyncStatus(id string, synced bool)
- type HealthCheckFunc
- type TCPHealthCheck
- type TCPPool
- func (p *TCPPool) AddHost(url string, port int) error
- func (p *TCPPool) DisableHost(id string)
- func (p *TCPPool) EnableHost(id string)
- func (p *TCPPool) Exec(req *rpc.Request) (*rpc.Response, error)
- func (p *TCPPool) ExecSynced(req *rpc.Request) (*rpc.Response, error)
- func (p *TCPPool) HandleInfoRequest(w http.ResponseWriter, r *http.Request)
- func (p *TCPPool) SetHostSyncStatus(id string, synced bool)
- func (p *TCPPool) Subscribe(method string) chan *rpc.Request
Constants ¶
This section is empty.
Variables ¶
var (
ErrNoHealthyHosts = fmt.Errorf("no healthy hosts")
)
Functions ¶
This section is empty.
Types ¶
type GRPCClient ¶
type GRPCClientFactory ¶
type GRPCClientFactory func(string, time.Duration) (GRPCClient, error)
type GRPCHealthCheck ¶
GRPCHealthCheck specifies the definition of connection health for all connections in the pool. Interval is the frequency that the health check runs, Timeout is the connection timeout.
Either the HTTP or RPC fields are required, if both are defined then HTTP will take precedence.
type GRPCPool ¶
type GRPCPool struct {
// contains filtered or unexported fields
}
HTTPPool represents a pool of HTTP hosts with methods to make standard HTTP calls.
func NewGRPCPool ¶
func NewGRPCPool( ctx context.Context, factory GRPCClientFactory, logger *log.Logger, healthCheck *GRPCHealthCheck, tunnel *sshtunnel.SSHTunnel, ) *GRPCPool
NewGRPCPool creates a GRPC pool that manages connection health and optimizes for latency (while maintaining a degree of "stickiness" to avoid excessive reordering).
The GRPCHealthCheck is not required, but without it the pool has little purpose. The health check interval defaults to one minute, the timeout defaults to
func (*GRPCPool) DisableHost ¶
Disables a host from being used for requests, though the host is not deleted (and can be enabled again).
func (*GRPCPool) EnableHost ¶
Enables a host, returning it to the active pool to be used in requests.
func (*GRPCPool) Exec ¶
Executes a GRPC call. All healthy hosts will be attempted, if there are no healthy hosts to begin with, ErrNoHealthyHosts is returned. If there are healthy hosts, though all are actively unhealthy, the last error is returned.
func (*GRPCPool) ExecSticky ¶
func (*GRPCPool) ExecSynced ¶
func (*GRPCPool) GetAllHosts ¶
func (*GRPCPool) HandleInfoRequest ¶
func (p *GRPCPool) HandleInfoRequest(w http.ResponseWriter, r *http.Request)
func (*GRPCPool) SetHostSyncStatus ¶
Sets the sync status of a given host.
type HTTPHealthCheck ¶
type HTTPHealthCheck struct { Interval time.Duration Timeout time.Duration HTTPMethod string HTTPPath string HTTPBody interface{} RPCRequest *rpc.Request }
HTTPHealthCheck specifies the definition of connection health for all connections in the pool. Interval is the frequency that the health check runs, Timeout is the connection timeout.
Either the HTTP or RPC fields are required, if both are defined then HTTP will take precedence.
type HTTPHostOptions ¶
type HTTPPool ¶
type HTTPPool struct {
// contains filtered or unexported fields
}
HTTPPool represents a pool of HTTP hosts with methods to make standard HTTP calls.
func NewHTTPPool ¶
func NewHTTPPool( ctx context.Context, logger *log.Logger, healthCheck *HTTPHealthCheck, tunnel *sshtunnel.SSHTunnel, ) *HTTPPool
NewHTTPPool creates an HTTP pool that manages connection health and optimizes for latency (while maintaining a degree of "stickiness" to avoid excessive reordering).
The HTTPHealthCheck is not required, but without it the pool has little purpose. The health check interval defaults to one minute, the timeout defaults to
func (*HTTPPool) AddHost ¶
func (p *HTTPPool) AddHost(url string, port int, opt *HTTPHostOptions) error
Adds a host to the pool. If the host already exists, nothing happens.
func (*HTTPPool) DisableHost ¶
Disables a host from being used for requests, though the host is not deleted (and can be enabled again).
func (*HTTPPool) EnableHost ¶
Enables a host, returning it to the active pool to be used in requests.
func (*HTTPPool) ExecHTTP ¶
Executes a HTTP call. All healthy hosts will be attempted, if there are no healthy hosts to begin with, ErrNoHealthyHosts is returned. If there are healthy hosts, though all are actively unhealthy, the last error is returned.
Note that user error is a possibility for hosts being marked as unhealthy if the json decoder fails. Target should be a pointer to the response object.
func (*HTTPPool) ExecHTTPSticky ¶
func (p *HTTPPool) ExecHTTPSticky( hostID, method, path string, body, target interface{}, ) (string, error)
Executes a HTTP call. All healthy hosts will be attempted, if there are no healthy hosts to begin with, ErrNoHealthyHosts is returned. If there are healthy hosts, though all are actively unhealthy, the last error is returned.
Note that user error is a possibility for hosts being marked as unhealthy if the json decoder fails. Target should be a pointer to the response object.
func (*HTTPPool) ExecHTTPSynced ¶
func (*HTTPPool) ExecRPCBulk ¶
Executes a bulk RPC call to all healthy hosts.
func (*HTTPPool) ExecRPCFromArgs ¶
Executes an RPC call and generates the *rpc.Request internally, requiring only the method and the parameters.
func (*HTTPPool) ExecRPCFromArgsSynced ¶
func (p *HTTPPool) ExecRPCFromArgsSynced(method string, params ...interface{}) (*rpc.Response, error)
Executes an RPC call the same way as ExecRPCFromArgs, except it will only attempt the request on synced hosts.
func (*HTTPPool) ExecRPCSynced ¶
func (*HTTPPool) GetAllHosts ¶
func (*HTTPPool) HandleInfoRequest ¶
func (p *HTTPPool) HandleInfoRequest(w http.ResponseWriter, r *http.Request)
func (*HTTPPool) SetHostSyncStatus ¶
Sets the sync status of a given host.
type HealthCheckFunc ¶
type HealthCheckFunc func() int
type TCPHealthCheck ¶
type TCPPool ¶
type TCPPool struct {
// contains filtered or unexported fields
}
func NewTCPPool ¶
func (*TCPPool) DisableHost ¶
Disables a host from being used for requests, though the host is not deleted (and can be enabled again).
func (*TCPPool) EnableHost ¶
Enables a host, returning it to the active pool to be used in requests.
func (*TCPPool) HandleInfoRequest ¶
func (p *TCPPool) HandleInfoRequest(w http.ResponseWriter, r *http.Request)
func (*TCPPool) SetHostSyncStatus ¶
Sets the sync status of a given host.