对后端进行主动健康检查

支持对 static cluster 配置 cluster 维度的健康检查能力,配置包括使用的健康检查协议、interval、timeout等

  1. type HealthCheck struct {
  2. Protocol string
  3. Timeout time.Duration
  4. Interval time.Duration
  5. IntervalJitter time.Duration
  6. HealthyThreshold uint32
  7. UnhealthyThreshold uint32
  8. CheckPath string
  9. ServiceName string
  10. }

支持对非static cluster配置默认的健康检查能力,包括开关是否打开、使用的默认健康检查协议等,当前支持bolt作为默认的健康检查协议

  1. type ClusterManagerConfig struct {
  2. AutoDiscovery bool `json:"auto_discovery"`
  3. UseHealthCheckGlobal bool `json:"use_health_check_global"`
  4. Clusters []ClusterConfig `json:"clusters,omitempty"`
  5. }
  6. var DefaultSofaRpcHealthCheckConf = v2.HealthCheck{
  7. Protocol: SofaRpc,
  8. Timeout: DefaultBoltHeartBeatTimeout,
  9. HealthyThreshold: DefaultHealthyThreshold,
  10. UnhealthyThreshold: DefaultUnhealthyThreshold,
  11. Interval: DefaultBoltHeartBeatInterval,
  12. IntervalJitter: DefaultIntervalJitter,
  13. }

支持对于 cluster 内部所有 hostSet 的机器,单独运行健康检查,并根据健康检查的结果,更新 host 的健康状态

  1. // An upstream cluster (group of hosts).
  2. type Cluster interface {
  3. ...
  4. // set the cluster's health checker
  5. SetHealthChecker(hc HealthChecker)
  6. // return the cluster's health checker
  7. HealthChecker() HealthChecker
  8. OutlierDetector() Detector
  9. }

负载均衡算法基于健康检查的主机的健康状态动态选择健康机器

  1. func (l *randomloadbalancer) ChooseHost(context context.Context) types.Host {
  2. ...
  3. hosts := hostset.HealthyHosts()
  4. ....
  5. }