From f304a2f0e614f7f75641b0d2dabc8c12e75e56f9 Mon Sep 17 00:00:00 2001 From: Umputun Date: Sat, 17 Apr 2021 23:06:48 -0500 Subject: [PATCH] add total number of services to health error --- app/proxy/health.go | 11 ++++++----- app/proxy/health_test.go | 5 ++++- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/app/proxy/health.go b/app/proxy/health.go index 16e1c09..a82b729 100644 --- a/app/proxy/health.go +++ b/app/proxy/health.go @@ -81,11 +81,12 @@ func (h *Http) healthHandler(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(http.StatusExpectationFailed) errResp := struct { - Status string `json:"status,omitempty"` - Passed int `json:"passed,omitempty"` - Failed int `json:"failed,omitempty"` - Errors []string `json:"errors,omitempty"` - }{Status: "failed", Passed: valid, Failed: total - valid, Errors: errs} + Status string `json:"status,omitempty"` + Services int `json:"services,omitempty"` + 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} rest.RenderJSON(w, errResp) return diff --git a/app/proxy/health_test.go b/app/proxy/health_test.go index 5bf9ce1..f7b688f 100644 --- a/app/proxy/health_test.go +++ b/app/proxy/health_test.go @@ -41,6 +41,7 @@ func TestHttp_healthHandler(t *testing.T) { svc := discovery.NewService([]discovery.Provider{ &provider.Static{Rules: []string{ "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", }, }}, time.Millisecond*10) @@ -67,7 +68,9 @@ 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, 1., res["passed"]) - assert.Equal(t, 1., res["failed"]) + assert.Equal(t, 2., res["failed"]) + assert.Equal(t, 2, len(res["errors"].([]interface{}))) assert.Contains(t, res["errors"].([]interface{})[0], "400 Bad Request") }