ISSUE-4244 comply with --health-check-path (#4619)
This commit is contained in:
parent
d5d2b4037c
commit
203a3ed455
2 changed files with 89 additions and 75 deletions
|
@ -135,7 +135,7 @@ func main() {
|
|||
go registerProfiler()
|
||||
}
|
||||
|
||||
registerHealthz(ngx, mux)
|
||||
registerHealthz(nginx.HealthPath, ngx, mux)
|
||||
registerMetrics(reg, mux)
|
||||
registerHandlers(mux)
|
||||
|
||||
|
@ -247,9 +247,10 @@ func registerHandlers(mux *http.ServeMux) {
|
|||
})
|
||||
}
|
||||
|
||||
func registerHealthz(ic *controller.NGINXController, mux *http.ServeMux) {
|
||||
func registerHealthz(healthPath string, ic *controller.NGINXController, mux *http.ServeMux) {
|
||||
// expose health check endpoint (/healthz)
|
||||
healthz.InstallHandler(mux,
|
||||
healthz.InstallPathHandler(mux,
|
||||
healthPath,
|
||||
healthz.PingHealthz,
|
||||
ic,
|
||||
)
|
||||
|
|
|
@ -33,6 +33,17 @@ import (
|
|||
)
|
||||
|
||||
func TestNginxCheck(t *testing.T) {
|
||||
var tests = []struct {
|
||||
healthzPath string
|
||||
}{
|
||||
{"/healthz"},
|
||||
{"/not-healthz"},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
testName := fmt.Sprintf("health path: %s", tt.healthzPath)
|
||||
t.Run(testName, func(t *testing.T) {
|
||||
|
||||
mux := http.NewServeMux()
|
||||
|
||||
listener, err := net.Listen("tcp", fmt.Sprintf(":%v", nginx.StatusPort))
|
||||
|
@ -60,7 +71,7 @@ func TestNginxCheck(t *testing.T) {
|
|||
}
|
||||
|
||||
t.Run("no pid or process", func(t *testing.T) {
|
||||
if err := callHealthz(true, mux); err == nil {
|
||||
if err := callHealthz(true, tt.healthzPath, mux); err == nil {
|
||||
t.Error("expected an error but none returned")
|
||||
}
|
||||
})
|
||||
|
@ -73,7 +84,7 @@ func TestNginxCheck(t *testing.T) {
|
|||
}
|
||||
|
||||
t.Run("no process", func(t *testing.T) {
|
||||
if err := callHealthz(true, mux); err == nil {
|
||||
if err := callHealthz(true, tt.healthzPath, mux); err == nil {
|
||||
t.Error("expected an error but none returned")
|
||||
}
|
||||
})
|
||||
|
@ -90,10 +101,10 @@ func TestNginxCheck(t *testing.T) {
|
|||
pidFile.Write([]byte(fmt.Sprintf("%v", pid)))
|
||||
pidFile.Close()
|
||||
|
||||
healthz.InstallHandler(mux, n)
|
||||
healthz.InstallPathHandler(mux, tt.healthzPath, n)
|
||||
|
||||
t.Run("valid request", func(t *testing.T) {
|
||||
if err := callHealthz(false, mux); err != nil {
|
||||
if err := callHealthz(false, tt.healthzPath, mux); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
})
|
||||
|
@ -103,14 +114,16 @@ func TestNginxCheck(t *testing.T) {
|
|||
pidFile.Close()
|
||||
|
||||
t.Run("bad pid", func(t *testing.T) {
|
||||
if err := callHealthz(true, mux); err == nil {
|
||||
if err := callHealthz(true, tt.healthzPath, mux); err == nil {
|
||||
t.Error("expected an error but none returned")
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func callHealthz(expErr bool, mux *http.ServeMux) error {
|
||||
req, err := http.NewRequest("GET", "/healthz", nil)
|
||||
func callHealthz(expErr bool, healthzPath string, mux *http.ServeMux) error {
|
||||
req, err := http.NewRequest("GET", healthzPath, nil)
|
||||
if err != nil {
|
||||
return fmt.Errorf("healthz error: %v", err)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue