client

package
v0.0.0-...-ba97115 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 16, 2026 License: Apache-2.0 Imports: 15 Imported by: 87

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Pool

type Pool struct {
	services.Service

	sync.RWMutex
	// contains filtered or unexported fields
}

Pool holds a cache of grpc_health_v1 clients.

func NewPool

func NewPool(clientName string, cfg PoolConfig, discovery PoolServiceDiscovery, factory PoolFactory, clientsMetric prometheus.Gauge, logger log.Logger) *Pool

NewPool creates a new Pool.

func (*Pool) Count

func (p *Pool) Count() int

Count returns how many clients are in the cache

func (*Pool) GetClientFor

func (p *Pool) GetClientFor(addr string) (PoolClient, error)

GetClientFor gets the client for the specified address. If it does not exist it will make a new client for that address.

func (*Pool) GetClientForInstance

func (p *Pool) GetClientForInstance(inst ring.InstanceDesc) (PoolClient, error)

GetClientForInstance gets the client for the specified ring member. If it does not exist it will make a new client for that instance.

func (*Pool) RegisteredAddresses

func (p *Pool) RegisteredAddresses() []string

RegisteredAddresses returns all the service addresses for which there's an active client.

func (*Pool) RemoveClient

func (p *Pool) RemoveClient(client PoolClient, addr string)

RemoveClient removes the client instance from the pool if it is still there and not cleaned up by health check. The value of client needs to be the same as returned by GetClientForInstance or GetClientFor. If addr is not empty and contains the same addr passed when obtaining the client, then the operation is sped up.

func (*Pool) RemoveClientFor

func (p *Pool) RemoveClientFor(addr string)

RemoveClientFor removes the client with the specified address

type PoolAddrFunc

type PoolAddrFunc func(addr string) (PoolClient, error)

PoolAddrFunc is an implementation of PoolFactory for functions that accept an instance address.

func (PoolAddrFunc) FromInstance

func (f PoolAddrFunc) FromInstance(inst ring.InstanceDesc) (PoolClient, error)

type PoolClient

type PoolClient interface {
	grpc_health_v1.HealthClient
	io.Closer
}

PoolClient is the interface that should be implemented by a client managed by the pool.

type PoolConfig

type PoolConfig struct {
	CheckInterval      time.Duration
	HealthCheckEnabled bool
	HealthCheckTimeout time.Duration

	// HealthCheckGracePeriod is the duration during which the health check is allowed to fail before the client is removed
	// from the pool.
	// For example, if the grace period is 60s, and the health check consistently fails during this period, then the client
	// will be removed from the pool at the end of this period.
	// However, if the health check passes at any point during this period, then the grace period is reset and starts again
	// when the health check next fails.
	HealthCheckGracePeriod time.Duration

	MaxConcurrentHealthChecks int // defaults to 16
}

PoolConfig is config for creating a Pool.

type PoolFactory

type PoolFactory interface {
	FromInstance(inst ring.InstanceDesc) (PoolClient, error)
}

PoolFactory is the interface for creating new clients based on the description of an instance in the ring.

type PoolInstFunc

type PoolInstFunc func(inst ring.InstanceDesc) (PoolClient, error)

PoolInstFunc is an implementation of PoolFactory for functions that accept ring instance metadata.

func (PoolInstFunc) FromInstance

func (f PoolInstFunc) FromInstance(inst ring.InstanceDesc) (PoolClient, error)

type PoolServiceDiscovery

type PoolServiceDiscovery func() ([]string, error)

PoolServiceDiscovery defines the signature of a function returning the list of known service endpoints. This function is used to remove stale clients from the pool (a stale client is a client connected to a service endpoint no more active).

func NewRingServiceDiscovery

func NewRingServiceDiscovery(r ring.ReadRing) PoolServiceDiscovery

func NewRingsServiceDiscovery

func NewRingsServiceDiscovery(rings []ring.ReadRing) PoolServiceDiscovery

NewRingsServiceDiscovery returns a PoolServiceDiscovery listing the deduplicated addresses of all healthy instances across the given rings.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址