Skip to content

Commit

Permalink
Consul: Use native HTTP checks instead of check-http wrapper
Browse files Browse the repository at this point in the history
This also adds support for HTTP check timeout
  • Loading branch information
jstasiak committed May 19, 2015
1 parent 66add71 commit d41132a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ All notable changes to this project will be documented in this file.
### Changed
- Overall refactoring and cleanup
- Decoupled registries into subpackages using extpoints
- Replaced check-http script with Consul's native HTTP checks
(requires Consul >= 0.5)


## [v5] - 2015-02-18
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,12 @@ When using the Consul's service catalog backend, you can specify a health check

#### Basic HTTP health check

This feature is only available when using the `check-http` script that comes with the [progrium/consul](https://github.com/progrium/docker-consul#health-checking-with-docker) container for Consul.
This feature is only available when using Consul 0.5 or newer.

SERVICE_80_CHECK_HTTP=/health/endpoint/path
SERVICE_80_CHECK_INTERVAL=15s
# Optional, Consul default value is used when not specified
SERVICE_80_CHECK_TIMEOUT=1s

It works for an HTTP service on any port, not just 80. If its the only service, you can also use `SERVICE_CHECK_HTTP`.

Expand Down
7 changes: 5 additions & 2 deletions consul/consul.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ func (r *ConsulAdapter) Register(service *bridge.Service) error {
func (r *ConsulAdapter) buildCheck(service *bridge.Service) *consulapi.AgentServiceCheck {
check := new(consulapi.AgentServiceCheck)
if path := service.Attrs["check_http"]; path != "" {
check.Script = fmt.Sprintf("check-http %s %s %s", service.Origin.ContainerID[:12], service.Origin.ExposedPort, path)
check.HTTP = fmt.Sprintf("http://%s:%d%s", service.IP, service.Port, path)
if timeout := service.Attrs["check_timeout"]; timeout != "" {
check.Timeout = timeout
}
} else if cmd := service.Attrs["check_cmd"]; cmd != "" {
check.Script = fmt.Sprintf("check-cmd %s %s %s", service.Origin.ContainerID[:12], service.Origin.ExposedPort, cmd)
} else if script := service.Attrs["check_script"]; script != "" {
Expand All @@ -76,7 +79,7 @@ func (r *ConsulAdapter) buildCheck(service *bridge.Service) *consulapi.AgentServ
} else {
return nil
}
if check.Script != "" {
if check.Script != "" || check.HTTP != "" {
if interval := service.Attrs["check_interval"]; interval != "" {
check.Interval = interval
} else {
Expand Down

0 comments on commit d41132a

Please sign in to comment.