mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 03:41:45 +00:00
Merge pull request #34410 from yuexiao-wang/heathz-log
Automatic merge from submit-queue (batch tested with PRs 37708, 34410) Fix some logs and commend information for healthz Fix some logs which should be a lower case letter for the first letter and modify some commend information which is consistent in context. Signed-off-by: yuexiao-wang wang.yuexiao@zte.com.cn
This commit is contained in:
commit
67d0f170b3
@ -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")
|
||||
}
|
||||
|
@ -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},
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user