hashicorp / nomad

Nomad is an easy-to-use, flexible, and performant workload orchestrator that can deploy a mix of microservice, batch, containerized, and non-containerized applications. Nomad is easy to operate and scale and has native Consul and Vault integrations.
https://www.nomadproject.io/
Other
14.88k stars 1.95k forks source link

[question] Query Container ID #4848

Open sevagh opened 5 years ago

sevagh commented 5 years ago

I'm looking for a way to associate running containers to an alloc id. This is for general debugging, or for example to use tools like https://github.com/google/cadvisor

I experimented with the label solution, where I add this to my HCL:

config {
  labels = "${NOMAD_ALLOC_ID}"
}

Also, the container name seems to contain the alloc id in it, e.g. ${task-name}-${nomad_alloc_id} in the output of docker ps.

I'm sure the ContainerID is kept track of in the code - is there a way to print this information from nomad alloc-status? Or nomad node status?

Is that useful? e.g. nomad alloc-status ${alloc-id} to print the actual container ID (if it's using the Docker driver).

preetapan commented 5 years ago

@sevagh thanks for the suggestion. This isn't something we are actively working on, but will consider adding it to a future roadmap with a more generic way to surface allocation metadata.

The upcoming 0.9 release will add support for passing allocid/taskid etc to docker as docker labels. #4781 tracks this.

sevagh commented 5 years ago

Thanks @preetapan - so that means instead of manually specifying labels = "${NOMAD_*_ID}" in all of my HCL files, Nomad will do it automatically in the new release?

Smithx10 commented 5 years ago

I've opened up this, https://github.com/hashicorp/nomad/issues/5863 trying to do the same for my users.

While exploring the code, I'm curious if DriverAttributes in the TaskStatus struct could be used for this? Or what they are used for.... I can't figure it out, or What NetworkOverride does. It is returned Nomad calls "func (d Driver) InspectTask(taskID string) (drivers.TaskStatus, error)" but I cant figure out when Nomad calls that function either. Hopefully someone can help educate me :) :)

type TaskStatus struct { ID string Name string State TaskState StartedAt time.Time CompletedAt time.Time ExitResult ExitResult DriverAttributes map[string]string NetworkOverride DriverNetwork }

Smithx10 commented 3 years ago

Anyone curious about this... we currently are getting around this by using the event.Eventer and then leaving it up to the consumer of /allocations to pull the latest information if they want. Not sure if Docker does this or not but it wouldn't break anything to add this.