Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
adnxn committed Jan 19, 2018
1 parent 9c1504c commit 200ad66
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 5 deletions.
5 changes: 4 additions & 1 deletion agent/app/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ func newAgent(
metadataManager = containermetadata.NewManager(dockerClient, cfg)
}

resource := resources.New()
resource.ApplyConfigDependencies(cfg)

return &ecsAgent{
ctx: ctx,
ec2MetadataClient: ec2MetadataClient,
Expand All @@ -163,7 +166,7 @@ func newAgent(
}),
os: oswrapper.New(),
metadataManager: metadataManager,
resource: resources.New(),
resource: resource,
terminationHandler: sighandlers.StartDefaultTerminationHandler,
}, nil
}
Expand Down
3 changes: 3 additions & 0 deletions agent/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,8 @@ func environmentConfig() (Config, error) {

dockerStopTimeout := getDockerStopTimeout()

cgroupMemorySubsystemPath := os.Getenv("ECS_CGROUP_MEMORY_SUBSYSTEM_PATH")

taskCleanupWaitDuration := parseEnvVariableDuration("ECS_ENGINE_TASK_CLEANUP_WAIT_DURATION")

availableLoggingDriversEnv := os.Getenv("ECS_AVAILABLE_LOGGING_DRIVERS")
Expand Down Expand Up @@ -388,6 +390,7 @@ func environmentConfig() (Config, error) {
ContainerMetadataEnabled: containerMetadataEnabled,
DataDirOnHost: dataDirOnHost,
OverrideAWSLogsExecutionRole: overrideAWSLogsExecutionRoleEnabled,
CgroupMemorySubsystemPath: cgroupMemorySubsystemPath,
}, err
}

Expand Down
3 changes: 3 additions & 0 deletions agent/config/config_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ const (
defaultCredentialsAuditLogFile = "/log/audit.log"
// Default cgroup prefix for ECS tasks
DefaultTaskCgroupPrefix = "/ecs"

defaultCgroupMemorySubsystemPath = "/sys/fs/cgroup/memory/"
)

// DefaultConfig returns the default configuration for Linux
Expand Down Expand Up @@ -55,6 +57,7 @@ func DefaultConfig() Config {
AWSVPCBlockInstanceMetdata: false,
ContainerMetadataEnabled: false,
TaskCPUMemLimit: DefaultEnabled,
CgroupMemorySubsystemPath: defaultCgroupMemorySubsystemPath,
}
}

Expand Down
2 changes: 2 additions & 0 deletions agent/config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,4 +194,6 @@ type Config struct {
// OverrideAWSLogsExecutionRole is config option used to enable awslogs
// driver authentication over the task's execution role
OverrideAWSLogsExecutionRole bool

CgroupMemorySubsystemPath string
}
4 changes: 3 additions & 1 deletion agent/engine/task_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,14 @@ type managedTask struct {
// This method must only be called when the engine.processTasks write lock is
// already held.
func (engine *DockerTaskEngine) newManagedTask(task *api.Task) *managedTask {
resource := resources.New()
resource.ApplyConfigDependencies(engine.cfg)
t := &managedTask{
Task: task,
acsMessages: make(chan acsTransition),
dockerMessages: make(chan dockerContainerChange),
engine: engine,
resource: resources.New(),
resource: resource,
}
engine.managedTasks[task.Arn] = t
return t
Expand Down
3 changes: 3 additions & 0 deletions agent/resources/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ package resources

import (
"github.com/aws/amazon-ecs-agent/agent/api"
"github.com/aws/amazon-ecs-agent/agent/config"
)

// Resource interface to interact with platform level resource constructs
Expand All @@ -26,4 +27,6 @@ type Resource interface {
Setup(task *api.Task) error
// Cleanup removes the resource
Cleanup(task *api.Task) error

ApplyConfigDependencies(cfg *config.Config)
}
12 changes: 9 additions & 3 deletions agent/resources/resources_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ import (
)

const (
memorySubsystem = "/sys/fs/cgroup/memory/"
memoryUseHierarchy = "memory.use_hierarchy"
)

// cgroupWrapper implements the Resource interface
type cgroupWrapper struct {
control cgroup.Control
ioutil ioutilwrapper.IOUtil
control cgroup.Control
ioutil ioutilwrapper.IOUtil
memorySubsystemPath string
}

// New is used to return an object that implements the Resource interface
Expand Down Expand Up @@ -67,6 +67,10 @@ func (c *cgroupWrapper) Cleanup(task *api.Task) error {
return c.cleanupCgroup(task)
}

func (c *cgroupWrapper) ApplyConfigDependencies(cfg *config.Config) {
c.memorySubsystemPath = cfg.CgroupMemorySubsystemPath
}

// cgroupInit is used to create the root '/ecs/ cgroup
func (c *cgroupWrapper) cgroupInit() error {
if c.control.Exists(config.DefaultTaskCgroupPrefix) {
Expand Down Expand Up @@ -106,6 +110,8 @@ func (c *cgroupWrapper) setupCgroup(task *api.Task) error {
}

// echo 1 > memory.use_hierarchy
memorySubsystem := c.memorySubsystemPath

err = c.ioutil.WriteFile(filepath.Join(memorySubsystem, cgroupRoot, memoryUseHierarchy), []byte(strconv.Itoa(1)), os.FileMode(0))
if err != nil {
return errors.Wrapf(err, "resource: setup cgroup: unable to set use hierarchy flag for task: %s", task.Arn)
Expand Down

0 comments on commit 200ad66

Please sign in to comment.