Skip to content

fix(ansible): name the daemon's log stream decdn-node - #64

Merged
thiras merged 2 commits into
mainfrom
fix/alloy-daemon-log-service-name
Sep 19, 2026
Merged

thiras merged 2 commits into
mainfrom
fix/alloy-daemon-log-service-name

Conversation

@thiras

@thiras thiras commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • loki.relabel "journal_identity" adds a replace rule: if unit matches decdn-node\.service, it sets service_name to grafana_alloy_service_name. Other units don't match, so they keep their current labels. job stays on the value the identity rules set (by default integrations/node_exporter), so the Linux Server log dashboards still match. The rule isn't rendered when grafana_alloy_service_name is empty.

  • The README now lists the three places Alloy sets service_name:

    • the node's /metrics series;
    • everything received on the local OTLP endpoint, as service.name, overwriting the sender's value;
    • the daemon's journald stream.

    It also covers two caveats:

    • systemd's own start/stop/crash messages about the daemon are logged under unit="init.scope", so {service_name="decdn-node"} won't show a crash loop;
    • Grafana Cloud's Loki may fill in a service_name for streams that don't have one.
  • Rewrote the "EVERY series/span/log line" wording in defaults, README and preflight. It contradicted the new rule and was already slightly wrong.

Tests

  • validate.sh now checks, on defaults.alloy, the rule's source_labels, regex, target_label and replacement. These checks depend on column alignment, and a comment says why.
  • The minimal fixture in render.yml now sets grafana_alloy_service_name: "". On that render, validate.sh checks that the metric rule, the journald rule and the OTTL service.name statement are all gone, and that the journald identity relabeller is still there.

Test plan

  • make lint-alloy passes: the real pinned Alloy v1.19.2 accepts all 9 renders, and every check passes.
  • Removing the template rule makes the defaults checks fail. Removing the Jinja guard makes the blank-service_name check fail.
  • make lint (pre-commit) and make lint-ansible (production profile) pass.

🤖 Generated with Claude Code

The journald pipeline shipped every unit with job=integrations/node_exporter
and the fleet labels, but no service_name, so the daemon's logs could not be
queried or correlated by service the way its metrics and spans are.

loki.relabel "journal_identity" now stamps service_name (from
grafana_alloy_service_name) on the decdn-node.service stream only. Host units
keep their labels unchanged, and job stays on the integration value so the
Linux Server log dashboards still match. The rule is skipped when
grafana_alloy_service_name is empty.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Copilot AI lite review requested due to automatic review settings September 19, 2026 16:28

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Add coverage for logs-enabled renders with an empty service name.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 Medium severity

Open (1)
What changed in this PR

Updates Grafana Alloy journald relabeling so only decdn-node.service receives service_name, with documentation and validation updates.

Changes:

  • Adds daemon-specific Loki relabeling.
  • Updates README and defaults documentation.
  • Extends rendered-config validation.
File Summary
ansible/​tests/​alloy-config/​validate.sh Validates the new relabel rule.
ansible/​roles/​grafana_alloy/​templates/​config.alloy.j2 Applies labeling only to daemon logs.
ansible/​roles/​grafana_alloy/​README.md Documents resulting log labels.
ansible/​roles/​grafana_alloy/​defaults/​main.yml Clarifies label behavior.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread ansible/roles/grafana_alloy/templates/config.alloy.j2
Review follow-ups for the daemon log-stream service_name rule:

- Docs claimed service_name lands "only" on node metrics, spans and the
  daemon's journald stream, and that "" drops it everywhere. The OTLP
  transform also stamps service.name on logs/metrics pushed to the local
  endpoint, and "" there only stops the overwrite. README now lists the three
  places Alloy sets it, notes that systemd's crash-loop lines for the daemon
  arrive as unit="init.scope", and that Loki may derive a service_name for
  label-less streams.
- Replace the "EVERY series/span/log line" wording (defaults, README,
  preflight) that the change made self-contradictory.
- render.yml's minimal fixture now blanks grafana_alloy_service_name, and
  validate.sh asserts the metric rule, journald rule and OTTL statement all
  vanish while the journald relabeller survives. The defaults render also
  pins the rule's source label and replacement value.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@thiras
thiras merged commit 8df4216 into main Sep 19, 2026
11 checks passed
@thiras
thiras deleted the fix/alloy-daemon-log-service-name branch September 19, 2026 16:39
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.

2 participants