Skip to content

Commit

Permalink
consul: checks get stored properly
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanuber committed Jan 10, 2015
1 parent 4ec78a8 commit 97c5d53
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions consul/catalog_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ func (c *Catalog) Register(args *structs.RegisterRequest, reply *struct{}) error

if args.Check != nil {
args.Checks = append(args.Checks, args.Check)
args.Check = nil
}
for _, check := range args.Checks {
if check.CheckID == "" && check.Name != "" {
Expand Down
7 changes: 6 additions & 1 deletion consul/state_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -497,12 +497,17 @@ func (s *StateStore) EnsureRegistration(index uint64, req *structs.RegisterReque
}
}

// Ensure the check if provided
// Ensure the check(s), if provided
if req.Check != nil {
if err := s.ensureCheckTxn(index, req.Check, tx); err != nil {
return err
}
}
for _, check := range req.Checks {
if err := s.ensureCheckTxn(index, check, tx); err != nil {
return err
}
}

// Commit as one unit
return tx.Commit()
Expand Down
11 changes: 10 additions & 1 deletion consul/state_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ func TestEnsureRegistration(t *testing.T) {
Status: structs.HealthPassing,
ServiceID: "api",
},
Checks: structs.HealthChecks{
&structs.HealthCheck{
Node: "foo",
CheckID: "api-cache",
Name: "Can cache stuff",
Status: structs.HealthPassing,
ServiceID: "api",
},
},
}

if err := store.EnsureRegistration(13, reg); err != nil {
Expand Down Expand Up @@ -60,7 +69,7 @@ func TestEnsureRegistration(t *testing.T) {
if idx != 13 {
t.Fatalf("bad: %v", idx)
}
if len(checks) != 1 {
if len(checks) != 2 {
t.Fatalf("check: %#v", checks)
}
}
Expand Down

0 comments on commit 97c5d53

Please sign in to comment.