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:
Miek Gieben
2017-08-27 21:33:38 +01:00
committed by Yong Tang
parent 9c56805d38
commit 558f4bea41
7 changed files with 149 additions and 22 deletions

View File

@@ -1,6 +1,10 @@
package health
import (
"net"
"time"
"github.com/coredns/coredns/core/dnsserver"
"github.com/coredns/coredns/middleware"
"github.com/mholt/caddy"
@@ -20,12 +24,32 @@ func setup(c *caddy.Controller) error {
}
h := &health{Addr: addr}
c.OnStartup(func() error {
for he := range healthers {
m := dnsserver.GetConfig(c).Handler(he)
if x, ok := m.(Healther); ok {
h.h = append(h.h, x)
}
}
return nil
})
c.OnStartup(func() error {
h.poll()
go func() {
for {
<-time.After(1 * time.Second)
h.poll()
}
}()
return nil
})
c.OnStartup(h.Startup)
c.OnShutdown(h.Shutdown)
// Don't do AddMiddleware, as health is not *really* a middleware just a separate
// webserver running.
// Don't do AddMiddleware, as health is not *really* a middleware just a separate webserver running.
return nil
}
@@ -38,6 +62,9 @@ func healthParse(c *caddy.Controller) (string, error) {
case 0:
case 1:
addr = args[0]
if _, _, e := net.SplitHostPort(addr); e != nil {
return "", e
}
default:
return "", c.ArgErr()
}