If I run those tests, I get an error saying describing exactly what the 
problem is:

root@prometheus:~# /opt/prometheus/promtool test rules 
replicas_mismatch_test.yaml
Unit Testing:  replicas_mismatch_test.yaml
  FAILED:
    alertname: KubernetesDeploymentReplicasMismatch-authproxy, time: 20m,
        *exp*:[
            0:
              
Labels:{alertname="KubernetesDeploymentReplicasMismatch-authproxy", 
job="prometheus", namespace="auth-proxy", severity="critical"}
*              Annotations:{description="YaRD_Kubernetes Deployment 
Replicas Mismatch in authproxy namespace from 11 min getting alert", 
summary="Kube_replicaset_spec_replicas_authproxy missmatches"}*
            ],
        *got*:[
            0:
              
Labels:{alertname="KubernetesDeploymentReplicasMismatch-authproxy", 
job="prometheus", namespace="auth-proxy", severity="critical"}
*              Annotations:{description="Deployment Replicas mismatch\n 
 VALUE = 5\n  LABELS = map[__name__:kube_replicaset_spec_replicas 
job:prometheus namespace:auth-proxy]", summary="Kubernetes Deployment 
replicas mismatch (instance )"}*
            ]

That's very clear.  Notice how "exp" (expected) is different to "got" (what 
the alerting rule actually produced).  You can either fix the "exp" to 
match the annotations generated by the alerting rule:

                         exp_annotations:
                               summary: "Kubernetes Deployment replicas 
mismatch (instance )"
                               description: "Deployment Replicas mismatch\n 
 VALUE = 5\n  LABELS = map[__name__:kube_replicaset_spec_replicas 
job:prometheus namespace:auth-proxy]"

(Notice that the instance in the summary is blank, because you didn't set 
an instance label in your test data).

Or you can change the alerting rules themselves to give the annotations 
that you expect in your test.  That's the whole point of testing - to see 
that what you generate is what you expect.

Aside: I see no point in putting LABELS in an annotation.  They are already 
part of the alert.  It only duplicates information, and makes the alert 
harder to understand and harder to test.

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/prometheus-users/71b561b8-6961-4c26-b093-e0452f8ab056n%40googlegroups.com.

Reply via email to