Description
Using ${data.nomad.task.name} in a Nomad autodiscover config template (following the documentation examples) results in an invalid template reference error. The variable can currently only be accessed via ${data.meta.nomad.task.name}, which is inconsistent with the current documentation.
There is some previous discussion in #26498 (comment) related to some ongoing documentation updates, but it wasn't just a simple documentation change so I opened this separate issue.
Details
According to the following documentation for the Nomad autodiscover feature, the nomad.task.* fields should be available on the emitted autodiscover event for config templating:
|
These are the available fields during config templating. The `nomad.*` fields will be available |
|
on each emitted event. |
|
|
|
* nomad.allocation.id |
|
* nomad.allocation.name |
|
* nomad.allocation.status |
|
* nomad.datacenter |
|
* nomad.job.name |
|
* nomad.job.type |
|
* nomad.namespace |
|
* nomad.region |
|
* nomad.task.name |
|
* nomad.task.service.canary_tags |
|
* nomad.task.service.name |
|
* nomad.task.service.tags |
|
Configuration templates can contain variables from the autodiscover event. They can be accessed under |
|
`data` namespace. |
This is consistent with various examples throughout the documentation which include ${data.nomad.task.name} in path templates.
Most of these fields are present on the event as expected, however it appears that the task fields are not on the nomad field directly but only on a nomad.meta field, which contains a copy of the nomad metadata with task merged into it. Here is the relevant code:
|
event := bus.Event{ |
|
"provider": p.uuid, |
|
"id": fmt.Sprintf("%s-%s", obj.ID, task["name"]), |
|
flag: true, |
|
"host": nodeName, |
|
"nomad": allocMeta, |
|
"meta": common.MapStr{ |
|
"nomad": common.MapStrUnion(allocMeta, common.MapStr{ |
|
"task": task, |
|
}), |
|
}, |
|
} |
|
|
|
p.publish(event) |
Discussion
It appears that the duplicated nomad.meta field was introduced as part of code review feedback (see #14954 (comment)). Based on that discussion, my understanding is that the nomad field allows for simpler template references (${data.nomad.*} instead of ${data.meta.nomad.*}), while the duplicated meta.nomad field is used to support enriching events by processors. If so, merging the task metadata into the nomad field in addition to meta.nomad sounds like a fix that would resolve this issue without needing to update the existing documentation.
Description
Using
${data.nomad.task.name}in a Nomad autodiscover config template (following the documentation examples) results in an invalid template reference error. The variable can currently only be accessed via${data.meta.nomad.task.name}, which is inconsistent with the current documentation.There is some previous discussion in #26498 (comment) related to some ongoing documentation updates, but it wasn't just a simple documentation change so I opened this separate issue.
Details
According to the following documentation for the Nomad autodiscover feature, the
nomad.task.*fields should be available on the emitted autodiscover event for config templating:beats/libbeat/docs/shared-autodiscover.asciidoc
Lines 408 to 422 in 5960d7f
beats/libbeat/docs/shared-autodiscover.asciidoc
Lines 473 to 474 in 5960d7f
This is consistent with various examples throughout the documentation which include
${data.nomad.task.name}in path templates.Most of these fields are present on the event as expected, however it appears that the
taskfields are not on thenomadfield directly but only on anomad.metafield, which contains a copy of thenomadmetadata withtaskmerged into it. Here is the relevant code:beats/x-pack/libbeat/autodiscover/providers/nomad/nomad.go
Lines 197 to 210 in 076e0a6
Discussion
It appears that the duplicated
nomad.metafield was introduced as part of code review feedback (see #14954 (comment)). Based on that discussion, my understanding is that thenomadfield allows for simpler template references (${data.nomad.*}instead of${data.meta.nomad.*}), while the duplicatedmeta.nomadfield is used to support enriching events by processors. If so, merging thetaskmetadata into thenomadfield in addition tometa.nomadsounds like a fix that would resolve this issue without needing to update the existing documentation.