From 924ab20a9d38de491f780bf96bad045d5b91e091 Mon Sep 17 00:00:00 2001 From: Roi Glinik Date: Wed, 12 Jul 2023 10:55:12 +0300 Subject: [PATCH] avoid namespace service and kind labels on node alerts (#982) * avoid namespace service and kind labels on node alerts --- src/robusta/core/reporting/base.py | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/robusta/core/reporting/base.py b/src/robusta/core/reporting/base.py index 4ff472f1e..77ab914cd 100644 --- a/src/robusta/core/reporting/base.py +++ b/src/robusta/core/reporting/base.py @@ -272,18 +272,21 @@ def __str__(self): def get_prometheus_silence_url(self, account_id: str, cluster_name: str) -> str: labels: Dict[str, str] = {"alertname": self.aggregation_key, "cluster": cluster_name, "account": account_id} - if self.subject.namespace: - labels["namespace"] = self.subject.namespace + kind: Optional[str] = self.subject.subject_type.value + if kind == "node": + pass + else: + if self.subject.namespace: + labels["namespace"] = self.subject.namespace - if self.silence_labels and self.silence_labels.get("service"): - labels["service"] = self.silence_labels["service"] + if self.silence_labels and self.silence_labels.get("service"): + labels["service"] = self.silence_labels["service"] - # In prometheus job is related to the scrape target. - # Kubernetes jobs are stored in job_name. - kind: Optional[str] = self.subject.subject_type.value - if kind and self.subject.name: - kind = "job_name" if kind == "job" else kind - labels[kind] = self.subject.name + # In prometheus, job is related to the scrape target. + # Kubernetes jobs are stored in job_name. + if kind and self.subject.name: + kind = "job_name" if kind == "job" else kind + labels[kind] = self.subject.name labels["referer"] = "sink" # New label added here should be added to the UI silence create whitelist as well.