From 4a5655dfea2c8618155e72215725ebb5be6c80cc Mon Sep 17 00:00:00 2001 From: Adnan Khan Date: Fri, 16 Feb 2018 10:14:58 -0800 Subject: [PATCH 1/2] engine: docker healthcheck nonzero log check --- agent/engine/docker_client.go | 15 ++++++++++++--- agent/engine/docker_client_test.go | 11 +++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/agent/engine/docker_client.go b/agent/engine/docker_client.go index 4d11544b103..b344d0dca24 100644 --- a/agent/engine/docker_client.go +++ b/agent/engine/docker_client.go @@ -45,6 +45,8 @@ const ( imageNameFormat = "%s:%s" // the buffer size will ensure agent doesn't miss any event from docker dockerEventBufferSize = 100 + // healthCheckStarting is the initial status returned from docker container health check + healthCheckStarting = "starting" // healthCheckHealthy is the healthy status returned from docker container health check healthCheckHealthy = "healthy" // healthCheckUnhealthy is unhealthy status returned from docker container health check @@ -768,7 +770,7 @@ func metadataFromContainer(dockerContainer *docker.Container) DockerContainerMet if dockerContainer.State.OOMKilled { metadata.Error = OutOfMemoryError{} } - if dockerContainer.State.Health.Status == "" { + if dockerContainer.State.Health.Status == "" || dockerContainer.State.Health.Status == healthCheckStarting { return metadata } @@ -785,11 +787,18 @@ func metadataFromContainer(dockerContainer *docker.Container) DockerContainerMet health.Output = output[:size] } - if dockerContainer.State.Health.Status == healthCheckHealthy { + switch dockerContainer.State.Health.Status { + case healthCheckHealthy: health.Status = api.ContainerHealthy - } else if dockerContainer.State.Health.Status == healthCheckUnhealthy { + case healthCheckUnhealthy: health.Status = api.ContainerUnhealthy + if logLength == 0 { + seelog.Warn("DockerGoClient: no container healthcheck data returned by Docker") + break + } health.ExitCode = dockerContainer.State.Health.Log[logLength-1].ExitCode + default: + seelog.Debugf("DockerGoClient: unknown healthcheck status event from docker: %s", dockerContainer.State.Health.Status) } metadata.Health = health diff --git a/agent/engine/docker_client_test.go b/agent/engine/docker_client_test.go index 91cfeb3911b..36ea07bae5d 100644 --- a/agent/engine/docker_client_test.go +++ b/agent/engine/docker_client_test.go @@ -1271,3 +1271,14 @@ func TestMetadataFromContainer(t *testing.T) { assert.Equal(t, started, metadata.StartedAt) assert.Equal(t, finished, metadata.FinishedAt) } + +func TestMetadataFromContainerHealthCheckWithNoLogs(t *testing.T) { + + dockerContainer := &docker.Container{ + State: docker.State{ + Health: docker.Health{Status: "unhealthy"}, + }} + + metadata := metadataFromContainer(dockerContainer) + assert.Equal(t, api.ContainerUnhealthy, metadata.Health.Status) +} From 109af5f8cc0ff34e4f3629b85c92d8b4f2e9e80f Mon Sep 17 00:00:00 2001 From: Adnan Khan Date: Mon, 19 Feb 2018 09:45:31 -0800 Subject: [PATCH 2/2] changelog: added loglen runtime fix --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b6dd53798b0..88ae1ab7203 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog +## 1.17.1-dev +* Bug - Fixed a bug that was causing a runtime panic by accessing negative index in the health check log slice. [#1239](https://github.com/aws/amazon-ecs-agent/pull/1239) + ## 1.17.0 * Feature - Support a HTTP endpoint for `awsvpc` tasks to query metadata * Feature - Support Docker health check