Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MAIN-2678] Fixing missing slack sink workload #1705

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/robusta/core/discovery/top_service_resolver.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions src/robusta/core/reporting/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
12 changes: 3 additions & 9 deletions src/robusta/core/sinks/slack/slack_sink.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]")

Expand Down Expand Up @@ -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:
Expand Down
Loading