summaryrefslogtreecommitdiff
path: root/modules/caddyhttp/reverseproxy/healthchecks.go
diff options
context:
space:
mode:
authorMatthew Holt <mholt@users.noreply.github.com>2019-09-03 16:56:09 -0600
committerMatthew Holt <mholt@users.noreply.github.com>2019-09-03 16:56:09 -0600
commit652460e03e11a037d9f86b09b3546c9e42733d2d (patch)
tree9b1042f3fc880f87ca25949618fea45e6960080a /modules/caddyhttp/reverseproxy/healthchecks.go
parent4a1e1649bc985e9658d326ed433a101d7d79ae30 (diff)
Some cleanup and godoc
Diffstat (limited to 'modules/caddyhttp/reverseproxy/healthchecks.go')
-rw-r--r--modules/caddyhttp/reverseproxy/healthchecks.go12
1 files changed, 12 insertions, 0 deletions
diff --git a/modules/caddyhttp/reverseproxy/healthchecks.go b/modules/caddyhttp/reverseproxy/healthchecks.go
index 96649a4..0b46d04 100644
--- a/modules/caddyhttp/reverseproxy/healthchecks.go
+++ b/modules/caddyhttp/reverseproxy/healthchecks.go
@@ -30,11 +30,15 @@ import (
"github.com/caddyserver/caddy/v2/modules/caddyhttp"
)
+// HealthChecks holds configuration related to health checking.
type HealthChecks struct {
Active *ActiveHealthChecks `json:"active,omitempty"`
Passive *PassiveHealthChecks `json:"passive,omitempty"`
}
+// ActiveHealthChecks holds configuration related to active
+// health checks (that is, health checks which occur in a
+// background goroutine independently).
type ActiveHealthChecks struct {
Path string `json:"path,omitempty"`
Port int `json:"port,omitempty"`
@@ -49,6 +53,9 @@ type ActiveHealthChecks struct {
bodyRegexp *regexp.Regexp
}
+// PassiveHealthChecks holds configuration related to passive
+// health checks (that is, health checks which occur during
+// the normal flow of request proxying).
type PassiveHealthChecks struct {
MaxFails int `json:"max_fails,omitempty"`
FailDuration caddy.Duration `json:"fail_duration,omitempty"`
@@ -57,6 +64,9 @@ type PassiveHealthChecks struct {
UnhealthyLatency caddy.Duration `json:"unhealthy_latency,omitempty"`
}
+// activeHealthChecker runs active health checks on a
+// regular basis and blocks until
+// h.HealthChecks.Active.stopChan is closed.
func (h *Handler) activeHealthChecker() {
ticker := time.NewTicker(time.Duration(h.HealthChecks.Active.Interval))
h.doActiveHealthChecksForAllHosts()
@@ -71,6 +81,8 @@ func (h *Handler) activeHealthChecker() {
}
}
+// doActiveHealthChecksForAllHosts immediately performs a
+// health checks for all hosts in the global repository.
func (h *Handler) doActiveHealthChecksForAllHosts() {
hosts.Range(func(key, value interface{}) bool {
addr := key.(string)