Prometheus Z得分的单位测试
我一直在通过以下警报进行编写单元测试进行很多尝试:https://prometheus.io/docs/prometheus/latest/latest/configuration/unit_testing_rules/#alerts-proments-promethes/code> 我有一些简单的案例,但是现在我正在解决不那么微不足道的规则。例如:
abs(
avg_over_time(my_metrics{service_name="aService"}[1m])
-
avg_over_time(my_metrics{service_name="aService"}[3m])
)
/ stddev_over_time(my_metrics{service_name="aService"}[3m])
> 3
我有一个带有上述规则的文件,然后在我的测试中进行:
- interval: 1m
# Series data.
input_series:
- series: 'my_metrics{service_name="aService"}'
values: '0 0 0 0 1 0 0 0 0 '
alert_rule_test:
- eval_time: 3m
alertname: myalert
exp_alerts:
- exp_labels:
severity: warning
service_name: aService
exp_annotations:
summary: "some text"
description: "some other text"
我不确定我的seriper
应该是什么样的,以便测试与均值的偏差。甚至可以测试这样的规则吗?
谢谢
编辑 如果我将其设置为> 0
与> 3
相反,我试图设置一系列此类:
'10+10x2 30+1000x1000'
但是我无法理解将其触发的正确设置
I have been experimenting a lot with writing unit tests for alerts as per this: https://prometheus.io/docs/prometheus/latest/configuration/unit_testing_rules/#alerts-yml
I have some simple cases out, but now I am tackling rules that are less trivial. For example this:
abs(
avg_over_time(my_metrics{service_name="aService"}[1m])
-
avg_over_time(my_metrics{service_name="aService"}[3m])
)
/ stddev_over_time(my_metrics{service_name="aService"}[3m])
> 3
I have one file with the above rule and then this is in my test:
- interval: 1m
# Series data.
input_series:
- series: 'my_metrics{service_name="aService"}'
values: '0 0 0 0 1 0 0 0 0 '
alert_rule_test:
- eval_time: 3m
alertname: myalert
exp_alerts:
- exp_labels:
severity: warning
service_name: aService
exp_annotations:
summary: "some text"
description: "some other text"
I am not sure what my series
should look like in order to test deviation from the mean. Is it even possible to test such rule?
Thank you
EDIT
I can have a succesful test if I set it > 0
as opposed to >3
I have tried to set a series of this sort:
'10+10x2 30+1000x1000'
but I cannot understand what would be the correct setup to have it triggered
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这不是直接的答案,而是一个花了很多时间在这些测试上的人的提示。您是否知道,除了测试警报表达式外,您还可以Untist Promql表达式吗?看看它如何有用:
我将您的警报表达式分为三个独立的简单零件。如果运行此UNITSEST,则会在错误消息中看到注释的值。从这里开始,不难将零件加在一起,看看为什么没有发生警报。您可以使用它来构建一个工作序列。
This isn't a direct answer, rather a tip from someone who spent quite some time on these tests. Did you know that apart from testing alert expressions, you can unittest PromQL expressions as well? See how it can be useful:
I've split your alert expression into three separate, simple parts. If you run this unittest, you will see the commented-out values in the error message. From here it is not difficult to join pieces together and see why the alert is not happening. You can use that to build a working sequence of values.