mirror of
https://github.com/coredns/coredns.git
synced 2025-12-15 23:05:16 -05:00
mw/health: poll other middleware (#976)
This add the infrastructure to let other middleware report their health status back to the health middleware. A health.Healther interface is introduced and a middleware needs to implement that. A middleware that supports healthchecks is statically configured. Every second each supported middleware is queried and the global health state is updated. Actual tests have been disabled as no other middleware implements this at the moment.
This commit is contained in:
@@ -16,6 +16,11 @@ type health struct {
|
||||
|
||||
ln net.Listener
|
||||
mux *http.ServeMux
|
||||
|
||||
// A slice of Healthers that the health middleware will poll every second for their health status.
|
||||
h []Healther
|
||||
sync.RWMutex
|
||||
ok bool // ok is the global boolean indicating an all healthy middleware stack
|
||||
}
|
||||
|
||||
func (h *health) Startup() error {
|
||||
@@ -35,7 +40,12 @@ func (h *health) Startup() error {
|
||||
h.mux = http.NewServeMux()
|
||||
|
||||
h.mux.HandleFunc(path, func(w http.ResponseWriter, r *http.Request) {
|
||||
io.WriteString(w, ok)
|
||||
if h.Ok() {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
io.WriteString(w, ok)
|
||||
return
|
||||
}
|
||||
w.WriteHeader(http.StatusServiceUnavailable)
|
||||
})
|
||||
|
||||
go func() {
|
||||
|
||||
Reference in New Issue
Block a user