Merge pull request #401 from hashicorp/f-healthcheck

Default services to "critical" state instead of "unknown"
This commit is contained in:
Armon Dadgar 2014-10-15 16:50:38 -07:00
commit 4f1fa3a4ce
8 changed files with 27 additions and 10 deletions

View File

@ -445,7 +445,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,

View File

@ -191,7 +191,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",
@ -222,7 +222,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",
@ -260,7 +260,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",
@ -296,7 +296,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,

View File

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

View File

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

View File

@ -23,6 +23,7 @@ func TestSessionCreate(t *testing.T) {
Node: srv.agent.config.NodeName,
Name: "consul",
ServiceID: "consul",
Status: structs.HealthPassing,
},
}
var out struct{}

View File

@ -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 != "" {

View File

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

View File

@ -767,7 +767,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