Add configurable file-existence and HTTP health checks

Add a section to the config file called "health". Within this section,
"filecheckers" and "httpcheckers" list checks to run. Each check
specifies a file or URI, a time interval for the check, and a threshold
specifying how many times the check must fail to reach an unhealthy
state.

Document the new options in docs/configuration.md.

Add unit testing for both types of checkers. Add an UnregisterAll
function in the health package to support the unit tests, and an
Unregister function for consistency with Register.

Fix a string conversion problem in the health package's HTTP checker.

Signed-off-by: Aaron Lehmann <aaron.lehmann@docker.com>
This commit is contained in:
Aaron Lehmann 2015-08-18 17:19:46 -07:00
parent e4b93d1e6d
commit b09b0ffcf9
6 changed files with 428 additions and 3 deletions

View file

@ -170,6 +170,20 @@ func Register(name string, check Checker) {
registeredChecks[name] = check
}
// Unregister removes the named checker.
func Unregister(name string) {
mutex.Lock()
defer mutex.Unlock()
delete(registeredChecks, name)
}
// UnregisterAll removes all registered checkers.
func UnregisterAll() {
mutex.Lock()
defer mutex.Unlock()
registeredChecks = make(map[string]Checker)
}
// RegisterFunc allows the convenience of registering a checker directly
// from an arbitrary func() error
func RegisterFunc(name string, check func() error) {