Skip to content

[➕ Feature]: Jinja template engine in workflow templates #4594

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
korolenkowork opened this issue Apr 19, 2025 · 8 comments · May be fixed by #4595
Open

[➕ Feature]: Jinja template engine in workflow templates #4594

korolenkowork opened this issue Apr 19, 2025 · 8 comments · May be fixed by #4595
Labels
Feature A new feature

Comments

@korolenkowork
Copy link
Contributor

Is your feature request related to a problem? Please describe
In our system, some alerts include all the labels, while others do not. When certain metrics or fields are missing, it causes exceptions during template rendering. This makes it difficult to build robust templates that can handle all alert variations gracefully. It's currently difficult due to the limitations of custom templating. Using Jinja instead would make it much easier and more flexible.

Describe the solution you'd like
Replace the current custom templating system with Jinja. This would provide greater flexibility and power when creating templates, especially when handling optional fields and conditional logic.

Describe alternatives you've considered

  • Extend the current custom templating to support conditional (if) blocks
  • Add support for default values when a metric or label is missing in the workflow
@dosubot dosubot bot added the Feature A new feature label Apr 19, 2025
@talboren
Copy link
Member

Absolutely! Closing #3129 in favor of this issue

@shahargl
Copy link
Member

👀

@korolenkowork
Copy link
Contributor Author

Can I work on this issue?

@shahargl
Copy link
Member

For sure. I would say it’s tough one but if you feel you ready you can try!

@korolenkowork korolenkowork linked a pull request Apr 19, 2025 that will close this issue
3 tasks
@korolenkowork
Copy link
Contributor Author

Ok, seems like I'm done with it. Will be glad for review ^_^

@shahargl
Copy link
Member

@EnotShow lot of tests are failing, can you have a look?

@korolenkowork
Copy link
Contributor Author

**✨ Features
Users can now choose their preferred template engine for workflows: Jinja2 or Mustache
Mustache remains the default template engine
Introduced a syntax validator that raises a RenderError if invalid syntax is used for the selected engine
If an incorrect templating engine is specified in the YAML, a ValueError is raised
**🛠 Improvements
Mustache (via Chevrone) now uses a tracking dictionary to log missing keys in the context, implemented in a thread-safe way.
**⚠️ Known Limitations
-During Jinja2 rendering, only missing top-level keys can be detected — full key paths cannot be tracked.
Example: {{ alert.namespase }} will report {{ namespace }} as missing, but due to how Jinja2's Undefined class works, it cannot identify the full path to the missing value.

-It’s not possible to use a tracking dictionary for Jinja2 in the same way as Mustache, because Jinja2 internally converts the context to a plain dict during rendering.

I need some help with workflow execution tests for jinja2 cose, I not so sure about how it work, but except it work seems like done

Need review

@korolenkowork
Copy link
Contributor Author

Done!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature A new feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants