trvl3r
December 14, 2020, 5:06pm
1
Using the docker based autodiscovery with datadog does not work with nomad because nomad cannot add the required labels to docker containers.
For example,
The Datadog Agent can autodiscover metrics by scanning the docker daemon for containers with certain labels. However, those labels are not allowed in HCL job spec due to the ā.ā in the key.
LABEL "com.datadoghq.ad.check_names"='[<INTEGRATION_NAME>]'
LABEL "com.datadoghq.ad.init_configs"='[<INIT_CONFIG>]'
LABEL "com.datadoghq.ad.instances"='[<INSTANCE_CONFIG>]'
Is there a good way that anyone can think of to get a more complex docker label added to containers via the job spec?
trvl3r
December 14, 2020, 9:14pm
2
I think the issue here was that using HCL for docker labels is restrictive for complex label keys
Workaround for the HCL issue was to use JSON over HTTP instead the nomad client w/ HCL
Sorry Iām 4.5 years late offering an easier solution! You can use a list of maps in HCL2 for labels:
labels = [
{
"com.datadoghq.ad.check_names" = "[\"openmetrics\"]"
"com.datadoghq.ad.init_configs" = "[{}]"
}
]
hashicorp:main ā hashicorp:docs-labels
opened 12:04AM - 27 Sep 24 UTC
Nomad v1.9.0 (finally!) removes support for HCL1 and the `-hcl1` flag. See #2391⦠2 for details.
One of the uses of HCL1 over HCL2 was that HCL1 allowed quoted keys in blocks such as env, meta, and Docker's labels:
```hcl
some_block {
"foo.bar" = "baz"
}
```
This works in HCL1 but is invalid HCL2. In HCL2 you must use a map instead of a block:
```hcl
some_map = {
"eggs.spam" = "works!"
}
```
This was such a hassle for users we special cased the `env` and `meta` blocks to be accepted as blocks or maps in #9936.
However Docker `labels`, being a task config option, is much harder to special case and commonly needs dots-in-keys for things like DataDog autodiscovery via Docker container labels:
https://docs.datadoghq.com/containers/docker/integrations/?tab=labels
Luckily `labels` can be specified as a list-of-maps instead:
```hcl
labels = [
{
"com.datadoghq.ad.check_names" = "[\"openmetrics\"]"
"com.datadoghq.ad.init_configs" = "[{}]"
}
]
```
So instead of adding more awkward hcl1/2 backward compat code to Nomad, I just updated the docs to hopefully help people hit by this.
The only other known workaround is dropping HCL in favor of JSON jobspecs altogether, but that forces a huge migration and maintenance burden on users:
https://discuss.hashicorp.com/t/docker-based-autodiscovery-with-datadog-how-can-we-make-it-work/18870
1 Like