plugin/health: implement dyn health checks (#1214)

Implement health.Healther in erratic and kubernetes plugin. The
kubernetes' healtcheck is only performed on startup - i.e. turn
healthy after the initial loading.

Erratic follow the drop count: every query%drop turns the healthcheck
unhealthy.

Fixes: #985
This commit is contained in:
Miek Gieben
2017-11-13 09:52:40 +00:00
committed by GitHub
parent 46a187df8f
commit 52b49f4838
7 changed files with 49 additions and 8 deletions

View File

@@ -16,6 +16,13 @@ a 503. *health* periodically (1s) polls plugin that exports health information.
plugin signals that it is unhealthy, the server will go unhealthy too. Each plugin that
supports health checks has a section "Health" in their README.
## Plugins
The following plugins report health to the health plugin:
* erratic
* kubernetes
## Examples
Run another health endpoint on http://localhost:8091.

View File

@@ -1,7 +1,14 @@
package health
// TODO(miek): enable again if plugin gets health check.
/*
import (
"fmt"
"io/ioutil"
"net/http"
"testing"
"github.com/coredns/coredns/plugin/erratic"
)
func TestHealth(t *testing.T) {
h := health{Addr: ":0"}
h.h = append(h.h, &erratic.Erratic{})
@@ -14,7 +21,7 @@ func TestHealth(t *testing.T) {
// Reconstruct the http address based on the port allocated by operating system.
address := fmt.Sprintf("http://%s%s", h.ln.Addr().String(), path)
// Norhing set should be unhealthy
// Nothing set should return unhealthy
response, err := http.Get(address)
if err != nil {
t.Fatalf("Unable to query %s: %v", address, err)
@@ -24,8 +31,7 @@ func TestHealth(t *testing.T) {
}
response.Body.Close()
// Make healthy
h.Poll()
h.poll()
response, err = http.Get(address)
if err != nil {
@@ -44,4 +50,3 @@ func TestHealth(t *testing.T) {
t.Errorf("Invalid response body: expecting 'OK', got '%s'", string(content))
}
}
*/

View File

@@ -38,5 +38,7 @@ func (h *health) poll() {
}
// Plugins that implements the Healther interface.
// TODO(miek): none yet.
var healthers = map[string]bool{}
var healthers = map[string]bool{
"erratic": true,
"kubernetes": true,
}