I’m seeing something strange when I unit test a disk space alert. The output from promtool is:
$ ./promtool test rules testalertrules.yml
Unit Testing: testalertrules.yml
FAILED:
alertname:DiskSpace20%Free, time:3m,
exp:"[Labels:{alertname=\"DiskSpace20%Free\", instance=\"rfmfxevnt-vp1:9100\", mountpoint=\"/\", severity=\"moderate\"} Annotations:{}, Labels:{alertname=\"DiskSpace20%Free\"} Annotations:{description=\"Diskspace on rfmfxevnt-vp1:9100 filesystem / has 19% available.\"}]",
got:"[Labels:{alertname=\"DiskSpace20%Free\", instance=\"rfmfxevnt-vp1:9100\", mountpoint=\"/\", severity=\"moderate\"} Annotations:{description=\"Diskspace on rfmfxevnt-vp1:9100 filesystem / has 19% available.\"}]"
Note that the expected alert has an extra 'Annotations:{}, Labels:{alertname=“DiskSpace20%Free”} ’ If I remove that they match up perfectly. Since the Annotations and Labels are already expected, how am I generating these extra requirements?
------------------------------- alertrules.yml ------------------------------------
groups:
- name: disk_space
rules:
- alert: DiskSpace20%Free
expr: 100 - round(100 * node_filesystem_avail_bytes / node_filesystem_size_bytes) < 20
labels:
severity: moderate
annotations:
description: "Diskspace on {{ $labels.instance }} filesystem {{ $labels.mountpoint }} has {{ $value }}% available."
------------------------------- testalertrules.yml ------------------------------------
rule_files:
- alertrules.yml
evaluation_interval: 1m
tests:
# Series data
- interval: 1m
input_series:
# 30% 27% 25% 19% 15% 11% 9% 5% 30%
- series: 'node_filesystem_size_bytes{instance="rfmfxevnt-vp1:9100", mountpoint="/"}'
values: '10726932480 10726932480 10726932480 10726932480'
- series: 'node_filesystem_avail_bytes{instance="rfmfxevnt-vp1:9100", mountpoint="/"}'
values: '7508852736 7830660710 8045199360 8688815308'
alert_rule_test:
- alertname: DiskSpace20%Free
eval_time: 2m
- alertname: DiskSpace20%Free
eval_time: 3m
exp_alerts:
- exp_labels:
severity: moderate
instance: rfmfxevnt-vp1:9100
mountpoint: /
- exp_annotations:
description: 'Diskspace on rfmfxevnt-vp1:9100 filesystem / has 19% available.'