upstream

package
v0.0.0-...-7429660 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2023 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HashFromContext

func HashFromContext(ctx context.Context) (code uint32, ok bool)

func InjectSubsetCarrier

func InjectSubsetCarrier(ctx context.Context, kvs []string) context.Context

func NewContextWithHash

func NewContextWithHash(ctx context.Context, hash interface{}) context.Context

func NewContextWithHashCode

func NewContextWithHashCode(ctx context.Context, hash uint32) context.Context

func SetLogger

func SetLogger(l *log.Logger)

Types

type ActiveHalthFailureType

type ActiveHalthFailureType uint32
const (
	Unknown ActiveHalthFailureType = iota
	UnHealthy
	Timeout
)

func (ActiveHalthFailureType) String

func (t ActiveHalthFailureType) String() string

type ActiveHealthCheckSession

type ActiveHealthCheckSession struct {
	// contains filtered or unexported fields
}

func (*ActiveHealthCheckSession) Close

func (ahcs *ActiveHealthCheckSession) Close()

func (*ActiveHealthCheckSession) SetUnhealthy

func (*ActiveHealthCheckSession) Start

func (ahcs *ActiveHealthCheckSession) Start()

type AtomicBool

type AtomicBool *bool

type BalanceType

type BalanceType int32
const (
	RoundRobin BalanceType = iota
	LeastRequest
	Random
	RingHash
	WeightRoundRobin
	SubsetBalanceType
)

func UnmarshalBalanceFromText

func UnmarshalBalanceFromText(t string) BalanceType

func (BalanceType) String

func (t BalanceType) String() string

type Balancer

type Balancer interface {
	ChooseHost(ctx context.Context) *Host
	Hosts(ctx context.Context) []*Host
}

type ChangeStateCallback

type ChangeStateCallback func(*Host)

type Cluster

type Cluster struct {
	// contains filtered or unexported fields
}

func NewCluster

func NewCluster(conf config.Cluster, backend registry.Backend) *Cluster

func (*Cluster) AddHostChangedCallback

func (c *Cluster) AddHostChangedCallback(fn func(current []string, added []string, removed []string))

func (*Cluster) Balancer

func (c *Cluster) Balancer() Balancer

func (*Cluster) Close

func (c *Cluster) Close()

func (*Cluster) GetHostByAddress

func (c *Cluster) GetHostByAddress(address string) *Host

func (*Cluster) HealthChecker

func (c *Cluster) HealthChecker() *HealthChecker

HealthChecker ...

type ClusterManager

type ClusterManager struct {
	// contains filtered or unexported fields
}

func NewClusterManager

func NewClusterManager() *ClusterManager

func (*ClusterManager) ChooseAllHosts

func (cm *ClusterManager) ChooseAllHosts(ctx context.Context, service string) []*Host

func (*ClusterManager) ChooseHost

func (cm *ClusterManager) ChooseHost(ctx context.Context, service string) *Host

func (*ClusterManager) Cluster

func (cm *ClusterManager) Cluster(name string) *Cluster

func (*ClusterManager) InitService

func (cm *ClusterManager) InitService(conf config.Cluster) error

func (*ClusterManager) PutResult

func (cm *ClusterManager) PutResult(service, address string, code int)

type Detector

type Detector interface {
	AddChangedStateCallback(ChangeStateCallback)
	SuccessRateAverage() float64
	SuccessRateEjectionThreshold() float64
}

type DetectorHostMonitor

type DetectorHostMonitor interface {
	NumEjections() uint32
	PutResult(Result)
	PutResponseTime(time.Duration)
	LastEjectionTime() time.Time
	LastUnejectionTime() time.Time
}

type Hashable

type Hashable interface {
	HashCode() int32
}

Hashable is a interface for hashable object.

type HealthCheckCompleteCallback

type HealthCheckCompleteCallback func(*Host, HealthTransition)

type HealthCheckFailureType

type HealthCheckFailureType int
const (
	ACTIVE HealthCheckFailureType = iota
	PASSIVE
	NETWORK
)

type HealthChecker

type HealthChecker struct {
	// contains filtered or unexported fields
}

func NewHealthChecker

func NewHealthChecker(tp HealthCheckerType, interval time.Duration, unHealthyThreshold, healthyThreshold uint32, name string) *HealthChecker

func (*HealthChecker) AddHostCheckCompleteCb

func (hc *HealthChecker) AddHostCheckCompleteCb(cb HealthCheckCompleteCallback)

func (*HealthChecker) AddHosts

