diff --git a/CHANGELOG.md b/CHANGELOG.md index cf48d2788..eb5847e94 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/consul/state_store.go b/consul/state_store.go index 1b137f33a..a2f139af1 100644 --- a/consul/state_store.go +++ b/consul/state_store.go @@ -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 diff --git a/consul/state_store_test.go b/consul/state_store_test.go index 308335826..a5130131a 100644 --- a/consul/state_store_test.go +++ b/consul/state_store_test.go @@ -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) { diff --git a/consul/structs/structs.go b/consul/structs/structs.go index b08a1c8e4..6eda48d59 100644 --- a/consul/structs/structs.go +++ b/consul/structs/structs.go @@ -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" diff --git a/website/source/docs/agent/http.html.markdown b/website/source/docs/agent/http.html.markdown index f7255e3de..4c8dfd92a 100644 --- a/website/source/docs/agent/http.html.markdown +++ b/website/source/docs/agent/http.html.markdown @@ -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: