Question: Why did you create this library?
Mario-Hofstaetter opened this issue · 4 comments
Hi!
May I ask what the motivation was to create this?
What are you using the parser for?
Hey!
Of course. So the motivation was to kind of three fold:
- To learn more about languages and parsers and specifically, parser combinators (it's been a long time since my university course on building compilers)
- To use it to inspect, validate and transform PromQL expressions for a project I'm doing at work
- To give something useful back to the .NET open source community.
And let's face it:
4. I've had a lot of time on my hands with the repeated lockdowns..
Thanks for the quick response! Maybe add a short "Why" section in the README.md 🙂
Regarding point 2.)
Can you disclose anything about that project, what the use case is for PromQL?
Is this app directly querying the prometheus API?
So far I am using prometheus / grafana at work, and could potentially use a parser / linter for:
- Grafana dashboards
- Prometheus (alert) rules
But since those queries are "hand made" and then checked into git (therefore human tested) I'm not sure an invalid query is something I need to worry about. Also grafana dashboard queries have all sorts of template variables in them which are tricky to handle.
Just for reference (to maybe other users browsing in here), there is also:
- https://github.com/cloudflare/pint , a "Prometheus rule linter" which even can connect to a live prometheus server and do existence / sanity checks for rule querys
- https://prometheus.io/docs/prometheus/latest/configuration/recording_rules/#syntax-checking-rules , using promtool
- Probably more I'm not aware of
Can you disclose anything about that project, what the use case is for PromQL?
Sure- it's a tool to manage SLO calculations and implement multi-burn rate alarms. Part of this requires taking simple PromQL expressions and transforming them into more complex expressions. There's a few self-imposed restrictions I require of PromQL expressions I can accept (e.g. must use rate
, must not use subquery expressions) as well.
This library helps me do this:
- It can parse out a PromQL expression into it's individual components
- I can run my custom validation logic on the resulting AST
- I can then transform these simple expressions by creating new instances of AST records.
This does not replace tools like promtool
and I explicitly call out the lack of semantic validation in the README. At work, I still run my generated expressions through promtool
to make sure they are correct before applying them to any production prometheus server.