diff --git a/api/tasks.go b/api/tasks.go index 2990b5433..c378c222d 100644 --- a/api/tasks.go +++ b/api/tasks.go @@ -27,7 +27,7 @@ type ServiceCheck struct { Name string Type string Script string - Http string + Path string Protocol string Interval time.Duration Timeout time.Duration diff --git a/client/consul.go b/client/consul.go index b3fdfe6c1..0c2988a52 100644 --- a/client/consul.go +++ b/client/consul.go @@ -6,6 +6,7 @@ import ( "github.com/hashicorp/go-multierror" "github.com/hashicorp/nomad/nomad/structs" "log" + "path" "sync" "time" ) @@ -180,7 +181,8 @@ func (c *ConsulClient) makeChecks(service *structs.Service, ip string, port int) } switch check.Type { case structs.ServiceCheckHTTP: - c.HTTP = fmt.Sprintf("%s://%s:%d/%s", check.Protocol, ip, port, check.Http) + baseUrl := fmt.Sprintf("%s://%s:%d", check.Protocol, ip, port) + c.HTTP = path.Join(baseUrl, check.Path) case structs.ServiceCheckTCP: c.TCP = fmt.Sprintf("%s:%d", ip, port) case structs.ServiceCheckScript: diff --git a/nomad/structs/structs.go b/nomad/structs/structs.go index 5ff8d8c3b..876bb0c39 100644 --- a/nomad/structs/structs.go +++ b/nomad/structs/structs.go @@ -1009,7 +1009,7 @@ type ServiceCheck struct { Name string // Name of the check, defaults to id Type string // Type of the check - tcp, http, docker and script Script string // Script to invoke for script check - Http string // path of the health check url for http type check + Path string // path of the health check url for http type check Protocol string // Protocol to use if check is http, defaults to http Interval time.Duration // Interval of the check Timeout time.Duration // Timeout of the response from the check before consul fails the check @@ -1017,16 +1017,16 @@ type ServiceCheck struct { func (sc *ServiceCheck) Validate() error { t := strings.ToLower(sc.Type) - if sc.Type == ServiceCheckHTTP && sc.Http == "" { + if t != ServiceCheckTCP && t != ServiceCheckHTTP { + return fmt.Errorf("Check with name %v has invalid check type: %s ", sc.Name, sc.Type) + } + if sc.Type == ServiceCheckHTTP && sc.Path == "" { return fmt.Errorf("http checks needs the Http path information.") } if sc.Type == ServiceCheckScript && sc.Script == "" { return fmt.Errorf("Script checks need the script to invoke") } - if t != ServiceCheckTCP && t != ServiceCheckHTTP { - return fmt.Errorf("Check with name %v has invalid check type: %s ", sc.Name, sc.Type) - } return nil }