# Docker based Autodiscovery with DataDog - How can we make it work?

**URL:** <https://discuss.hashicorp.com/t/docker-based-autodiscovery-with-datadog-how-can-we-make-it-work/18870>\
**Category:** Nomad\
**Created:** [December 14, 2020, 5:06pm UTC](https://discuss.hashicorp.com/t/docker-based-autodiscovery-with-datadog-how-can-we-make-it-work/18870 "2020-12-14T17:06:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![trvl3r](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/trvl3r/32/8499_2.png) [@trvl3r](https://discuss.hashicorp.com/u/trvl3r)\
**Post date:** [December 14, 2020, 5:06pm UTC](https://discuss.hashicorp.com/t/docker-based-autodiscovery-with-datadog-how-can-we-make-it-work/18870/1 "2020-12-14T17:06:59Z")

</div>

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.

```auto
LABEL "com.datadoghq.ad.check_names"='[<INTEGRATION_NAME>]'
LABEL "com.datadoghq.ad.init_configs"='[<INIT_CONFIG>]'
LABEL "com.datadoghq.ad.instances"='[<INSTANCE_CONFIG>]'

```

> **[Docker Integrations Autodiscovery](https://docs.datadoghq.com/agent/docker/integrations/?tab=docker#configuration)**
>
> Datadog, the leading service for cloud-scale monitoring.

Is there a good way that anyone can think of to get a more complex docker label added to containers via the job spec?

> **[Drivers: Docker | Nomad by HashiCorp](https://www.nomadproject.io/docs/drivers/docker#labels)**
>
> The Docker task driver is used to run Docker based tasks.

---

<div class="post-metadata">

**Author:** ![trvl3r](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/trvl3r/32/8499_2.png) [@trvl3r](https://discuss.hashicorp.com/u/trvl3r)\
**Post date:** [December 14, 2020, 9:14pm UTC](https://discuss.hashicorp.com/t/docker-based-autodiscovery-with-datadog-how-can-we-make-it-work/18870/2 "2020-12-14T21:14:36Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![schmichael](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/schmichael/32/722_2.png) [@schmichael](https://discuss.hashicorp.com/u/schmichael)\
**Post date:** [September 27, 2024, 12:06am UTC](https://discuss.hashicorp.com/t/docker-based-autodiscovery-with-datadog-how-can-we-make-it-work/18870/3 "2024-09-27T00:06:58Z")

</div>

Sorry I’m 4.5 years late offering an easier solution! You can use a list of maps in HCL2 for labels:

```hcl
        labels = [
          {
            "com.datadoghq.ad.check_names" = "[\"openmetrics\"]"
            "com.datadoghq.ad.init_configs" = "[{}]"
          }
        ]

```

> <https://github.com/hashicorp/nomad/pull/24074>
>
> 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
