Skip to content

fix(ansible): take decdn-node's Loki level from its JSON log field - #65

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

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

Conversation

@thiras

@thiras thiras commented Sep 19, 2026

Copy link
Copy Markdown
Contributor

Summary

Loki labelled every decdn-node log line level="info", WARN, ERROR and DEBUG included, so level-filtered queries (e.g. an error count) returned zero.

Root cause: grafana_alloy set level only from journald's priority. The daemon logs JSON to stdout, and journald gives every stdout line priority 6 (info). The real severity is the level field of the tracing-subscriber JSON body.

Fix: a new loki.process "daemon_level" step between the journal source and the identity relabel, scoped to unit="decdn-node.service":

  • Parses the JSON level and accepts only the five tracing levels (trimmed, case-folded).
  • Normalises them to journald's keywords (WARN → warning; TRACE → trace) and sets the level label.
  • Lines that aren't JSON, JSON without a usable level, and other units keep their journald level.
  • The priority drop setting is now applied to the daemon's JSON level, anchored as ^(?:…)$. journal_rules exempts the daemon from the journald-priority drop, so a setting that includes info no longer deletes daemon warnings and errors.

Behaviour changes for operators

  • grafana_alloy_logs_drop_priority_regex now defaults to 'debug|trace', so the daemon's TRACE lines are dropped (they would otherwise bypass the old debug default).
  • Daemon lines are filtered by their JSON level, not their journald priority.
  • Query level="warning", not warn.
  • Log lines already in Loki stay labelled info; the fix applies from deploy onward.

Testing

  • make lint-alloy now runs the rendered journal_rules + daemon_level in the real pinned Alloy (1.19.2), fed sample lines, and checks the exact label set. It covers the default settings and a new info|debug|trace render variant.
  • The test covers WARN, lowercase warn, ERROR, INFO, TRACE, a padded DEBUG, JSON with no level, a non-string level, a non-JSON line, and other units.
  • Mutation-checked: removing the label step, removing the daemon exemption, the old permissive template, the old debug default, a bare {% endraw %}, and an unwired stage each fail the gate.
  • make lint-ansible, molecule test -s grafana-cloud and pre-commit all pass.

🤖 Generated with Claude Code

thiras and others added 2 commits September 19, 2026 22:37
journald gives every stdout line priority 6, so the journal_rules mapping
labelled all daemon lines level="info" — WARN and ERROR included — and
level-filtered queries (error counts) returned zero. The debug guardrail
never dropped the daemon's DEBUG lines for the same reason.

Add loki.process "daemon_level", scoped to unit="decdn-node.service": parse
the tracing JSON `level`, normalise it to journald's keywords (WARN ->
warning), set the label, and apply the anchored priority-drop regex. Non-JSON
lines and other units keep their journald level.

make lint-alloy now runs the rendered stage in the real pinned Alloy and
asserts the resulting labels, and fails against the old behaviour.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
- Exempt decdn-node from the journald-priority drop in journal_rules and
  let daemon_level apply the same regex to its JSON level: every daemon
  line is journald-info, so a guardrail containing `info` dropped its
  warnings and errors before the JSON was ever read.
- Default the priority guardrail to 'debug|trace'. TRACE normalises to
  `trace`, not a journald keyword, so it bypassed the old 'debug' default.
- Accept only the five tracing levels (trimmed, case-folded); anything else
  keeps the journald level instead of becoming a label value.
- `{% endraw +%}`: trim_blocks glued the stage's closing brace onto the
  template line in the rendered config.
- Fix comments: upstream's formats are pretty/json (no "text"), the
  three places the unit name is hard-coded, and the empty-template path.

validate.sh: assert the stage is wired in both directions, run the rendered
journal_rules + daemon_level through the real Alloy for the defaults and a new
info-dropping render variant, cover TRACE/lowercase/no-level/non-string cases,
fail explicitly on readiness/entry-count timeouts and on an Alloy crash, and
dump the Alloy log before cleanup deletes it.

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

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

The rendered Alloy regex uses unsupported non-capturing group syntax and will fail validation.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 High severity

Open (1)
What changed in this PR

Updates Grafana Alloy to derive decdn-node log severity from JSON fields, with revised filtering, documentation, and validation coverage.

Changes:

  • Adds daemon JSON severity parsing and normalization.
  • Updates priority filtering defaults and operator documentation.
  • Adds render, pipeline, and Molecule validation.
File Summary
ansible/​tests/​alloy-config/​validate.sh Adds rendering and behavior validation.
ansible/​tests/​alloy-config/​render.yml Adds an info-dropping render variant.
ansible/​roles/​grafana_alloy/​templates/​config.alloy.j2 Adds daemon severity processing and filtering.
ansible/​roles/​grafana_alloy/​README.md Documents new severity behavior.
ansible/​roles/​grafana_alloy/​defaults/​main.yml Updates the default priority-drop regex.
ansible/​molecule/​grafana-cloud/​verify.yml Verifies the new processing stage.

💡 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
@thiras
thiras merged commit 3ce361d into main Sep 19, 2026
12 checks passed
@thiras
thiras deleted the fix/alloy-daemon-log-level branch September 19, 2026 20:00
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