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

App diagnose chat #1699

Merged
merged 12 commits into from
Jan 30, 2025
Merged
1 change: 1 addition & 0 deletions helm/robusta/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ lightActions:
- holmes_conversation
- holmes_issue_chat
- holmes_chat
- holmes_workload_chat

# install prometheus, alert-manager, and grafana along with Robusta?
enablePrometheusStack: false
Expand Down
14 changes: 14 additions & 0 deletions src/robusta/core/model/base_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,20 @@ class HolmesWorkloadHealthParams(HolmesParams):
silent_healthy: bool = False


class HolmesWorkloadHealthChatParams(HolmesParams):
"""
:var ask: User's prompt for holmes
:var workload_health_result: Result from the workload health check
:var resource: The resource related to the initial investigation
:var conversation_history: List of previous user prompts and responses.
"""

ask: str
workload_health_result: HolmesInvestigationResult
resource: ResourceInfo
conversation_history: Optional[list[dict]] = None


class NamespacedResourcesParams(ActionParams):
"""
:var name: Resource name
Expand Down
54 changes: 54 additions & 0 deletions src/robusta/core/playbooks/internal/ai_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
HolmesIssueChatParams,
HolmesWorkloadHealthParams,
ResourceInfo,
HolmesWorkloadHealthChatParams
)
from robusta.core.model.events import ExecutionBaseEvent
from robusta.core.playbooks.actions_registry import action
Expand All @@ -26,6 +27,7 @@
HolmesRequest,
HolmesResult,
HolmesResultsBlock,
HolmesWorkloadHealthRequest,
)
from robusta.core.schedule.model import FixedDelayRepeat
from robusta.integrations.kubernetes.autogenerated.events import KubernetesAnyChangeEvent
Expand Down Expand Up @@ -354,3 +356,55 @@ def holmes_chat(event: ExecutionBaseEvent, params: HolmesChatParams):
raise ActionException(ErrorCodes.HOLMES_REQUEST_ERROR, "Holmes internal configuration error.")
else:
raise ActionException(ErrorCodes.HOLMES_UNEXPECTED_ERROR, "An unexpected error occured.")


@action
def holmes_workload_chat(event: ExecutionBaseEvent, params: HolmesWorkloadHealthChatParams):
holmes_url = HolmesDiscovery.find_holmes_url(params.holmes_url)
if not holmes_url:
raise ActionException(ErrorCodes.HOLMES_DISCOVERY_FAILED, "Robusta couldn't connect to the Holmes client.")

try:
holmes_req = HolmesWorkloadHealthRequest(
ask=params.ask,
conversation_history=params.conversation_history,
workload_health_result=params.workload_health_result,
resource=params.resource
)
result = requests.post(f"{holmes_url}/api/workload_health_chat", data=holmes_req.json())
result.raise_for_status()

holmes_result = HolmesChatResult(**json.loads(result.text))

finding = Finding(
title=f"AI Chat for Health Check of {params.resource}",
aggregation_key="HolmesWorkloadConversationResult",
subject=FindingSubject(
name=params.resource.name if params.resource else "",
namespace=params.resource.namespace if params.resource else "",
subject_type=FindingSubjectType.from_kind(params.resource.kind)
if params.resource
else FindingSubjectType.TYPE_NONE,
node=params.resource.node if params.resource else "",
container=params.resource.container if params.resource else "",
),
finding_type=FindingType.AI_ANALYSIS,
failure=False,
)
finding.add_enrichment(
[HolmesChatResultsBlock(holmes_result=holmes_result)], enrichment_type=EnrichmentType.ai_analysis
)

event.add_finding(finding)

except Exception as e:
logging.exception(f"Failed to get holmes chat for health check of {params.resource}", exc_info=True)
if isinstance(e, requests.ConnectionError):
raise ActionException(ErrorCodes.HOLMES_CONNECTION_ERROR, "Holmes endpoint is currently unreachable.")
elif isinstance(e, requests.HTTPError):
if e.response.status_code == 401 and "invalid_api_key" in e.response.text:
raise ActionException(ErrorCodes.HOLMES_REQUEST_ERROR, "Holmes invalid api key.")

raise ActionException(ErrorCodes.HOLMES_REQUEST_ERROR, "Holmes internal configuration error.")
else:
raise ActionException(ErrorCodes.HOLMES_UNEXPECTED_ERROR, "An unexpected error occured.")
5 changes: 5 additions & 0 deletions src/robusta/core/reporting/holmes.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,8 @@ class HolmesChatResult(BaseModel):

class HolmesChatResultsBlock(BaseBlock):
holmes_result: Optional[HolmesChatResult]


class HolmesWorkloadHealthRequest(HolmesChatRequest):
workload_health_result: HolmesInvestigationResult
resource: ResourceInfo
Loading