From f311ada60e24cda8de5e3c3082a99e63a34480b2 Mon Sep 17 00:00:00 2001 From: Ryan Uber Date: Wed, 15 Oct 2014 10:08:13 -0700 Subject: [PATCH 1/4] agent: Default health checks to critical. Fixes #341 --- command/agent/structs.go | 2 +- command/agent/structs_test.go | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 command/agent/structs_test.go diff --git a/command/agent/structs.go b/command/agent/structs.go index 2370c3936a..e202823710 100644 --- a/command/agent/structs.go +++ b/command/agent/structs.go @@ -46,7 +46,7 @@ func (c *CheckDefinition) HealthCheck(node string) *structs.HealthCheck { Node: node, CheckID: c.ID, Name: c.Name, - Status: structs.HealthUnknown, + Status: structs.HealthCritical, Notes: c.Notes, } if health.CheckID == "" && health.Name != "" { diff --git a/command/agent/structs_test.go b/command/agent/structs_test.go new file mode 100644 index 0000000000..f21f69fd74 --- /dev/null +++ b/command/agent/structs_test.go @@ -0,0 +1,16 @@ +package agent + +import ( + "github.com/hashicorp/consul/consul/structs" + "testing" +) + +func TestAgentStructs_HealthCheck(t *testing.T) { + def := CheckDefinition{} + check := def.HealthCheck("node1") + + // Health checks default to critical state + if check.Status != structs.HealthCritical { + t.Fatalf("bad: %v", check.Status) + } +} From 2f93e13da8c8e312f2408c27a8d684fa412064a9 Mon Sep 17 00:00:00 2001 From: Ryan Uber Date: Wed, 15 Oct 2014 10:14:46 -0700 Subject: [PATCH 2/4] consul: kill remaining use of HealthUnknown --- command/agent/agent.go | 2 +- command/agent/agent_test.go | 8 ++++---- command/agent/check.go | 4 ++-- command/agent/local_test.go | 2 +- consul/state_store.go | 2 +- consul/structs/structs.go | 1 - 6 files changed, 9 insertions(+), 10 deletions(-) diff --git a/command/agent/agent.go b/command/agent/agent.go index 418c5fef4c..b470bac346 100644 --- a/command/agent/agent.go +++ b/command/agent/agent.go @@ -437,7 +437,7 @@ func (a *Agent) AddService(service *structs.NodeService, chkType *CheckType) err Node: a.config.NodeName, CheckID: fmt.Sprintf("service:%s", service.ID), Name: fmt.Sprintf("Service '%s' check", service.Service), - Status: structs.HealthUnknown, + Status: structs.HealthCritical, Notes: "", ServiceID: service.ID, ServiceName: service.Service, diff --git a/command/agent/agent_test.go b/command/agent/agent_test.go index 3343c4afc1..11f2af7616 100644 --- a/command/agent/agent_test.go +++ b/command/agent/agent_test.go @@ -186,7 +186,7 @@ func TestAgent_AddCheck(t *testing.T) { Node: "foo", CheckID: "mem", Name: "memory util", - Status: structs.HealthUnknown, + Status: structs.HealthCritical, } chk := &CheckType{ Script: "exit 0", @@ -217,7 +217,7 @@ func TestAgent_AddCheck_MinInterval(t *testing.T) { Node: "foo", CheckID: "mem", Name: "memory util", - Status: structs.HealthUnknown, + Status: structs.HealthCritical, } chk := &CheckType{ Script: "exit 0", @@ -255,7 +255,7 @@ func TestAgent_RemoveCheck(t *testing.T) { Node: "foo", CheckID: "mem", Name: "memory util", - Status: structs.HealthUnknown, + Status: structs.HealthCritical, } chk := &CheckType{ Script: "exit 0", @@ -291,7 +291,7 @@ func TestAgent_UpdateCheck(t *testing.T) { Node: "foo", CheckID: "mem", Name: "memory util", - Status: structs.HealthUnknown, + Status: structs.HealthCritical, } chk := &CheckType{ TTL: 15 * time.Second, diff --git a/command/agent/check.go b/command/agent/check.go index cf38f30cd6..dce7d8f75c 100644 --- a/command/agent/check.go +++ b/command/agent/check.go @@ -109,7 +109,7 @@ func (c *CheckMonitor) check() { cmd, err := ExecScript(c.Script) if err != nil { c.Logger.Printf("[ERR] agent: failed to setup invoke '%s': %s", c.Script, err) - c.Notify.UpdateCheck(c.CheckID, structs.HealthUnknown, err.Error()) + c.Notify.UpdateCheck(c.CheckID, structs.HealthCritical, err.Error()) return } @@ -121,7 +121,7 @@ func (c *CheckMonitor) check() { // Start the check if err := cmd.Start(); err != nil { c.Logger.Printf("[ERR] agent: failed to invoke '%s': %s", c.Script, err) - c.Notify.UpdateCheck(c.CheckID, structs.HealthUnknown, err.Error()) + c.Notify.UpdateCheck(c.CheckID, structs.HealthCritical, err.Error()) return } diff --git a/command/agent/local_test.go b/command/agent/local_test.go index 29bf379806..0fb036a1e8 100644 --- a/command/agent/local_test.go +++ b/command/agent/local_test.go @@ -172,7 +172,7 @@ func TestAgentAntiEntropy_Checks(t *testing.T) { chk2_mod := new(structs.HealthCheck) *chk2_mod = *chk2 - chk2_mod.Status = structs.HealthUnknown + chk2_mod.Status = structs.HealthCritical args.Check = chk2_mod if err := agent.RPC("Catalog.Register", args, &out); err != nil { t.Fatalf("err: %v", err) diff --git a/consul/state_store.go b/consul/state_store.go index fcb4f04ecf..7dff338f74 100644 --- a/consul/state_store.go +++ b/consul/state_store.go @@ -762,7 +762,7 @@ func (s *StateStore) EnsureCheck(index uint64, check *structs.HealthCheck) error func (s *StateStore) ensureCheckTxn(index uint64, check *structs.HealthCheck, tx *MDBTxn) error { // Ensure we have a status if check.Status == "" { - check.Status = structs.HealthUnknown + check.Status = structs.HealthCritical } // Ensure the node exists diff --git a/consul/structs/structs.go b/consul/structs/structs.go index 5b3597bba4..531a1e4b85 100644 --- a/consul/structs/structs.go +++ b/consul/structs/structs.go @@ -29,7 +29,6 @@ const ( // HealthAny is special, and is used as a wild card, // not as a specific state. HealthAny = "any" - HealthUnknown = "unknown" HealthPassing = "passing" HealthWarning = "warning" HealthCritical = "critical" From d2fc11c19d6998618b02f07bbac442489aae9c73 Mon Sep 17 00:00:00 2001 From: Ryan Uber Date: Wed, 15 Oct 2014 11:35:22 -0700 Subject: [PATCH 3/4] consul/structs: keep HealthUnknown around for backward compatibility --- consul/structs/structs.go | 1 + 1 file changed, 1 insertion(+) diff --git a/consul/structs/structs.go b/consul/structs/structs.go index 531a1e4b85..5b3597bba4 100644 --- a/consul/structs/structs.go +++ b/consul/structs/structs.go @@ -29,6 +29,7 @@ const ( // HealthAny is special, and is used as a wild card, // not as a specific state. HealthAny = "any" + HealthUnknown = "unknown" HealthPassing = "passing" HealthWarning = "warning" HealthCritical = "critical" From 149656951d8731dca671e167a72438601cfa7b1f Mon Sep 17 00:00:00 2001 From: Ryan Uber Date: Wed, 15 Oct 2014 15:43:53 -0700 Subject: [PATCH 4/4] agent: fix tests after default status change --- command/agent/session_endpoint_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/command/agent/session_endpoint_test.go b/command/agent/session_endpoint_test.go index 9052e42385..b5a93eea3a 100644 --- a/command/agent/session_endpoint_test.go +++ b/command/agent/session_endpoint_test.go @@ -23,6 +23,7 @@ func TestSessionCreate(t *testing.T) { Node: srv.agent.config.NodeName, Name: "consul", ServiceID: "consul", + Status: structs.HealthPassing, }, } var out struct{}