Skip to content

NodeUtils: export upcall variables to the environment - #705

Open
thiell wants to merge 1 commit into
clustershell:masterfrom
thiell:fix/upcall-env
Open

NodeUtils: export upcall variables to the environment#705
thiell wants to merge 1 commit into
clustershell:masterfrom
thiell:fix/upcall-env

Conversation

@thiell

@thiell thiell commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator

Upcall commands already inherit the caller's full environment. This change simply sets the four substitution variables ($GROUP, $NODE, $SOURCE, $CFGDIR) in that environment, so shell parameter expansions that are not replaced by the library, like ${GROUP:-default}, expand to the same values instead of silently reading whatever the caller exported. $GROUP and $NODE are set empty when they do not apply to the upcall. Textual substitution is unchanged and still happens first, so existing configs behave identically.

This makes it easy for a map upcall to support a default when the group name is empty, e.g. for query-backed sources:

[prometheus]
map: promtool query -o json instant http://localhost:9090 "up{job=~\"${GROUP:-.*}\"}" | jq -r '.[].metric.instance' | cut -d: -f1

Here each Prometheus scrape job is a node group, resolving to the hostnames of its targets: @prometheus:node_exporter expands to the nodes scraped by the node_exporter job, and @prometheus: (empty group name) expands to the nodes of all jobs (useful for map-only sources, where @prometheus:* cannot work).

See #609 for a related earlier discussion (FYI).

Docs updated: groups.conf(5) + sphinx config.

Closes #704

@thiell thiell added this to the 1.11 milestone Aug 5, 2026
@thiell
thiell requested a review from degremont August 5, 2026 02:16
@thiell thiell self-assigned this Aug 5, 2026
Group source upcalls only support textual substitution of $GROUP,
$NODE, $SOURCE and $CFGDIR. Also export them as environment variables
so shell parameter expansions like ${GROUP:-default} work as users
expect, instead of silently reading the caller's environment.

Signed-off-by: Stephane Thiell <stephane@thiell.com>
@thiell

thiell commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator Author

The docs now state it explicitly: exported variables take precedence over any same-named variables from the calling environment.

Flagging for the 1.11 release notes as a minor behavior change: upcall commands no longer inherit caller-exported GROUP, NODE, SOURCE or CFGDIR values.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

groups.conf upcalls: ${GROUP:-default} expands from the caller's environment, not the group name

1 participant