diff --git a/api/services.go b/api/services.go index d7cb87e57af3..50932ccf0439 100644 --- a/api/services.go +++ b/api/services.go @@ -95,6 +95,7 @@ type ServiceCheck struct { TaskName string `mapstructure:"task" hcl:"task,optional"` SuccessBeforePassing int `mapstructure:"success_before_passing" hcl:"success_before_passing,optional"` FailuresBeforeCritical int `mapstructure:"failures_before_critical" hcl:"failures_before_critical,optional"` + Body string `hcl:"body,optional"` OnUpdate string `mapstructure:"on_update" hcl:"on_update,optional"` } diff --git a/command/agent/consul/service_client.go b/command/agent/consul/service_client.go index 66c00225c598..05ca9e9879f8 100644 --- a/command/agent/consul/service_client.go +++ b/command/agent/consul/service_client.go @@ -1408,6 +1408,7 @@ func createCheckReg(serviceID, checkID string, check *structs.ServiceCheck, host chkReg.HTTP = checkURL.String() chkReg.Method = check.Method chkReg.Header = check.Header + chkReg.Body = check.Body case structs.ServiceCheckTCP: chkReg.TCP = net.JoinHostPort(host, strconv.Itoa(port)) diff --git a/jobspec/parse_service.go b/jobspec/parse_service.go index c8778cbb09ae..9d7ff22cd684 100644 --- a/jobspec/parse_service.go +++ b/jobspec/parse_service.go @@ -852,6 +852,7 @@ func parseChecks(service *api.Service, checkObjs *ast.ObjectList) error { "tls_skip_verify", "header", "method", + "body", "check_restart", "address_mode", "grpc_service", diff --git a/jobspec/parse_test.go b/jobspec/parse_test.go index b0f397f1beb3..d373221cc8d9 100644 --- a/jobspec/parse_test.go +++ b/jobspec/parse_test.go @@ -1349,6 +1349,47 @@ func TestParse(t *testing.T) { }, false, }, + { + "tg-service-check-body.hcl", + &api.Job{ + ID: stringToPtr("group_service_check_script"), + Name: stringToPtr("group_service_check_script"), + TaskGroups: []*api.TaskGroup{ + { + Name: stringToPtr("group"), + Count: intToPtr(1), + Networks: []*api.NetworkResource{ + { + Mode: "bridge", + ReservedPorts: []api.Port{ + { + Label: "http", + Value: 80, + To: 8080, + }, + }, + }, + }, + Services: []*api.Service{ + { + Name: "foo-service", + PortLabel: "http", + Checks: []api.ServiceCheck{ + { + Name: "check-name", + Type: "http", + Method: "POST", + Body: "{\"check\":\"mem\"}", + }, + }, + }, + }, + Tasks: []*api.Task{{Name: "foo"}}, + }, + }, + }, + false, + }, { "tg-service-connect-native.hcl", &api.Job{ diff --git a/jobspec/test-fixtures/tg-service-check-body.hcl b/jobspec/test-fixtures/tg-service-check-body.hcl new file mode 100644 index 000000000000..ef19cd7a4dbc --- /dev/null +++ b/jobspec/test-fixtures/tg-service-check-body.hcl @@ -0,0 +1,28 @@ +job "group_service_check_script" { + group "group" { + count = 1 + + network { + mode = "bridge" + + port "http" { + static = 80 + to = 8080 + } + } + + service { + name = "foo-service" + port = "http" + + check { + name = "check-name" + type = "http" + method = "POST" + body = "{\"check\":\"mem\"}" + } + } + + task "foo" {} + } +} diff --git a/nomad/structs/diff_test.go b/nomad/structs/diff_test.go index 2d1637c19c14..0da24d457b3f 100644 --- a/nomad/structs/diff_test.go +++ b/nomad/structs/diff_test.go @@ -2805,6 +2805,12 @@ func TestTaskGroupDiff(t *testing.T) { Old: "", New: "", }, + { + Type: DiffTypeNone, + Name: "Body", + Old: "", + New: "", + }, { Type: DiffTypeEdited, Name: "Command", @@ -5996,6 +6002,12 @@ func TestTaskDiff(t *testing.T) { Old: "", New: "", }, + { + Type: DiffTypeNone, + Name: "Body", + Old: "", + New: "", + }, { Type: DiffTypeNone, Name: "Command", diff --git a/nomad/structs/services.go b/nomad/structs/services.go index 03a777f883ed..5355e5b6093d 100644 --- a/nomad/structs/services.go +++ b/nomad/structs/services.go @@ -61,6 +61,7 @@ type ServiceCheck struct { TaskName string // What task to execute this check in SuccessBeforePassing int // Number of consecutive successes required before considered healthy FailuresBeforeCritical int // Number of consecutive failures required before considered unhealthy + Body string // Body to use in HTTP check OnUpdate string } @@ -168,6 +169,10 @@ func (sc *ServiceCheck) Equals(o *ServiceCheck) bool { return false } + if sc.Body != o.Body { + return false + } + if sc.OnUpdate != o.OnUpdate { return false } diff --git a/vendor/github.com/hashicorp/nomad/api/services.go b/vendor/github.com/hashicorp/nomad/api/services.go index d7cb87e57af3..50932ccf0439 100644 --- a/vendor/github.com/hashicorp/nomad/api/services.go +++ b/vendor/github.com/hashicorp/nomad/api/services.go @@ -95,6 +95,7 @@ type ServiceCheck struct { TaskName string `mapstructure:"task" hcl:"task,optional"` SuccessBeforePassing int `mapstructure:"success_before_passing" hcl:"success_before_passing,optional"` FailuresBeforeCritical int `mapstructure:"failures_before_critical" hcl:"failures_before_critical,optional"` + Body string `hcl:"body,optional"` OnUpdate string `mapstructure:"on_update" hcl:"on_update,optional"` }