Skip to content

Commit 75244e2

Browse files
committed
Show container health check status in ps command
1 parent f7495b8 commit 75244e2

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

ecs-cli/modules/cli/compose/container/container.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,11 @@ const (
2828
containerStateKey = "State"
2929
containerPortsKey = "Ports"
3030
taskDefinitionKey = "TaskDefinition"
31+
healthKey = "Health"
3132
)
3233

33-
var ContainerInfoColumns = []string{containerNameKey, containerStateKey, containerPortsKey, taskDefinitionKey}
34+
// ContainerInfoColumns is the ordered list of info columns for the ps commands
35+
var ContainerInfoColumns = []string{containerNameKey, containerStateKey, containerPortsKey, taskDefinitionKey, healthKey}
3436

3537
// Container is a wrapper around ecsContainer
3638
type Container struct {
@@ -59,8 +61,8 @@ func (c *Container) Id() string {
5961
// ECS doesn't have a describe container API so providing the task's UUID in the name enables users
6062
// to easily look up this container in the ecs world by invoking DescribeTask
6163
func (c *Container) Name() string {
62-
taskId := utils.GetIdFromArn(aws.StringValue(c.task.TaskArn))
63-
return utils.GetFormattedContainerName(taskId, aws.StringValue(c.ecsContainer.Name))
64+
taskID := utils.GetIdFromArn(aws.StringValue(c.task.TaskArn))
65+
return utils.GetFormattedContainerName(taskID, aws.StringValue(c.ecsContainer.Name))
6466
}
6567

6668
// TaskDefinition returns the ECS task definition id which encompasses the container definition, with
@@ -112,6 +114,11 @@ func (c *Container) PortString() string {
112114
return strings.Join(result, ", ")
113115
}
114116

117+
// HealthStatus returns the container healthcheck status for the given container
118+
func (c *Container) HealthStatus() string {
119+
return aws.StringValue(c.ecsContainer.HealthStatus)
120+
}
121+
115122
// ConvertContainersToInfoSet transforms the list of containers into a formatted set of fields
116123
func ConvertContainersToInfoSet(containers []Container) project.InfoSet {
117124
result := project.InfoSet{}
@@ -122,6 +129,7 @@ func ConvertContainersToInfoSet(containers []Container) project.InfoSet {
122129
containerStateKey: cont.State(),
123130
containerPortsKey: cont.PortString(),
124131
taskDefinitionKey: cont.TaskDefinition(),
132+
healthKey: cont.HealthStatus(),
125133
}
126134
result = append(result, info)
127135
}

ecs-cli/modules/cli/compose/container/container_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020

2121
"github.com/aws/aws-sdk-go/aws"
2222
"github.com/aws/aws-sdk-go/service/ecs"
23+
"github.com/stretchr/testify/assert"
2324
)
2425

2526
const (
@@ -126,6 +127,15 @@ func TestPortString(t *testing.T) {
126127
}
127128
}
128129

130+
func TestHealthStatus(t *testing.T) {
131+
containerHealth := ecs.HealthStatusHealthy
132+
container := setupContainer()
133+
container.ecsContainer.SetHealthStatus(containerHealth)
134+
135+
// container.HealthStatus() should simply report the value returned by the ECS API
136+
assert.Equal(t, containerHealth, container.HealthStatus())
137+
}
138+
129139
func setupContainer() Container {
130140
ecsContainer := &ecs.Container{
131141
ContainerArn: aws.String(contArn),

0 commit comments

Comments
 (0)