Skip to content

Commit

Permalink
Don't set Interval on TTL health checks
Browse files Browse the repository at this point in the history
  • Loading branch information
schmichael committed Oct 17, 2017
1 parent 756737a commit a52cb34
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 30 deletions.
2 changes: 2 additions & 0 deletions command/agent/consul/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1064,6 +1064,8 @@ func createCheckReg(serviceID, checkID string, check *structs.ServiceCheck, host
chkReg.TCP = net.JoinHostPort(host, strconv.Itoa(port))
case structs.ServiceCheckScript:
chkReg.TTL = (check.Interval + ttlCheckBuffer).String()
// As of Consul 1.0.0 setting TTL and Interval is a 400
chkReg.Interval = ""
default:
return nil, fmt.Errorf("check type %+q not valid", check.Type)
}
Expand Down
47 changes: 17 additions & 30 deletions command/agent/consul/int_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/hashicorp/nomad/command/agent/consul"
"github.com/hashicorp/nomad/nomad/mock"
"github.com/hashicorp/nomad/nomad/structs"
"github.com/stretchr/testify/assert"
)

func testLogger() *log.Logger {
Expand All @@ -37,6 +38,8 @@ func TestConsul_Integration(t *testing.T) {
if testing.Short() {
t.Skip("-short set; skipping")
}
assert := assert.New(t)

// Create an embedded Consul server
testconsul, err := testutil.NewTestServerConfig(func(c *testutil.TestServerConfig) {
// If -v wasn't specified squelch consul logging
Expand Down Expand Up @@ -128,9 +131,8 @@ func TestConsul_Integration(t *testing.T) {
taskDir := allocDir.NewTaskDir(task.Name)
vclient := vaultclient.NewMockVaultClient()
consulClient, err := consulapi.NewClient(consulConfig)
if err != nil {
t.Fatalf("error creating consul client: %v", err)
}
assert.Nil(err)

serviceClient := consul.NewServiceClient(consulClient.Agent(), true, logger)
defer serviceClient.Shutdown() // just-in-case cleanup
consulRan := make(chan struct{})
Expand All @@ -154,9 +156,7 @@ func TestConsul_Integration(t *testing.T) {
// Block waiting for the service to appear
catalog := consulClient.Catalog()
res, meta, err := catalog.Service("httpd2", "test", nil)
if err != nil {
t.Fatalf("bad: %v", err)
}
assert.Nil(err)

for i := 0; len(res) == 0 && i < 10; i++ {
//Expected initial request to fail, do a blocking query
Expand All @@ -165,32 +165,25 @@ func TestConsul_Integration(t *testing.T) {
t.Fatalf("error querying for service: %v", err)
}
}
if len(res) != 1 {
t.Fatalf("expected 1 service but found %d:\n%#v", len(res), res)
}
assert.Len(res, 1)

// Truncate results
res = res[:]

// Assert the service with the checks exists
for i := 0; len(res) == 0 && i < 10; i++ {
res, meta, err = catalog.Service("httpd", "http", &consulapi.QueryOptions{WaitIndex: meta.LastIndex + 1, WaitTime: 3 * time.Second})
if err != nil {
t.Fatalf("error querying for service: %v", err)
}
}
if len(res) != 1 {
t.Fatalf("exepcted 1 service but found %d:\n%#v", len(res), res)
assert.Nil(err)
}
assert.Len(res, 1)

// Assert the script check passes (mock_driver script checks always
// pass) after having time to run once
time.Sleep(2 * time.Second)
checks, _, err := consulClient.Health().Checks("httpd", nil)
if err != nil {
t.Fatalf("error querying checks: %v", err)
}
if expected := 2; len(checks) != expected {
t.Fatalf("expected %d checks but found %d:\n%#v", expected, len(checks), checks)
}
assert.Nil(err)
assert.Len(checks, 2)

for _, check := range checks {
if expected := "httpd"; check.ServiceName != expected {
t.Fatalf("expected checks to be for %q but found service name = %q", expected, check.ServiceName)
Expand Down Expand Up @@ -244,13 +237,7 @@ func TestConsul_Integration(t *testing.T) {

// Ensure Consul is clean
services, _, err := catalog.Services(nil)
if err != nil {
t.Fatalf("error query services: %v", err)
}
if len(services) != 1 {
t.Fatalf("expected only 1 service in Consul but found %d:\n%#v", len(services), services)
}
if _, ok := services["consul"]; !ok {
t.Fatalf(`expected only the "consul" key in Consul but found: %#v`, services)
}
assert.Nil(err)
assert.Len(services, 1)
assert.Contains(services, "consul")
}

0 comments on commit a52cb34

Please sign in to comment.