Support wildcard for check lookup. Fixes #152

pull/168/head
Armon Dadgar 11 years ago
parent de309057ff
commit e55a6fb6d6

@ -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)

@ -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

@ -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) {

@ -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"

@ -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:

Loading…
Cancel
Save