Changed the http field to path

This commit is contained in:
Diptanu Choudhury 2015-11-18 13:02:25 -08:00
parent 7141b11c16
commit bb7f29f023
3 changed files with 9 additions and 7 deletions

View file

@ -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

View file

@ -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:

View file

@ -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
}