Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

engine: docker healthcheck logLength index fix #1239

Merged
merged 2 commits into from
Feb 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
15 changes: 12 additions & 3 deletions agent/engine/docker_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand All @@ -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
Expand Down
11 changes: 11 additions & 0 deletions agent/engine/docker_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}