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

GetCurrentContainerID() Fails on latest AWS ECS Agent 1.16.0 #263

Closed
sidewaysgravity opened this issue Nov 30, 2017 · 2 comments
Closed

Comments

@sidewaysgravity
Copy link
Contributor

sidewaysgravity commented Nov 30, 2017

The recent update to aws ecs agent 1.16.0 changed the default prefix for the control groups inside a docker container so that the regex inside GetCurrentContainerID() (https://github.com/jwilder/docker-gen/blob/master/context.go#L161) no longer works. I submitted an issue and PR to aws here aws/amazon-ecs-agent#1119 but they have given reasons for why they won't accept it.

They also linked out to some other issues for docker introspection which is still an open issue for a standard way to get this information. The latest ecs agent also has some ability to get container meta data.

All of this leads me with knowing the problem but not a great idea for a solution.

We could easily just add a secondary check to the regex to work for both standard docker or ecs but I'm not a big fan of making a platform specific change.

var dockerRegex = "/docker[/-]([[:alnum:]]{64})(\\.scope)?$"
var ecsRegex = "/ecs/[^/]{1,}/([[:alnum:]]{64})(\\.scope)?$"
var dockerRe = regexp.MustCompilePOSIX(dockerRegex)
var ecsRe = regexp.MustCompilePOSIX(ecsRegex)

if dockerRe.MatchString(line) {
   var submatches = dockerRe.FindStringSubmatch(line)
   var containerID = submatches[1]
   fmt.Printf("Docker %s", containerID)
} else if ecsRe.MatchString(line) {
   var submatches = ecsRe.FindStringSubmatch(line)
   var containerID = submatches[1]
   fmt.Printf("ECS %s", containerID)
} else {
   fmt.Print("We didn't get anything")
}

I wanted to reach out and at least get some other people thinking about the issue and see if there are any other ideas.

@sidewaysgravity sidewaysgravity changed the title GetCurrentContainerID() Fails on latest AWS ECS GetCurrentContainerID() Fails on latest AWS ECS 1.16.0 Nov 30, 2017
@sidewaysgravity sidewaysgravity changed the title GetCurrentContainerID() Fails on latest AWS ECS 1.16.0 GetCurrentContainerID() Fails on latest AWS ECS Agent 1.16.0 Nov 30, 2017
@jwilder
Copy link
Collaborator

jwilder commented Dec 18, 2017

If adding a second regex for ecs would resolve this, I'm fine with that solution for now. The current implementation of GetCurrentContainerID has always been brittle because there hasn't been a standard way to determine your container ID from within a container.

@jbrodley
Copy link

Just spun up a new container and ran into this issue. Is there a known workaround or know when we'll have a fix?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants