Need Help for Promtool alert testing

103 views
Skip to first unread message

Shivanand Shete

unread,
Jan 10, 2023, 2:31:37 AM1/10/23
to Prometheus Users
 Dear all,

Please find the below my prometheous alert and rules file , but I am not able test the alert using promtool.
I not able to understand where is the exact issue.
Please kindly help me.

Alert File: 
groups:
- name: pod-restart.alerts
rules:
- alert: KubernetesPodCrashLooping
expr: increase(kube_pod_container_status_restarts_total[1m]) > 3
for: 2m
labels:
severity: warning
annotations:
summary: Kubernetes pod crash looping (instance {{ $labels.instance }})
description: "Pod {{ $labels.pod }} is crash looping\n VALUE = {{ $value }}\n LABELS = {{ $labels }}"


Rule Test File content: 


evaluation_interval: 1m


tests:
- interval: 1m
input_series:
- series: kube_pod_container_status_restarts_total{pod="test_pod", instance="test_host" }
values: 5 10 15 20

alert_rule_test:
- eval_time: 2m
alertname: KubernetesPodCrashLooping
exp_alerts:
- exp_labels:
pod: test_pod
instance: test_host
severity: warning
exp_annotations:
summary: Kubernetes pod crash looping (instance test_host)
description: "Pod test_pod is crash looping\n VALUE = 4\n LABELS = {{ $labels }}"

I am Getting Below Error Output.

:/testdata# promtool test rules pod-restart_test.yaml
Unit Testing:  pod-restart_test.yaml
  WARNING: no file match pattern /testdata/pod-restar.yaml
  FAILED:
    alertname: KubernetesPodCrashLooping, time: 2m,
        exp:[
            0:
              Labels:{alertname="KubernetesPodCrashLooping", instance="test_host", pod="test_pod", severity="warning"}
              Annotations:{description="Pod test_pod is crash looping\n  VALUE = 4\n  LABELS = {{ $labels }}", summary="Kubernetes pod crash looping (instance test_host)"}
            ],
        got:[]

pod-restart.yaml
pod-restart_test.yaml

David Leadbeater

unread,
Jan 10, 2023, 2:36:10 AM1/10/23
to Shivanand Shete, Prometheus Users
Looks like:

"WARNING: no file match pattern /testdata/pod-restar.yaml" is the relevant bit.

You've got a typo in rules_file in the test file.

David
> --
> You received this message because you are subscribed to the Google Groups "Prometheus Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to prometheus-use...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/prometheus-users/1b8f054f-2657-48f5-b369-c87d560f7154n%40googlegroups.com.

Shivanand Shete

unread,
Jan 10, 2023, 2:46:19 AM1/10/23
to Prometheus Users
Yes I fixed that, After that getting below error.

Unit Testing:  pod-restart_test.yaml

  FAILED:
    alertname: KubernetesPodCrashLooping, time: 2m,
        exp:[
            0:
              Labels:{alertname="KubernetesPodCrashLooping", instance="test_host", pod="test_pod", severity="warning"}
              Annotations:{description="Pod test_pod is crash looping\n  VALUE = 4\n  LABELS = {{ $labels }}", summary="Kubernetes pod crash looping (instance test_host)"}
            ],
        got:[]

Shivanand Shete

unread,
Jan 10, 2023, 2:48:50 AM1/10/23
to Prometheus Users
Yes, I got it , and I fixed that then getting below error.

Unit Testing:  pod-restart_test.yaml

  FAILED:
    alertname: KubernetesPodCrashLooping, time: 2m,
        exp:[
            0:
              Labels:{alertname="KubernetesPodCrashLooping", instance="test_host", pod="test_pod", severity="warning"}
              Annotations:{description="Pod test_pod is crash looping\n  VALUE = 4\n  LABELS = {{ $labels }}", summary="Kubernetes pod crash looping (instance test_host)"}
            ],
        got:[]

On Tuesday, January 10, 2023 at 1:06:10 PM UTC+5:30 d...@dgl.cx wrote:
Reply all
Reply to author
Forward
0 new messages