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

Add ecs-agent container healthcheck localhost ip override env var #2834

Merged
merged 1 commit into from
Mar 19, 2021
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ additional details on each available environment variable.
| `ECS_ENABLE_TASK_CPU_MEM_LIMIT` | `true` | Whether to enable task-level cpu and memory limits | `true` | `false` |
| `ECS_CGROUP_PATH` | `/sys/fs/cgroup` | The root cgroup path that is expected by the ECS agent. This is the path that accessible from the agent mount. | `/sys/fs/cgroup` | Not applicable |
| `ECS_CGROUP_CPU_PERIOD` | `10ms` | CGroups CPU period for task level limits. This value should be between 8ms to 100ms | `100ms` | Not applicable |
| `ECS_AGENT_HEALTHCHECK_HOST` | `localhost` | Override for the ecs-agent container's healthcheck localhost ip address| `localhost` | `localhost` |
| `ECS_ENABLE_CPU_UNBOUNDED_WINDOWS_WORKAROUND` | `true` | When `true`, ECS will allow CPU unbounded(CPU=`0`) tasks to run along with CPU bounded tasks in Windows. | Not applicable | `false` |
| `ECS_ENABLE_MEMORY_UNBOUNDED_WINDOWS_WORKAROUND` | `true` | When `true`, ECS will ignore the memory reservation parameter (soft limit) to run along with memory bounded tasks in Windows. To run a memory unbounded task, omit the memory hard limit and set any memory reservation, it will be ignored. | Not applicable | `false` |
| `ECS_TASK_METADATA_RPS_LIMIT` | `100,150` | Comma separated integer values for steady state and burst throttle limits for task metadata endpoint | `40,60` | `40,60` |
Expand Down
17 changes: 17 additions & 0 deletions agent/app/healthcheck_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"fmt"
"net/http"
"net/http/httptest"
"os"
"testing"
"time"

Expand All @@ -39,6 +40,22 @@ func TestHealthcheck_InvalidURL2(t *testing.T) {
require.Equal(t, 1, rc)
}

func TestHealthcheck_EnvvarConfig(t *testing.T) {
testEnvVar := "TEST_AGENT_HEALTHCHECK_ENV_VAR"
defer os.Unsetenv(testEnvVar)
os.Setenv(testEnvVar, "127.0.0.1")

// testing healthcheck url setup from app/run.go
localhost := "localhost"
if localhostOverride := os.Getenv(testEnvVar); localhostOverride != "" {
localhost = localhostOverride
}
healthcheckUrl := fmt.Sprintf("http://%s:51678/v1/metadata", localhost)
expectedUrl := "http://127.0.0.1:51678/v1/metadata"

require.Equal(t, healthcheckUrl, expectedUrl)
}

func TestHealthcheck_Timeout(t *testing.T) {
sema := make(chan int)
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
Expand Down
15 changes: 14 additions & 1 deletion agent/app/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
package app

import (
"fmt"
"os"
"time"

"github.com/aws/amazon-ecs-agent/agent/app/args"
Expand All @@ -24,6 +26,10 @@ import (
log "github.com/cihub/seelog"
)

const (
fierlion marked this conversation as resolved.
Show resolved Hide resolved
ECS_AGENT_HEALTHCHECK_HOST_ENV_VAR = "ECS_AGENT_HEALTHCHECK_HOST"
)

// Run runs the ECS Agent App. It returns an exit code, which is used by
// main() to set the status code for the program
func Run(arguments []string) int {
Expand All @@ -43,7 +49,14 @@ func Run(arguments []string) int {
// timeout of 30s. This is so that we can catch any http timeout and log the
// issue within agent logs.
// see https://docs.docker.com/engine/reference/builder/#healthcheck
return runHealthcheck("http://localhost:51678/v1/metadata", time.Second*25)
// if ECS_AGENT_HEALTHCHECK_HOST env var is set, it will override
// the healthcheck's localhost ip address inside the ecs-agent container
localhost := "localhost"
if localhostOverride := os.Getenv(ECS_AGENT_HEALTHCHECK_HOST_ENV_VAR); localhostOverride != "" {
fierlion marked this conversation as resolved.
Show resolved Hide resolved
localhost = localhostOverride
}
healthcheckUrl := fmt.Sprintf("http://%s:51678/v1/metadata", localhost)
return runHealthcheck(healthcheckUrl, time.Second*25)
}

if *parsedArgs.LogLevel != "" {
Expand Down