Fix some logs and commend informations for healthz

Signed-off-by: yuexiao-wang <wang.yuexiao@zte.com.cn>
This commit is contained in:
yuexiao-wang 2016-10-09 17:24:50 +08:00
parent 853ee4c9f7
commit 0c4974a31a
2 changed files with 8 additions and 8 deletions

View File

@ -23,7 +23,7 @@ import (
"sync"
)
// HealthzChecker is a named healthz check.
// HealthzChecker is a named healthz checker.
type HealthzChecker interface {
Name() string
Check(req *http.Request) error
@ -41,7 +41,7 @@ func DefaultHealthz(checks ...HealthzChecker) {
// PingHealthz returns true automatically when checked
var PingHealthz HealthzChecker = ping{}
// ping implements the simplest possible health checker.
// ping implements the simplest possible healthz checker.
type ping struct{}
func (ping) Name() string {
@ -53,7 +53,7 @@ func (ping) Check(_ *http.Request) error {
return nil
}
// NamedCheck returns a health checker for the given name and function.
// NamedCheck returns a healthz checker for the given name and function.
func NamedCheck(name string, check func(r *http.Request) error) HealthzChecker {
return &healthzCheck{name, check}
}
@ -125,7 +125,7 @@ func adaptCheckToHandler(c func(r *http.Request) error) http.HandlerFunc {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
err := c(r)
if err != nil {
http.Error(w, fmt.Sprintf("Internal server error: %v", err), http.StatusInternalServerError)
http.Error(w, fmt.Sprintf("internal server error: %v", err), http.StatusInternalServerError)
} else {
fmt.Fprint(w, "ok")
}

View File

@ -29,15 +29,15 @@ func TestInstallHandler(t *testing.T) {
InstallHandler(mux)
req, err := http.NewRequest("GET", "http://example.com/healthz", nil)
if err != nil {
t.Fatalf("Unexpected error: %v", err)
t.Fatalf("unexpected error: %v", err)
}
w := httptest.NewRecorder()
mux.ServeHTTP(w, req)
if w.Code != http.StatusOK {
t.Errorf("Expected %v, got %v", http.StatusOK, w.Code)
t.Errorf("expected %v, got %v", http.StatusOK, w.Code)
}
if w.Body.String() != "ok" {
t.Errorf("Expected %v, got %v", "ok", w.Body.String())
t.Errorf("expected %v, got %v", "ok", w.Body.String())
}
}
@ -53,7 +53,7 @@ func TestMulitipleChecks(t *testing.T) {
{"/healthz", "ok", http.StatusOK, false},
{"/healthz?verbose", "[+]ping ok\n[-]bad failed: this will fail\nhealthz check failed\n", http.StatusInternalServerError, true},
{"/healthz/ping", "ok", http.StatusOK, true},
{"/healthz/bad", "Internal server error: this will fail\n", http.StatusInternalServerError, true},
{"/healthz/bad", "internal server error: this will fail\n", http.StatusInternalServerError, true},
{"/healthz", "[+]ping ok\n[-]bad failed: this will fail\nhealthz check failed\n", http.StatusInternalServerError, true},
}