mirror of
https://github.com/moby/moby.git
synced 2026-01-11 18:51:37 +00:00
explicitly access Container.State.Health.Health
The State.Health struct has a mutex, but in various places we access the embedded Health struct directly. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
committed by
Rob Murray
parent
0df791cb72
commit
d06f0d008d
@@ -296,7 +296,7 @@ func (v *View) transform(ctr *Container) *Snapshot {
|
||||
failingStreak := 0
|
||||
if ctr.State.Health != nil {
|
||||
health = ctr.State.Health.Status()
|
||||
failingStreak = ctr.State.Health.FailingStreak
|
||||
failingStreak = ctr.State.Health.Health.FailingStreak
|
||||
}
|
||||
|
||||
snapshot := &Snapshot{
|
||||
|
||||
@@ -197,14 +197,14 @@ func handleProbeResult(d *Daemon, c *container.Container, result *containertypes
|
||||
h := c.State.Health
|
||||
oldStatus := h.Status()
|
||||
|
||||
if len(h.Log) >= maxLogEntries {
|
||||
h.Log = append(h.Log[len(h.Log)+1-maxLogEntries:], result)
|
||||
if len(h.Health.Log) >= maxLogEntries {
|
||||
h.Health.Log = append(h.Health.Log[len(h.Health.Log)+1-maxLogEntries:], result)
|
||||
} else {
|
||||
h.Log = append(h.Log, result)
|
||||
h.Health.Log = append(h.Health.Log, result)
|
||||
}
|
||||
|
||||
if result.ExitCode == exitStatusHealthy {
|
||||
h.FailingStreak = 0
|
||||
h.Health.FailingStreak = 0
|
||||
h.SetStatus(containertypes.Healthy)
|
||||
} else { // Failure (including invalid exit code)
|
||||
shouldIncrementStreak := true
|
||||
@@ -223,9 +223,9 @@ func handleProbeResult(d *Daemon, c *container.Container, result *containertypes
|
||||
}
|
||||
|
||||
if shouldIncrementStreak {
|
||||
h.FailingStreak++
|
||||
h.Health.FailingStreak++
|
||||
|
||||
if h.FailingStreak >= retries {
|
||||
if h.Health.FailingStreak >= retries {
|
||||
h.SetStatus(containertypes.Unhealthy)
|
||||
}
|
||||
}
|
||||
@@ -377,7 +377,7 @@ func (daemon *Daemon) initHealthMonitor(c *container.Container) {
|
||||
|
||||
if h := c.State.Health; h != nil {
|
||||
h.SetStatus(containertypes.Starting)
|
||||
h.FailingStreak = 0
|
||||
h.Health.FailingStreak = 0
|
||||
} else {
|
||||
h := &container.Health{}
|
||||
h.SetStatus(containertypes.Starting)
|
||||
|
||||
@@ -114,8 +114,8 @@ func TestHealthStates(t *testing.T) {
|
||||
if status := c.State.Health.Status(); status != containertypes.Starting {
|
||||
t.Errorf("Expecting starting, but got %#v\n", status)
|
||||
}
|
||||
if c.State.Health.FailingStreak != 2 {
|
||||
t.Errorf("Expecting FailingStreak=2, but got %d\n", c.State.Health.FailingStreak)
|
||||
if c.State.Health.Health.FailingStreak != 2 {
|
||||
t.Errorf("Expecting FailingStreak=2, but got %d\n", c.State.Health.Health.FailingStreak)
|
||||
}
|
||||
handleResult(c.State.StartedAt.Add(60*time.Second), 1)
|
||||
expect(eventtypes.ActionHealthStatusUnhealthy)
|
||||
@@ -123,7 +123,7 @@ func TestHealthStates(t *testing.T) {
|
||||
handleResult(c.State.StartedAt.Add(80*time.Second), 0)
|
||||
expect(eventtypes.ActionHealthStatusHealthy)
|
||||
if c.State.Health.FailingStreak != 0 {
|
||||
t.Errorf("Expecting FailingStreak=0, but got %d\n", c.State.Health.FailingStreak)
|
||||
t.Errorf("Expecting FailingStreak=0, but got %d\n", c.State.Health.Health.FailingStreak)
|
||||
}
|
||||
|
||||
// Test start period
|
||||
@@ -136,19 +136,19 @@ func TestHealthStates(t *testing.T) {
|
||||
if status := c.State.Health.Status(); status != containertypes.Starting {
|
||||
t.Errorf("Expecting starting, but got %#v\n", status)
|
||||
}
|
||||
if c.State.Health.FailingStreak != 0 {
|
||||
if c.State.Health.Health.FailingStreak != 0 {
|
||||
t.Errorf("Expecting FailingStreak=0, but got %d\n", c.State.Health.FailingStreak)
|
||||
}
|
||||
handleResult(c.State.StartedAt.Add(50*time.Second), 1)
|
||||
if status := c.State.Health.Status(); status != containertypes.Starting {
|
||||
t.Errorf("Expecting starting, but got %#v\n", status)
|
||||
}
|
||||
if c.State.Health.FailingStreak != 1 {
|
||||
t.Errorf("Expecting FailingStreak=1, but got %d\n", c.State.Health.FailingStreak)
|
||||
if c.State.Health.Health.FailingStreak != 1 {
|
||||
t.Errorf("Expecting FailingStreak=1, but got %d\n", c.State.Health.Health.FailingStreak)
|
||||
}
|
||||
handleResult(c.State.StartedAt.Add(80*time.Second), 0)
|
||||
expect(eventtypes.ActionHealthStatusHealthy)
|
||||
if c.State.Health.FailingStreak != 0 {
|
||||
t.Errorf("Expecting FailingStreak=0, but got %d\n", c.State.Health.FailingStreak)
|
||||
if c.State.Health.Health.FailingStreak != 0 {
|
||||
t.Errorf("Expecting FailingStreak=0, but got %d\n", c.State.Health.Health.FailingStreak)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,8 +113,8 @@ func (daemon *Daemon) getInspectData(daemonCfg *config.Config, ctr *container.Co
|
||||
if ctr.State.Health != nil {
|
||||
containerHealth = &containertypes.Health{
|
||||
Status: ctr.State.Health.Status(),
|
||||
FailingStreak: ctr.State.Health.FailingStreak,
|
||||
Log: append([]*containertypes.HealthcheckResult{}, ctr.State.Health.Log...),
|
||||
FailingStreak: ctr.State.Health.Health.FailingStreak,
|
||||
Log: append([]*containertypes.HealthcheckResult{}, ctr.State.Health.Health.Log...),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user