Documentation ¶
Index ¶
- Variables
- type HealthCheck
- func (h *HealthCheck) CheckAll(ctx context.Context) (map[string]uint16, error)
- func (h *HealthCheck) CheckOutbound(ctx context.Context, tag string) (uint16, error)
- func (h *HealthCheck) CheckProvider(ctx context.Context, tag string) (map[string]uint16, error)
- func (h *HealthCheck) Close() error
- func (h *HealthCheck) InterfaceUpdated() error
- func (h *HealthCheck) ReportFailure(outbound adapter.Outbound)
- func (h *HealthCheck) Start() error
- type History
- type MetaData
- type RTT
- type Stats
- type Storage
- type Storages
Constants ¶
This section is empty.
Variables ¶
var (
ErrNoNetWork = errors.New("no network")
)
errors
Functions ¶
This section is empty.
Types ¶
type HealthCheck ¶
type HealthCheck struct { Storage *Storages // contains filtered or unexported fields }
HealthCheck is the health checker for balancers
func New ¶
func New( router adapter.Router, providers []adapter.Provider, providersByTag map[string]adapter.Provider, options *option.HealthCheckOptions, logger log.Logger, ) *HealthCheck
New creates a new HealthPing with settings.
The globalHistory is optional and is only used to sync latency history between different health checkers. Each HealthCheck will maintain its own history storage since different ones can have different check destinations, sampling numbers, etc.
func (*HealthCheck) CheckOutbound ¶
CheckOutbound performs check for the specified node
func (*HealthCheck) CheckProvider ¶
CheckProvider performs checks for nodes of the provider
func (*HealthCheck) Close ¶
func (h *HealthCheck) Close() error
Close stops the health check service, implements adapter.Service
func (*HealthCheck) InterfaceUpdated ¶
func (h *HealthCheck) InterfaceUpdated() error
InterfaceUpdated implements adapter.InterfaceUpdateListener
func (*HealthCheck) ReportFailure ¶
func (h *HealthCheck) ReportFailure(outbound adapter.Outbound)
ReportFailure reports a failure of the node
func (*HealthCheck) Start ¶
func (h *HealthCheck) Start() error
Start starts the health check service, implements adapter.Service
type MetaData ¶
MetaData is the context for health check, it collects network connectivity status and checked status of outbounds
About connectivity status collection:
Consider the health checks are done asynchronously, success checks will report network is available in a short time, after that, there will be failure checks query the network connectivity. So,
1. In cases of any one check success, the network is known to be available, no extra connectivity check needed.
2. In cases of all checks failed, we can not distinguesh from the network is down or all nodes are dead. Only in this case we need to do connectivity check, and it's rare.
func NewMetaData ¶
NewMetaData creates a new MetaData
func (*MetaData) ReportChecked ¶
ReportChecked reports the outbound of the tag is checked
func (*MetaData) ReportConnected ¶
func (c *MetaData) ReportConnected()
ReportConnected reports the network is connected
type RTT ¶
type RTT uint16
RTT is the round trip time with underlying type uint16, precision is millisecond
const ( // Failed is a special value to indicate a failed check // or unable to get a valid result, e.g.: average RTT // will be Fail(0) if a node is never tested. Failed RTT = 0 Millisecond RTT = 1 Second RTT = 1000 )
RTT constant values
func RTTOf ¶
func RTTOf[T preciseDuration](d T) RTT
RTTOf converts a precise duration (underlying type int64, like `time.Duration`) to `rtt.Duration`
func RTTsOf ¶
func RTTsOf[T preciseDuration](values []T) []RTT
RTTsOf converts precise durations (underlying type int64, like `[]time.Duration`) to `[]rtt.Duration`
func (RTT) TimeDuration ¶
TimeDuration converts a rtt.Duration to time.Duration
type Stats ¶
type Stats struct { All int // total number of health checks Fail int // number of failed health checks Deviation RTT // standard deviation of RTTs Average RTT // average RTT of all health checks Max RTT // maximum RTT of all health checks Min RTT // minimum RTT of all health checks Latest RTT // latest RTT of all health checks Expires time.Time // time of the statistics expires }
Stats is the statistics of RTTs
type Storage ¶
type Storage struct {
// contains filtered or unexported fields
}
Storage holds ping rtts for health Checker, it's not thread safe
func NewStorage ¶
NewStorage returns a new rtt storage with specified capacity
func (*Storage) Get ¶
Get gets the history at the offset to the latest history, ignores the validity
type Storages ¶
Storages is the storages for different tags (nodes)
func NewStorages ¶
NewStorages returns a new Storages