fix(templates): accept dotted VictoriaLogs fields in templates (#25)#27
Merged
fxthiry merged 1 commit intorelease/1.1.1from Apr 15, 2026
Merged
Conversation
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.
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #25. VictoriaLogs emits fields like
nginx.http.request_idas literal flat keys, but minijinja interpretsa.b.cas nested attribute access — so bothvalerter --validateand runtime rendering fail on user-written templates referencing these fields.Two complementary fixes:
At render time —
TemplateEnginenow 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 awarn!is emitted.At validation — the
validate_template_rendersentinel is swapped fromjson!({})to aTruthyChainableObject: 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 %}/| lengthagainst undefined to validate cleanly.Test plan
cargo test --lib— 429 passed (baseline 427 + 2 new regression tests)cargo clippy --all-targets --all-features -- -D warnings— cleanvalerter --validatereturnsConfiguration is valid(exit 0)release/1.1.1rc build)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:20—TruthyChainablesentinel (the design decision)src/parser.rs:271—unflatten_dotted_keys(additive deflation)src/template.rs:165/src/template.rs:180— application points beforerender_strTargeted at
release/1.1.1rather thanmainso the patch release can be bundled with #26 and validated by the reporter before tagging.