Skip to content

Commit

Permalink
Support wildcard for check lookup. Fixes #152
Browse files Browse the repository at this point in the history
  • Loading branch information
armon committed May 21, 2014
1 parent de30905 commit e55a6fb
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ IMPROVEMENTS:
* Allow raw key value lookup [GH-150]
* Log encryption enabled [GH-151]
* Support `-rejoin` to rejoin a cluster after a previous leave. [GH-110]
* Support the "any" wildcard for v1/health/state/ [GH-152]

## 0.2.1 (May 20, 2014)

Expand Down
10 changes: 9 additions & 1 deletion consul/state_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,15 @@ func (s *StateStore) ServiceChecks(service string) (uint64, structs.HealthChecks

// CheckInState is used to get all the checks for a service in a given state
func (s *StateStore) ChecksInState(state string) (uint64, structs.HealthChecks) {
return s.parseHealthChecks(s.checkTable.Get("status", state))
var idx uint64
var res []interface{}
var err error
if state == structs.HealthAny {
idx, res, err = s.checkTable.Get("id")
} else {
idx, res, err = s.checkTable.Get("status", state)
}
return s.parseHealthChecks(idx, res, err)
}

// parseHealthChecks is used to handle the resutls of a Get against
Expand Down
14 changes: 14 additions & 0 deletions consul/state_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -889,6 +889,20 @@ func TestEnsureCheck(t *testing.T) {
if !reflect.DeepEqual(checks[0], check2) {
t.Fatalf("bad: %v", checks[0])
}

idx, checks = store.ChecksInState(structs.HealthAny)
if idx != 4 {
t.Fatalf("bad: %v", idx)
}
if len(checks) != 2 {
t.Fatalf("bad: %v", checks)
}
if !reflect.DeepEqual(checks[0], check) {
t.Fatalf("bad: %v", checks[0])
}
if !reflect.DeepEqual(checks[1], check2) {
t.Fatalf("bad: %v", checks[1])
}
}

func TestDeleteNodeCheck(t *testing.T) {
Expand Down
3 changes: 3 additions & 0 deletions consul/structs/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ const (
)

const (
// HealthAny is special, and is used as a wild card,
// not as a specific state.
HealthAny = "any"
HealthUnknown = "unknown"
HealthPassing = "passing"
HealthWarning = "warning"
Expand Down
3 changes: 2 additions & 1 deletion website/source/docs/agent/http.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,8 @@ state for a given datacenter. By default the datacenter of the agent is queried,
however the dc can be provided using the "?dc=" query parameter.

The state being queried must be provided after the slash. The supported states
are "unknown", "passing", "warning", or "critical".
are "any", "unknown", "passing", "warning", or "critical". The "any" state is
a wildcard that can be used to return all the checks.

It returns a JSON body like this:

Expand Down

0 comments on commit e55a6fb

Please sign in to comment.