Skip to content

Nomad autodiscover event missing task fields #26538

@wjordan

Description

@wjordan

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions