Skip to content

Commit

Permalink
auto investigate playbook
Browse files Browse the repository at this point in the history
- actions:
  - auto_ask_holmes: {}
  triggers:
  - on_prometheus_alert:
      alert_name: PodNotReady
  - on_pod_crash_loop:
      restart_reason: "CrashLoopBackOff"
  • Loading branch information
Avi-Robusta committed Jan 19, 2025
1 parent 4b6c2d0 commit 9e96fa2
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion src/robusta/core/playbooks/internal/ai_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
)
from robusta.core.schedule.model import FixedDelayRepeat
from robusta.integrations.kubernetes.autogenerated.events import KubernetesAnyChangeEvent
from robusta.integrations.prometheus.models import PrometheusKubernetesAlert
from robusta.integrations.prometheus.utils import HolmesDiscovery
from robusta.utils.error_codes import ActionException, ErrorCodes

Expand All @@ -40,6 +41,32 @@ def build_investigation_title(params: AIInvestigateParams) -> str:
return params.context.get("issue_type", "unknown health issue")


@action
def auto_ask_holmes(event: ExecutionBaseEvent):
subject: FindingSubject = event.get_subject()
resource = ResourceInfo(
name=subject.name,
namespace=subject.namespace,
kind=str(subject.subject_type.value),
node=subject.node,
container=subject.container,
)
issue_type = event.alert_name if isinstance(event, PrometheusKubernetesAlert) else type(event).__name__
logging.warning(issue_type)
source = event.get_source()

context = {
"issue_type": issue_type,
"source": str(source.value),
"labels": subject.labels,
}

action_params = AIInvestigateParams(
resource=resource, investigation_type="issue", ask="Why is this alert firing?", context=context
)
ask_holmes(event, params=action_params)


@action
def ask_holmes(event: ExecutionBaseEvent, params: AIInvestigateParams):
holmes_url = HolmesDiscovery.find_holmes_url(params.holmes_url)
Expand Down Expand Up @@ -167,7 +194,9 @@ def build_conversation_title(params: HolmesConversationParams) -> str:


def add_labels_to_ask(params: HolmesConversationParams) -> str:
label_string = f"the alert has the following labels: {params.context.get('labels')}" if params.context.get("labels") else ""
label_string = (
f"the alert has the following labels: {params.context.get('labels')}" if params.context.get("labels") else ""
)
ask = f"{params.ask}, {label_string}" if label_string else params.ask
logging.debug(f"holmes ask query: {ask}")
return ask
Expand Down

0 comments on commit 9e96fa2

Please sign in to comment.