Closed rgildein closed 1 year ago
I want to ask if we can add unit tests for alert rules to the repo and integrate it with CI? it will be useful for future improvement and maintenance.
I want to ask if we can add unit tests for alert rules to the repo and integrate it with CI? it will be useful for future improvement and maintenance.
What kind of unit tests did you have in mind? We have some in the Prometheus/Loki repos (and pretty much all of the unit tests are also integrated with CI), but without knowing the general outline of what your idea was, it's hard to say conclusively whether it's already done, possible to implement, or a non-starter.
What kind of unit tests did you have in mind? We have some in the Prometheus/Loki repos (and pretty much all of the unit tests are also integrated with CI), but without knowing the general outline of what your idea was, it's hard to say conclusively whether it's already done, possible to implement, or a non-starter.
I used promtool to run unit tests for alert rules, which I provided in the description. I was following official documentation for unit testing rules.
I used promtool to run unit tests for alert rules, which I provided in the description. I was following official documentation for unit testing rules.
Without seeing what the promtool "unit tests" do, it's really hard to say what this does.
cos-tool
can validate whether rules are valid or not (which appears to be what this is doing), and this is done in other repos. But when we speak about unit tests in the context of charms, we usually mean something with much more specificity. We do also validate rules as parts of some of these, if that's all your looking for, but they're also (additionally) validated at runtime with appropriate messages sent back in relation data if they aren't.
I used promtool to run unit tests for alert rules, which I provided in the description. I was following official documentation for unit testing rules.
Without seeing what the promtool "unit tests" do, it's really hard to say what this does.
cos-tool
can validate whether rules are valid or not (which appears to be what this is doing), and this is done in other repos. But when we speak about unit tests in the context of charms, we usually mean something with much more specificity. We do also validate rules as parts of some of these, if that's all your looking for, but they're also (additionally) validated at runtime with appropriate messages sent back in relation data if they aren't.
The "unit testing" w/ promtool is not only for validating format of rules, but more for validating when those alerts are actually firing. By defining the test metrics and then checking expected outputs of queries or expecting fire from alert. For me these is useful since I'm new in PromQL and also it's hard to create environment with high network usage / errors / etc.
In the unit tests you mention we are only checking (if I'm right) rules existence and how those rules files are proceed, but not actual alerting. That's why I think it would be nice to somehow integrate these "unit" (I do not like the name) tests, which can be tested w/ promtool
(is part of Prometheus snap).
I used promtool to run unit tests for alert rules, which I provided in the description. I was following official documentation for unit testing rules.
Without seeing what the promtool "unit tests" do, it's really hard to say what this does.
cos-tool
can validate whether rules are valid or not (which appears to be what this is doing), and this is done in other repos. But when we speak about unit tests in the context of charms, we usually mean something with much more specificity. We do also validate rules as parts of some of these, if that's all your looking for, but they're also (additionally) validated at runtime with appropriate messages sent back in relation data if they aren't.The "unit testing" w/ promtool is not only for validating format of rules, but more for validating when those alerts are actually firing. By defining the test metrics and then checking expected outputs of queries or expecting fire from alert. For me these is useful since I'm new in PromQL and also it's hard to create environment with high network usage / errors / etc.
In the unit tests you mention we are only checking (if I'm right) rules existence and how those rules files are proceed, but not actual alerting. That's why I think it would be nice to somehow integrate these "unit" (I do not like the name) tests, which can be tested w/
promtool
(is part of Prometheus snap).
I'd suggest that this is more functional/integration testing than unit testing (as much as it kind of straddles the middle ground).
But as above, the "right" way to do this in the charming ecosystem is actually by adding an integration test which would deploy prometheus-k8s and grafana-agent (as a subordinate to some machine charm) as actual charms, relate them, and ensure that the rules loaded successfully and/or that the metrics which they would alert on are present. Triggering the alert itself after that would take tweaking, but isn't strictly necessary.
From a charming POV, promtool isn't particularly relevant or useful. We'd be interested in seeing whether the annotated alerts/metrics (with juju topology inserted by cos-tool) for some appropriate client are present/firing.
I do nominally see a use in what you're proposing, but more from a "pure" Prometheus POV than a charmed one.
I'd suggest that this is more functional/integration testing than unit testing (as much as it kind of straddles the middle ground).
But as above, the "right" way to do this in the charming ecosystem is actually by adding an integration test which would deploy prometheus-k8s and grafana-agent (as a subordinate to some machine charm) as actual charms, relate them, and ensure that the rules loaded successfully and/or that the metrics which they would alert on are present. Triggering the alert itself after that would take tweaking, but isn't strictly necessary.
From a charming POV, promtool isn't particularly relevant or useful. We'd be interested in seeing whether the annotated alerts/metrics (with juju topology inserted by cos-tool) for some appropriate client are present/firing.
I do nominally see a use in what you're proposing, but more from a "pure" Prometheus POV than a charmed one.
I completely agreed on this, these are not really unit tests and I was thinking that we could have one functional tests actually running promtool on one grafana-agent unit, but this will be more confusing to see in functional tests
My second suggestion is to provide simple md file how these tests worked and how they can be used along with actual yaml file containing those tests. Something like this:
tests
├── alert-rules
│ ├── README.md
│ └── tests.yaml
├── integration
...
What do you say?
Context
Moving memory NRPE checks from charm-nrpe.
Testing Instructions
Tested with
and promtool
Release Notes