diff --git a/app/proxy/health.go b/app/proxy/health.go index 93c9502..bd7cecf 100644 --- a/app/proxy/health.go +++ b/app/proxy/health.go @@ -32,10 +32,14 @@ func (h *Http) healthHandler(w http.ResponseWriter, _ *http.Request) { // runs pings in parallel check := func(mappers []discovery.URLMapper) (ok bool, valid int, total int, errs []string) { outCh := make(chan error, concurrent) - pinged := 0 + services, pinged := 0, 0 var wg sync.WaitGroup for _, m := range mappers { - if m.MatchType != discovery.MTProxy || m.PingURL == "" { + if m.MatchType != discovery.MTProxy { + continue + } + services++ + if m.PingURL == "" { continue } sema <- struct{}{} @@ -73,7 +77,7 @@ func (h *Http) healthHandler(w http.ResponseWriter, _ *http.Request) { for e := range outCh { errs = append(errs, e.Error()) } - return len(errs) == 0, pinged - len(errs), len(mappers), errs + return len(errs) == 0, pinged - len(errs), services, errs } w.Header().Set("Content-Type", "application/json; charset=UTF-8") @@ -87,7 +91,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: valid, Failed: total - valid, Errors: errs} + }{Status: "failed", Services: total, Passed: valid, Failed: len(errs), Errors: errs} rest.RenderJSON(w, errResp) return diff --git a/app/proxy/health_test.go b/app/proxy/health_test.go index 202718a..398d4e7 100644 --- a/app/proxy/health_test.go +++ b/app/proxy/health_test.go @@ -44,6 +44,8 @@ func TestHttp_healthHandler(t *testing.T) { "localhost,^/api/(.*)," + ds.URL + "/123/$1," + ps.URL + "/123/ping", "localhost,^/xyz/(.*)," + ds.URL + "/123/$1," + ps.URL + "/xxx/ping", "127.0.0.1,^/api/(.*)," + ds.URL + "/567/$1," + ps.URL + "/567/ping", + "127.0.0.1,^/api/(.*)," + ds.URL + "/567/$1,", + "127.0.0.1,^/api/(.*),assets:/567/$1," + ps.URL + "/567/ping", }, }}, time.Millisecond*10) @@ -69,7 +71,7 @@ func TestHttp_healthHandler(t *testing.T) { err = json.NewDecoder(resp.Body).Decode(&res) require.NoError(t, err) assert.Equal(t, "failed", res["status"]) - assert.Equal(t, 3., res["services"]) + assert.Equal(t, 4., res["services"]) assert.Equal(t, 1., res["passed"]) assert.Equal(t, 2., res["failed"]) assert.Equal(t, 2, len(res["errors"].([]interface{})))