From ebe1b0f381202c55bd8c40b7b85b22f5607d64f8 Mon Sep 17 00:00:00 2001 From: jebbs Date: Mon, 17 Oct 2022 17:10:23 +0800 Subject: [PATCH] fix health check --- balancer/healthcheck.go | 2 ++ balancer/healthcheck_nodes.go | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/balancer/healthcheck.go b/balancer/healthcheck.go index da54bc34..e92ebbde 100644 --- a/balancer/healthcheck.go +++ b/balancer/healthcheck.go @@ -109,6 +109,7 @@ func (h *HealthCheck) Check() { nodes := h.refreshNodes() h.mutex.Unlock() for _, n := range nodes { + n := n go h.checkNode(n) } } @@ -124,6 +125,7 @@ func (h *HealthCheck) CheckNodes() { nodes := h.refreshNodes() h.mutex.Unlock() for _, n := range nodes { + n := n delay := time.Duration(rand.Intn(int(h.options.Interval))) time.AfterFunc(delay, func() { h.checkNode(n) diff --git a/balancer/healthcheck_nodes.go b/balancer/healthcheck_nodes.go index e5a2e6d4..f1014103 100644 --- a/balancer/healthcheck_nodes.go +++ b/balancer/healthcheck_nodes.go @@ -59,6 +59,12 @@ func (h *HealthCheck) Nodes(network string) *Nodes { default: nodes.Qualified = append(nodes.Qualified, n) } + h.logger.Trace( + "[", n.Tag, "]", + " STD=", n.Deviation, + " AVG=", n.Average, + " Fail=", n.Fail, "/", n.All, + ) } return nodes } @@ -83,6 +89,7 @@ func (h *HealthCheck) refreshNodes() []adapter.Outbound { nodes := CoveredOutbounds(h.router, h.tags) tags := make(map[string]struct{}) for _, n := range nodes { + n := n tag := n.Tag() tags[tag] = struct{}{} // make it known to the health check results