Label replace over a range vector in Prometheus Label replace over a range vector in Prometheus kubernetes kubernetes

Label replace over a range vector in Prometheus


I was able to solve this problem by doing label_replace after doing the sum

Query

sort_desc(sum by (pod_set) (label_replace(sort_desc(sum by (namespace, pod) (avg_over_time(ALERTS{alertname=~"(KubeDeploymentReplicasMismatch|KubePodNotReady|KubePodCrashLooping|KubeJobFailed)", alertstate="firing"}[1w]))), "pod_set", "$1", "pod", "([a-z-A-Z]+)-.*" )))

Result

{pod_set="sendsms"} 62{pod_set="emailspreprocessor"}  32{pod_set="sendmail"}    21