From 095fe915a8e20ffb8a16384c5b755d9092e74f62 Mon Sep 17 00:00:00 2001 From: "avi@robusta.dev" Date: Thu, 23 Jan 2025 15:05:49 +0200 Subject: [PATCH] discovery workload improved --- src/robusta/core/discovery/top_service_resolver.py | 10 +++++++++- src/robusta/core/reporting/base.py | 1 + src/robusta/core/sinks/slack/slack_sink.py | 12 +++--------- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/robusta/core/discovery/top_service_resolver.py b/src/robusta/core/discovery/top_service_resolver.py index f073958f4..68b062788 100644 --- a/src/robusta/core/discovery/top_service_resolver.py +++ b/src/robusta/core/discovery/top_service_resolver.py @@ -1,7 +1,7 @@ import threading import time from collections import defaultdict -from typing import Dict, List, Optional +from typing import Any, Dict, List, Optional from pydantic.main import BaseModel @@ -67,6 +67,14 @@ def guess_cached_resource(cls, name: str, namespace: str) -> Optional[TopLevelRe return cached_resource return None + @classmethod + def guess_workload_from_labels(cls, labels: Dict[Any, Any] = None) -> Optional[TopLevelResource]: + relevant_label_keys = ["job_name", "deployment", "statefulset", "daemonset", "pod"] + for label in relevant_label_keys: + if label in labels: + return labels[label] + return None + @classmethod def add_cached_resource(cls, resource: TopLevelResource): cls.__namespace_to_resource[resource.namespace].append(resource) diff --git a/src/robusta/core/reporting/base.py b/src/robusta/core/reporting/base.py index bfb6d9517..cff0f8b88 100644 --- a/src/robusta/core/reporting/base.py +++ b/src/robusta/core/reporting/base.py @@ -282,6 +282,7 @@ def __init__( self.enrichments: List[Enrichment] = [] self.links: List[Link] = [] self.service = TopServiceResolver.guess_cached_resource(name=subject.name, namespace=subject.namespace) + self.backup_workload_name = TopServiceResolver.guess_workload_from_labels(labels=silence_labels) self.service_key = self.service.get_resource_key() if self.service else "" uri_path = f"services/{self.service_key}?tab=grouped" if self.service_key else "graphs" self.investigate_uri = f"{ROBUSTA_UI_DOMAIN}/{uri_path}" diff --git a/src/robusta/core/sinks/slack/slack_sink.py b/src/robusta/core/sinks/slack/slack_sink.py index 1f7aa7989..9e66024d4 100644 --- a/src/robusta/core/sinks/slack/slack_sink.py +++ b/src/robusta/core/sinks/slack/slack_sink.py @@ -42,7 +42,7 @@ def handle_notification_grouping(self, finding: Finding, platform_enabled: bool) investigate_uri = self.get_timeline_uri(self.account_id, self.cluster_name) finding_data = finding.attribute_map # The top level entity name (the owner of the pod etc) - finding_data["workload"] = finding.service.name if finding.service else None + finding_data["workload"] = finding.service.name if finding.service else finding.backup_workload_name finding_data["cluster"] = self.cluster_name resolved = finding.title.startswith("[RESOLVED]") @@ -112,19 +112,13 @@ def __replace_callback_with_string(self, slack_message, block_id, message_string blocks[i] = { "type": "section", "block_id": block_id, - "text": { - "type": "mrkdwn", - "text": message_string - } + "text": {"type": "mrkdwn", "text": message_string}, } break # Call the shorter update function return self.slack_sender.update_slack_message( - channel=channel_id, - ts=message_ts, - blocks=blocks, - text=message_string + channel=channel_id, ts=message_ts, blocks=blocks, text=message_string ) except Exception as e: