client

package
v0.0.0-...-a1bba12 Latest Latest
Warning

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

Go to latest
Published: May 9, 2024 License: Apache-2.0 Imports: 15 Imported by: 74

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
	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

Jump to

Keyboard shortcuts

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