Skip to content

fix(templates): accept dotted VictoriaLogs fields in templates (#25)#27

Merged
fxthiry merged 1 commit intorelease/1.1.1from
fix/gh-25-dotted-field-templates
Apr 15, 2026
Merged

fix(templates): accept dotted VictoriaLogs fields in templates (#25)#27
fxthiry merged 1 commit intorelease/1.1.1from
fix/gh-25-dotted-field-templates

Conversation

@fxthiry
Copy link
Copy Markdown
Owner

@fxthiry fxthiry commented Apr 15, 2026

Summary

Fixes #25. VictoriaLogs emits fields like nginx.http.request_id as literal flat keys, but minijinja interprets a.b.c as nested attribute access — so both valerter --validate and runtime rendering fail on user-written templates referencing these fields.

Two complementary fixes:

  • At render timeTemplateEngine now deflates the event additively before handing it to minijinja. Flat dotted keys stay accessible, and a nested structure is added on top so {{ nginx.http.request_id }} resolves. Deep-merges with existing nested values; on collision with an existing top-level scalar, the scalar wins and a warn! is emitted.

  • At validation — the validate_template_render sentinel is swapped from json!({}) to a TruthyChainable Object: returns itself on any attribute access, always truthy, iterates as an empty sequence, stringifies as empty. Keeps {% if x.y %} bodies walked so unknown-filter detection does not regress, while allowing chained undefined access and {% for %} / | length against undefined to validate cleanly.

Test plan

Review hints

Spec and suggested review order: _bmad-output/implementation-artifacts/spec-gh-25-dotted-field-templates.md (local, not in VCS).

Key entry points:

  • src/config/validation.rs:20TruthyChainable sentinel (the design decision)
  • src/parser.rs:271unflatten_dotted_keys (additive deflation)
  • src/template.rs:165 / src/template.rs:180 — application points before render_str

Targeted at release/1.1.1 rather than main so the patch release can be bundled with #26 and validated by the reporter before tagging.

VictoriaLogs emits fields like `nginx.http.request_id` as literal flat keys,
but minijinja interprets `a.b.c` as nested attribute access. Both `--validate`
and runtime rendering would therefore fail on user-written templates referencing
these fields.

Two complementary fixes:

- At render time, deflate the event additively in `TemplateEngine` before
  handing it to minijinja: flat dotted keys stay accessible, and a nested
  structure is added on top so `{{ nginx.http.request_id }}` resolves.
  Deep-merges with existing nested values; on collision with an existing
  top-level scalar, the scalar wins and a `warn!` is emitted.

- Swap the `validate_template_render` sentinel from `json!({})` to a
  `TruthyChainable` Object that returns itself on any attribute access,
  is always truthy, iterates as an empty sequence, and stringifies as empty.
  Keeps `{% if x.y %}` bodies walked so unknown-filter detection doesn't
  regress, while allowing chained undefined access and `{% for %}` / length
  against undefined to validate cleanly.
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.

1 participant