func (hc *HealthChecker) AddHosts(added []*Host)

func (*HealthChecker) OnHostsChanged

func (hc *HealthChecker) OnHostsChanged(added []*Host, removed []*Host)

type HealthCheckerType

type HealthCheckerType int
const (
	HTTP HealthCheckerType = iota
	TCP
)

type HealthFlag

type HealthFlag uint32
const (
	FailedActiveHC       HealthFlag = 0x01
	FailedDetectorCheck  HealthFlag = 0x02
	FailedRegistryHealth HealthFlag = 0x04
)

type HealthTransition

type HealthTransition int
const (
	Unchanged HealthTransition = iota
	Changed
	ChangePending
)

func (HealthTransition) String

func (t HealthTransition) String() string

type Host

type Host struct {
	// contains filtered or unexported fields
}

func NewHost

func NewHost(address string, weight uint32, meta map[string]string) *Host

func (*Host) Address

func (h *Host) Address() string

func (*Host) GetActiveHealthFailureType

func (h *Host) GetActiveHealthFailureType() (tp ActiveHalthFailureType)

func (*Host) GetDetectorMonitor

func (h *Host) GetDetectorMonitor() DetectorHostMonitor

func (*Host) HealthFlagClear

func (h *Host) HealthFlagClear(flag HealthFlag)

func (*Host) HealthFlagGet

func (h *Host) HealthFlagGet(flag HealthFlag) (res bool)

func (*Host) HealthFlagSet

func (h *Host) HealthFlagSet(flag HealthFlag)

func (*Host) Healthy

func (h *Host) Healthy() (health bool)

func (*Host) Meta

func (h *Host) Meta() map[string]string

func (*Host) SetActiveHealthFailureType

func (h *Host) SetActiveHealthFailureType(tp ActiveHalthFailureType)

func (*Host) SetDetectorMonitor

func (h *Host) SetDetectorMonitor(d DetectorHostMonitor)

func (*Host) SetMeta

func (h *Host) SetMeta(meta map[string]string)

func (*Host) SetUsed

func (h *Host) SetUsed(new bool)

func (*Host) SetWeight

func (h *Host) SetWeight(new uint32)

func (*Host) Used

func (h *Host) Used() (used bool)

func (*Host) Weight

func (h *Host) Weight() (weight uint32)

type HostSet

type HostSet struct {
	// contains filtered or unexported fields
}

func NewHostSet

func NewHostSet(hosts, healthHosts []*Host) *HostSet

func (*HostSet) AddUpdateCallback

func (h *HostSet) AddUpdateCallback(m memberUpdateCallback)

func (*HostSet) HelathHosts

func (h *HostSet) HelathHosts() []*Host

func (*HostSet) Hosts

func (h *HostSet) Hosts() []*Host

func (*HostSet) UpdateHosts

func (h *HostSet) UpdateHosts(hosts, healthHosts, added, removed []*Host)

type RandomBalancer

type RandomBalancer struct {
	// contains filtered or unexported fields
}

func NewRandomBalancer

func NewRandomBalancer(set *HostSet, threshhold int) *RandomBalancer

func (*RandomBalancer) ChooseHost

func (rr *RandomBalancer) ChooseHost(ctx context.Context) *Host

func (*RandomBalancer) Hosts

func (rr *RandomBalancer) Hosts(context.Context) []*Host

type Result

type Result int

type RingHashBalancer

type RingHashBalancer struct {
	// contains filtered or unexported fields
}

func (*RingHashBalancer) ChooseHost

func (rh *RingHashBalancer) ChooseHost(ctx context.Context) *Host

func (*RingHashBalancer) Hosts

func (rr *RingHashBalancer) Hosts(context.Context) []*Host

type RoundRobinBalancer

type RoundRobinBalancer struct {
	// contains filtered or unexported fields
}

func NewRoundRobinBalancer

func NewRoundRobinBalancer(set *HostSet, threshhold int) *RoundRobinBalancer

func (*RoundRobinBalancer) ChooseHost

func (rr *RoundRobinBalancer) ChooseHost(ctx context.Context) *Host

func (*RoundRobinBalancer) Hosts

func (rr *RoundRobinBalancer) Hosts(context.Context) []*Host

type SimpleDetector

type SimpleDetector struct {
	// contains filtered or unexported fields
}

func NewSimpleDector

func NewSimpleDector(c *Cluster, conf config.Detector) *SimpleDetector

func (*SimpleDetector) AddChangedStateCallback

func (sd *SimpleDetector) AddChangedStateCallback(cb ChangeStateCallback)

