mirror of
https://github.com/status-im/consul.git
synced 2025-01-10 22:06:20 +00:00
consul/state: set index if we have an existing health check
This commit is contained in:
parent
8c6f40f299
commit
6ebed234bb
@ -352,6 +352,21 @@ func (s *StateStore) EnsureCheck(idx uint64, hc *structs.HealthCheck) error {
|
|||||||
// a health check into the state store. It ensures safety against inserting
|
// a health check into the state store. It ensures safety against inserting
|
||||||
// checks with no matching node or service.
|
// checks with no matching node or service.
|
||||||
func (s *StateStore) ensureCheckTxn(idx uint64, hc *structs.HealthCheck, tx *memdb.Txn) error {
|
func (s *StateStore) ensureCheckTxn(idx uint64, hc *structs.HealthCheck, tx *memdb.Txn) error {
|
||||||
|
// Check if we have an existing health check
|
||||||
|
existing, err := tx.First("checks", "id", hc.Node, hc.CheckID)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed health check lookup: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set the indexes
|
||||||
|
if existing != nil {
|
||||||
|
hc.CreateIndex = existing.(*structs.HealthCheck).CreateIndex
|
||||||
|
hc.ModifyIndex = idx
|
||||||
|
} else {
|
||||||
|
hc.CreateIndex = idx
|
||||||
|
hc.ModifyIndex = idx
|
||||||
|
}
|
||||||
|
|
||||||
// Use the default check status if none was provided
|
// Use the default check status if none was provided
|
||||||
if hc.Status == "" {
|
if hc.Status == "" {
|
||||||
hc.Status = structs.HealthCritical
|
hc.Status = structs.HealthCritical
|
||||||
|
@ -332,9 +332,30 @@ func TestStateStore_EnsureCheck(t *testing.T) {
|
|||||||
t.Fatalf("err: %s", err)
|
t.Fatalf("err: %s", err)
|
||||||
}
|
}
|
||||||
if len(checks) != 1 {
|
if len(checks) != 1 {
|
||||||
t.Fatalf("bad number of checks: %d", len(checks))
|
t.Fatalf("wrong number of checks: %d", len(checks))
|
||||||
}
|
}
|
||||||
if !reflect.DeepEqual(checks[0], check) {
|
if !reflect.DeepEqual(checks[0], check) {
|
||||||
t.Fatalf("bad: %#v", checks[0])
|
t.Fatalf("bad: %#v", checks[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Modify the health check
|
||||||
|
check.Output = "bbb"
|
||||||
|
if err := s.EnsureCheck(4, check); err != nil {
|
||||||
|
t.Fatalf("err: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check that we successfully updated
|
||||||
|
checks, err = s.NodeChecks("node1")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("err: %s", err)
|
||||||
|
}
|
||||||
|
if len(checks) != 1 {
|
||||||
|
t.Fatalf("wrong number of checks: %d", len(checks))
|
||||||
|
}
|
||||||
|
if checks[0].Output != "bbb" {
|
||||||
|
t.Fatalf("wrong check output: %#v", checks[0])
|
||||||
|
}
|
||||||
|
if checks[0].CreateIndex != 3 || checks[0].ModifyIndex != 4 {
|
||||||
|
t.Fatalf("bad index: %#v", checks[0])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -283,6 +283,8 @@ type HealthCheck struct {
|
|||||||
Output string // Holds output of script runs
|
Output string // Holds output of script runs
|
||||||
ServiceID string // optional associated service
|
ServiceID string // optional associated service
|
||||||
ServiceName string // optional service name
|
ServiceName string // optional service name
|
||||||
|
|
||||||
|
RaftIndex
|
||||||
}
|
}
|
||||||
type HealthChecks []*HealthCheck
|
type HealthChecks []*HealthCheck
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user