Toggle /ping to artificially return unhealthy response on SIGTERM during requestAcceptGraceTimeout interval
This commit is contained in:
parent
9699dc2a85
commit
5792a19b97
5 changed files with 45 additions and 4 deletions
27
ping/ping.go
27
ping/ping.go
|
@ -3,19 +3,38 @@ package ping
|
|||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"sync"
|
||||
|
||||
"github.com/containous/mux"
|
||||
)
|
||||
|
||||
//Handler expose ping routes
|
||||
// Handler expose ping routes
|
||||
type Handler struct {
|
||||
EntryPoint string `description:"Ping entryPoint" export:"true"`
|
||||
EntryPoint string `description:"Ping entryPoint" export:"true"`
|
||||
terminating bool
|
||||
lock sync.RWMutex
|
||||
}
|
||||
|
||||
// SetTerminating causes the ping endpoint to serve non 200 responses.
|
||||
func (g *Handler) SetTerminating() {
|
||||
g.lock.Lock()
|
||||
defer g.lock.Unlock()
|
||||
|
||||
g.terminating = true
|
||||
}
|
||||
|
||||
// AddRoutes add ping routes on a router
|
||||
func (g Handler) AddRoutes(router *mux.Router) {
|
||||
func (g *Handler) AddRoutes(router *mux.Router) {
|
||||
router.Methods(http.MethodGet, http.MethodHead).Path("/ping").
|
||||
HandlerFunc(func(response http.ResponseWriter, request *http.Request) {
|
||||
fmt.Fprint(response, "OK")
|
||||
g.lock.RLock()
|
||||
defer g.lock.RUnlock()
|
||||
|
||||
statusCode := http.StatusOK
|
||||
if g.terminating {
|
||||
statusCode = http.StatusServiceUnavailable
|
||||
}
|
||||
response.WriteHeader(statusCode)
|
||||
fmt.Fprint(response, http.StatusText(statusCode))
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue