health.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package routing
  2. import "time"
  3. // HealthChecker is the interface for health checkers
  4. type HealthChecker interface {
  5. // StartScheduler starts the check scheduler
  6. StartScheduler(selector func() ([]string, error))
  7. // StopScheduler stops the check scheduler
  8. StopScheduler()
  9. // Check start the health checking for given tags.
  10. Check(tags []string) error
  11. }
  12. // OutboundInfo holds information of an outbound
  13. type OutboundInfo struct {
  14. Tag string // Tag of the outbound
  15. Values []string // Information of the outbound, which can be different between strategies, like health ping RTT
  16. }
  17. // StrategyInfo holds strategy running information, like selected handlers and others
  18. type StrategyInfo struct {
  19. Settings []string // Strategy settings
  20. ValueTitles []string // Value titles of OutboundInfo.Values
  21. Selects []*OutboundInfo // Selects of the strategy
  22. Others []*OutboundInfo // Other outbounds
  23. }
  24. // BalancingOverrideInfo holds balancing override information
  25. type BalancingOverrideInfo struct {
  26. Until time.Time
  27. Selects []string
  28. }
  29. // BalancerInfo holds information of a balancer
  30. type BalancerInfo struct {
  31. Tag string // Tag of the balancer
  32. Override *BalancingOverrideInfo
  33. Strategy *StrategyInfo // Strategy and its running information
  34. }
  35. // RouterChecker represents a router that is able to perform checks for its balancers, and get statistics.
  36. type RouterChecker interface {
  37. // CheckHanlders performs a health check for specified outbound hanlders.
  38. CheckHanlders(tags []string) error
  39. // CheckBalancers performs health checks for specified balancers,
  40. // if not specified, check them all.
  41. CheckBalancers(tags []string) error
  42. // GetBalancersInfo get health info of specific balancer, if balancer not specified, get all
  43. GetBalancersInfo(tags []string) ([]*BalancerInfo, error)
  44. }