func (*SimpleDetector) CheckHostForUneject

func (sd *SimpleDetector) CheckHostForUneject(h *Host, m *SimpleDetectorHostMonitor, now time.Time)

func (*SimpleDetector) EjectHost

func (sd *SimpleDetector) EjectHost(h *Host, t ejectType)

func (*SimpleDetector) OnConsecutiveConnectionFailure

func (sd *SimpleDetector) OnConsecutiveConnectionFailure(host *Host)

func (*SimpleDetector) OnConsecutiveFailure

func (sd *SimpleDetector) OnConsecutiveFailure(host *Host)

func (*SimpleDetector) ProcessSuccessRateEjections

func (sd *SimpleDetector) ProcessSuccessRateEjections()

func (*SimpleDetector) Start

func (sd *SimpleDetector) Start()

func (*SimpleDetector) SuccessRateAverage

func (sd *SimpleDetector) SuccessRateAverage() float64

func (*SimpleDetector) SuccessRateEjectionThreshold

func (sd *SimpleDetector) SuccessRateEjectionThreshold() float64

type SimpleDetectorHostMonitor

type SimpleDetectorHostMonitor struct {
	// contains filtered or unexported fields
}

func NewSimpleDetectoHostMonitor

func NewSimpleDetectoHostMonitor(detector *SimpleDetector, host *Host) *SimpleDetectorHostMonitor

func (*SimpleDetectorHostMonitor) Eject

func (hm *SimpleDetectorHostMonitor) Eject(t time.Time)

func (*SimpleDetectorHostMonitor) LastEjectionTime

func (hm *SimpleDetectorHostMonitor) LastEjectionTime() time.Time

func (*SimpleDetectorHostMonitor) LastUnejectionTime

func (hm *SimpleDetectorHostMonitor) LastUnejectionTime() time.Time

func (*SimpleDetectorHostMonitor) NumEjections

func (hm *SimpleDetectorHostMonitor) NumEjections() uint32

func (*SimpleDetectorHostMonitor) PutResponseTime

func (hm *SimpleDetectorHostMonitor) PutResponseTime(time.Duration)

func (*SimpleDetectorHostMonitor) PutResult

func (hm *SimpleDetectorHostMonitor) PutResult(r Result)

func (*SimpleDetectorHostMonitor) ResetConsecutiveConnectionError

func (hm *SimpleDetectorHostMonitor) ResetConsecutiveConnectionError()

func (*SimpleDetectorHostMonitor) ResetConsecutiveError

func (hm *SimpleDetectorHostMonitor) ResetConsecutiveError()

func (*SimpleDetectorHostMonitor) SetSuccessRate

func (hm *SimpleDetectorHostMonitor) SetSuccessRate(newSuccessRate float64)

func (*SimpleDetectorHostMonitor) SuccessRate

func (hm *SimpleDetectorHostMonitor) SuccessRate() float64

func (*SimpleDetectorHostMonitor) SuccessRateAccumulator

func (hm *SimpleDetectorHostMonitor) SuccessRateAccumulator() *successRateAccumulator

func (*SimpleDetectorHostMonitor) Uneject

func (hm *SimpleDetectorHostMonitor) Uneject(t time.Time)

func (*SimpleDetectorHostMonitor) UpdateCurrentSuccessRateBucket

func (hm *SimpleDetectorHostMonitor) UpdateCurrentSuccessRateBucket()

type SubsetBalancer

type SubsetBalancer struct {
	LBType           BalanceType
	LBPanicThreshold int
	// contains filtered or unexported fields
}

func NewSubsetBalancer

func NewSubsetBalancer(hostSet *HostSet, lbType BalanceType, threshhold int, keys [][]string, defaultKVs []string, name string) *SubsetBalancer

func (*SubsetBalancer) ChooseHost

func (ss *SubsetBalancer) ChooseHost(ctx context.Context) *Host

func (*SubsetBalancer) Hosts

func (ss *SubsetBalancer) Hosts(ctx context.Context) []*Host

type WeightRoundRobinBalancer

type WeightRoundRobinBalancer struct {
	// contains filtered or unexported fields
}

func NewWeightRoundRobinBalancer

func NewWeightRoundRobinBalancer(set *HostSet, threshhold int) *WeightRoundRobinBalancer

func (*WeightRoundRobinBalancer) ChooseHost

func (wrr *WeightRoundRobinBalancer) ChooseHost(ctx context.Context) *Host

func (*WeightRoundRobinBalancer) Hosts

Jump to

Keyboard shortcuts

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