diff --git a/app/discovery/discovery.go b/app/discovery/discovery.go index 50645a7..91204ef 100644 --- a/app/discovery/discovery.go +++ b/app/discovery/discovery.go @@ -138,10 +138,7 @@ func (s *Service) Match(srv, src string) (string, MatchType, bool) { case MTProxy: dest := m.SrcMatch.ReplaceAllString(src, m.Dst) if src != dest { - if m.IsAlive() { - return dest, m.MatchType, true - } - return dest, m.MatchType, false + return dest, m.MatchType, m.IsAlive() } case MTStatic: if src == m.AssetsWebRoot || strings.HasPrefix(src, m.AssetsWebRoot+"/") { @@ -160,15 +157,16 @@ func (s *Service) ScheduleHealthCheck(ctx context.Context, interval time.Duratio go func() { ticker := time.NewTicker(interval) + defer ticker.Stop() for { select { case <-ticker.C: - pinged := s.CheckHealth() + pingErrs := s.CheckHealth() s.lock.Lock() for _, mappers := range s.mappers { for i := range mappers { - if err, ok := pinged[mappers[i].PingURL]; ok { + if err, ok := pingErrs[mappers[i].PingURL]; ok { mappers[i].dead = false if err != nil { mappers[i].dead = true @@ -178,7 +176,6 @@ func (s *Service) ScheduleHealthCheck(ctx context.Context, interval time.Duratio } s.lock.Unlock() case <-ctx.Done(): - ticker.Stop() return } } diff --git a/app/proxy/health.go b/app/proxy/health.go index cbf292b..a056b82 100644 --- a/app/proxy/health.go +++ b/app/proxy/health.go @@ -32,10 +32,10 @@ func (h *Http) healthHandler(w http.ResponseWriter, _ *http.Request) { } } - pingRes := h.CheckHealth() + pingErrs := h.CheckHealth() var errs []string - for _, pingErr := range pingRes { + for _, pingErr := range pingErrs { if pingErr != nil { errs = append(errs, pingErr.Error()) } @@ -50,7 +50,7 @@ func (h *Http) healthHandler(w http.ResponseWriter, _ *http.Request) { Passed int `json:"passed,omitempty"` Failed int `json:"failed,omitempty"` Errors []string `json:"errors,omitempty"` - }{Status: "failed", Services: total, Passed: len(pingRes) - len(errs), Failed: len(errs), Errors: errs} + }{Status: "failed", Services: total, Passed: len(pingErrs) - len(errs), Failed: len(errs), Errors: errs} rest.RenderJSON(w, errResp) return