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

include parent job ID as a Docker container label #17751

Closed
EtienneBruines opened this issue Jun 27, 2023 · 7 comments · Fixed by #17843
Closed

include parent job ID as a Docker container label #17751

EtienneBruines opened this issue Jun 27, 2023 · 7 comments · Fixed by #17843
Labels
good first issue stage/accepted Confirmed, and intend to work on. No timeline committment though. theme/driver/docker type/enhancement
Milestone

Comments

@EtienneBruines
Copy link
Contributor

Proposal

Next to the container.labels.com_hashicorp_nomad_job_id field that is already being set, have a field that excludes the /periodic-901283123 suffix for batch jobs.

My feeling tells me the container.labels.com_hashicorp_nomad_job_name field would make sense for that (since right now, they have the same value) - but that would break backwards compatibility a bit.

Any field would suffice. In a lot of cases, I only care about the job name as provided in the .nomad.hcl file, and not have to bother with whatever suffixes were added.

Use-cases

Logging / filtering / grouping based on that value, while not caring about the timestamp that the batch job.

Attempted Solutions

In my Elasticsearch I now need to setup an ingest pipeline to remove this /periodic-* suffix, because I want to filter on the name of the job (without the timestamp).

@tgross tgross changed the title Docker container labels including batch job name without timestamp include parent job ID as a Docker driver label Jun 28, 2023
@tgross tgross changed the title include parent job ID as a Docker driver label include parent job ID as a Docker container label Jun 28, 2023
@tgross
Copy link
Member

tgross commented Jun 28, 2023

Hi @EtienneBruines! That seems like a good idea. I'll mark this for roadmapping but it's also small enough that I'll mark it as a good first issue to see if anyone from the community wants to give a try at adding it (they might start looking in docker/driver.go

@tgross tgross added the stage/accepted Confirmed, and intend to work on. No timeline committment though. label Jun 28, 2023
@devashishTaneja
Copy link
Contributor

@tgross I would like to contribute to this issue.

@tgross
Copy link
Member

tgross commented Jul 5, 2023

Go for it! Feel free to tag me o the PR and I'll make sure it gets reviewed.

@devashishTaneja
Copy link
Contributor

Hi @tgross, @EtienneBruines,

This is my first contribution to Nomad so I am lacking some context. I would appreciate if you could help me with a couple of doubts. So I was able to setup Nomad in my local to start a periodic docker. When I do a docker inspect on the container. I can see the following labels set up by default i.e. dockerLabelAllocID but no com_hashicorp_nomad_job_id label

Screenshot 2023-07-07 at 9 36 31 PM

But I do see a similar env set (screenshot attached below) so my question is the ask to add a new env or label itself. If labels can you suggest me how these labels are set in the first place. Below is the config file I used to start the periodic docker.

Screenshot 2023-07-07 at 9 36 41 PM
job "simple" {
  datacenters = ["dc1"]
  type = "batch"

  periodic {
    cron             = "*/1 * * * *"
    prohibit_overlap = true
  }

  group "simple" {
    task "simple" {
      driver       = "docker"
      kill_timeout = "10m"

      config {
        image   = "hashicorp/http-echo:latest"
        command = "-listen=:8080 -text='hello world'"
        args = [
          "-listen",
          ":3032",
          "-text",
          "Hello, world!",
        ]
      }

      resources {
        cpu    = 100
        memory = 100
      }
    }
  }
}

@EtienneBruines
Copy link
Contributor Author

@devashishTaneja Have you configured your Nomad Client to add those labels? e.g.:

plugin "docker" {
  config {
    # Extra labels to add to Docker containers. Available options are job_name, job_id, 
    # task_group_name, task_name, namespace, node_name, node_id. Globs are supported (e.g. task*)
    extra_labels = ["job_name", "job_id", "task_name"]
  }
}

devashishTaneja added a commit to devashishTaneja/nomad that referenced this issue Jul 7, 2023
@devashishTaneja
Copy link
Contributor

Thanks for the help @EtienneBruines !! Please review the final label.

Screenshot 2023-07-08 at 12 06 59 AM

@tgross I have raised the PR can you please review the PR.
#17843

@tgross
Copy link
Member

tgross commented Jul 10, 2023

Done in #17843 which will ship in Nomad 1.6.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue stage/accepted Confirmed, and intend to work on. No timeline committment though. theme/driver/docker type/enhancement
Projects
Development

Successfully merging a pull request may close this issue.

3 participants