tutorial: Writing Prometheus Alert Rules with Nickel #1386
Replies: 2 comments 1 reply
-
Hi @mipmip, very cool to see a blogpost about trying Nickel out! A couple of quick, focused feedback first:
More general feedback about idiomatic Nickel. Once again, it might depart from your original idea of showing off a very simple example, so feel free to ignore 🙂 However, please at least look at the very last section (middle ground) as I think it would improve readability of your example without changing much of the rest. In the grand scheme of things, I think I would actually write alert_rule like this:
This is a bare record, with a new field The metadata
In the end, what's the difference? The goal achieved is similar to functions. You use a combo of undefined fields, Nickel's record ability to self-reference and Nickel's merging instead of application to encode functions in a strange way. But, as mentioned before, As a second step, you can add contracts, documentation and default value to
You could even define custom contracts to check that Middle groundHowever, the former approach might be a bit harder (or is it?) to expose in one short blog post. Could maybe make for a follow-up post 🙃 ? If you want to stick to functions, you can also - as in Nix - use records and destructuring to emulate named arguments, which I think would improve readability. The
This is a function which expects its argument to be a record, and destructure it on-the-fly. To apply it, you now have to pass a record, but which has the advantage of naming things:
|
Beta Was this translation helpful? Give feedback.
-
Wow this is great feedback! I will definitely improve the blog with suggestions. I feel honored to get this private training 😀 thanks |
Beta Was this translation helpful? Give feedback.
-
I just published a new blog about Nickel: https://technative.eu/blog/writing_prometheus_alert_rules_with_nickel/
Feedback is highly appreciated.
Beta Was this translation helpful? Give feedback.
All reactions