-
Notifications
You must be signed in to change notification settings - Fork 2k
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 extra Docker labels ( job name, task and task group name) #9885
Conversation
@sofixa Exposing the namespace as a label would also be super useful, especially now that namespaces are available in Nomad OSS 👍 |
@henrikjohansen i thought about adding namespace and node name, but they don't seem to be available at that level ( If anyone has an idea about how to get namespace and node information at task creation, i'm all ears! |
It would be relatively easy to add the namespace/nodename here: nomad/client/allocrunner/taskrunner/task_runner.go Lines 954 to 1005 in 0078854
That said maybe @tgross could comment on whether that would be okay for the nomad team or whether another approach should be taken. |
Attached you will find a diff that also adds namespace & node_name:
Tested locally and checked the created container:
|
Is there anything preventing this from being merged? This would be super helpful. Would be happy to help if I can. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi folks! Apologies for letting this PR linger. As it turns out, we wrote and closed a similar PR #5153 a little over a year ago. Our concern there was that adding labels will increase the volume of high-cardinality metadata, and that'll make it more expensive for folks using third-party monitoring systems to use Nomad.
I brought this up again for discussion internally and we came to a consensus that if the PR included an option to tune the labels being emitted in the client's plugin configuration, we'd be more comfortable merging this. Think you'd be willing to take a shot at that?
@tgross yep, that seems logical. How do you propose the configuration should look like? A per-label flag or a global one, e.g. : extra_flags = true or extra_flags {
task_name = true
job_name = true
}
Adrian |
It probably would be better to call it 'labels' instead of 'flags'. A third option would be:
extra_labels = ['node_name','task_name'...] with a shortcut of 'all' to opt in for all (even future defined) labels.
But let's wait what the nomad team prefers before putting that into code
…On Sat, Feb 20, 2021, at 08:34, Adrian Todorov wrote:
@tgross <https://github.com/tgross> yep, that seems logical. How do you
propose the configuration should look like? A per-label flag or a
global one, e.g. :
extra_flags = true
or
extra_flags {
task_name = true
job_name = true
}
Adrian
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#9885 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAT5CYLU5CZGCCCBALLTVTS75QZVANCNFSM4WR6T56A>.
|
Apf, i meant labels, not flags, that's what happens when i write pseudocode before fully waking up :D And indeed, i think a list with an "all" keyword or a * wildcard is better than a map. |
I think plugin "docker" {
extra_labels = ["node_name", "job_name", ...]
} One minor detail for the labels is that I'd recommend we go with |
@tgross we can add both, but in most cases, names would be more useful than ids for metrics and logs - in most cases you want to see the logs for job or task name X, not for a particular instance of it. Furthermore, indexing is recommended only on non-random fields in tools like Loki or Prometheus. So, we're looking at: All labels:
With a configuration like: plugin "docker" {
extra_labels = ["node_name", "job_name", "task*"]
}
@tgross @apollo13 what do you think? I can start working on it ~tomorrow. Adrian |
+1 on having the actual job names and not ids in there. |
Ok, I'm sold on that argument. Go for it! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking pretty good! I did a quickie test with some of the globs and I see the expected labels just fine:
$ docker inspect 0a5 | jq '.[0].Config.Labels'
{
"com.hashicorp.nomad.alloc_id": "bacfab64-5e45-5b8e-79df-28d758f8a055",
"com.hashicorp.nomad.job_id": "example",
"com.hashicorp.nomad.job_name": "example",
"com.hashicorp.nomad.task_group_name": "cache",
"com.hashicorp.nomad.task_name": "redis"
}
@tgross @apollo13 any ideas how i can simulate the driver configuration in tests? That doesn't seem to be done - i can't find any instances in drivers/docker/driver_test.go, and there's only configuration parsing tests config_test.go, like so:
For doing more than configuration parsing (which I agree would be nice), there's a function dockerSetup
that takes the config you want to pass to the driver.
what is the difference between job_id & job_name? I would have expected the id to be a uuid, but they are both example? Can the two be different? |
They are normally identical because folks don't set the optional job |
Co-authored-by: Tim Gross <[email protected]>
Test is done! |
This looks great @sofixa! After taking a second look at it, we can avoid a bunch of allocations and generally make the code a bit easier to read with the change I just pushed in 29d3460 (I'd have made that as a comment but it's trivial and I want to get this merged in for you). Once CI is green from that commit, I'll squash and merge this. |
Ok, that's been merged! This PR will ship in the next release of Nomad, which is 1.1.0. |
That's great, thanks @tgross ! Any idea when 1.1.0 would come out? I'd like to have this ASAP, but i'm a bit hesitant about running the version from the master branch :D |
Sorry, I can't give you a timeline on that except that it's definitely not in the next couple weeks. But your patch should apply cleanly on top of v1.0.4 as far as I know. |
I'm going to lock this pull request because it has been closed for 120 days ⏳. This helps our maintainers find and focus on the active contributions. |
As discussed in #4781 , having those extra labels is needed for log shipping, cAdvisor, etc.