promtool单元测试没有显示预期的结果



我在这个警报测试中需要帮助。这是我的警报规则

- alert: MemoryUsage90Percent
expr: sum(container_memory_usage_bytes{job="cadvisor",container_label_io_rancher_stack_name!="", image=~"rancher.*"}) by (container_label_io_rancher_stack_name, instance, dns_name) /1024/1024/1024 *100 > 90
for: 5m
labels:
severity: Critical
alert_owner: alerts-infra
annotations:
description: "Service memory has been at over 90% for 1 minute. Service: {{ $labels.container_label_io_rancher_stack_name }}, DnsName: {{ $labels.dns_name }}. n"

我正试图为此编写一个测试,测试:

# Infra Alert Tests
- input_series:
- series: 'container_memory_usage_bytes{job="cadvisor",container_label_io_rancher_stack_name="network-service",image="rancher.test"}'
values: '0 100000000 0 100000000 100000000'
alert_rule_test:
- alertname: MemoryUsage90Percent
# eval_time: 5m
exp_alerts:
- exp_labels:
alertname: MemoryUsage90Percent
severity: Critical
alert_owner: alerts-infra
exp_annotations:
description: "Service memory has been at over 90% for 1 minute. Service: (), DnsName: ()."

但我总是得到,

Unit Testing:  tests/infra_db_alerts-tests.yml
FAILED:
alertname: ServiceMemoryUsage90Percent, time: 0s,
exp:[
0:
Labels:{alert_owner="alerts-infra", alertname="ServiceMemoryUsage90Percent", severity="Critical"}
Annotations:{description="Service memory has been at over 90% for 1 minute. Service: (), DnsName: ()."}
],
got:[]

我在警报规则测试中尝试了许多选项。但一切都无济于事。有什么需要帮助的吗?不知道为什么我得到了空。并且总是触发警报,即使我保持输入序列值为0。

我终于找到了答案。这是因为标签和注解没有像预期的那样匹配,没有得到结果。一旦我把它修好,一切都正常了。

相关内容

  • 没有找到相关文章

最新更新