|
12 | 12 | HolmesChatParams, |
13 | 13 | HolmesConversationParams, |
14 | 14 | HolmesIssueChatParams, |
15 | | - HolmesWorkloadHealthChatParams, |
16 | | - HolmesWorkloadHealthParams, |
17 | 15 | ResourceInfo, |
18 | 16 | ) |
19 | 17 | from robusta.core.model.events import ExecutionBaseEvent |
|
35 | 33 | HolmesRequest, |
36 | 34 | HolmesResult, |
37 | 35 | HolmesResultsBlock, |
38 | | - HolmesWorkloadHealthRequest, |
39 | 36 | ) |
40 | 37 | from robusta.core.reporting.utils import convert_svg_to_png |
41 | 38 | from robusta.core.stream.utils import ( |
|
44 | 41 | parse_sse_data, |
45 | 42 | StreamEvents, |
46 | 43 | ) |
47 | | -from robusta.core.schedule.model import FixedDelayRepeat |
48 | | -from robusta.integrations.kubernetes.autogenerated.events import ( |
49 | | - KubernetesAnyChangeEvent, |
50 | | -) |
51 | 44 | from robusta.integrations.prometheus.utils import HolmesDiscovery |
52 | 45 | from robusta.utils.error_codes import ActionException, ErrorCodes |
53 | 46 |
|
@@ -173,71 +166,6 @@ def ask_holmes(event: ExecutionBaseEvent, params: AIInvestigateParams): |
173 | 166 | handle_holmes_error(e) |
174 | 167 |
|
175 | 168 |
|
176 | | -@action |
177 | | -def holmes_workload_health( |
178 | | - event: ExecutionBaseEvent, params: HolmesWorkloadHealthParams |
179 | | -): |
180 | | - holmes_url = HolmesDiscovery.find_holmes_url(params.holmes_url) |
181 | | - if not holmes_url: |
182 | | - raise ActionException( |
183 | | - ErrorCodes.HOLMES_DISCOVERY_FAILED, |
184 | | - "Robusta couldn't connect to the Holmes client.", |
185 | | - ) |
186 | | - |
187 | | - params.resource.cluster = event.get_context().cluster_name |
188 | | - |
189 | | - try: |
190 | | - result = requests.post( |
191 | | - f"{holmes_url}/api/workload_health_check", data=params.json() |
192 | | - ) |
193 | | - result.raise_for_status() |
194 | | - |
195 | | - holmes_result = HolmesResult(**json.loads(result.text)) |
196 | | - |
197 | | - healthy = True |
198 | | - try: |
199 | | - analysis = json.loads(holmes_result.analysis) |
200 | | - healthy = analysis.get("workload_healthy") |
201 | | - except Exception: |
202 | | - logging.exception( |
203 | | - "Error in holmes response format, analysis did not return the expected json format." |
204 | | - ) |
205 | | - pass |
206 | | - |
207 | | - if params.silent_healthy and healthy: |
208 | | - return |
209 | | - |
210 | | - finding = Finding( |
211 | | - title=f"AI Health check of {params.resource}", |
212 | | - aggregation_key="HolmesHealthCheck", |
213 | | - subject=FindingSubject( |
214 | | - name=params.resource.name if params.resource else "", |
215 | | - namespace=params.resource.namespace if params.resource else "", |
216 | | - subject_type=( |
217 | | - FindingSubjectType.from_kind(params.resource.kind) |
218 | | - if params.resource |
219 | | - else FindingSubjectType.TYPE_NONE |
220 | | - ), |
221 | | - node=params.resource.node if params.resource else "", |
222 | | - container=params.resource.container if params.resource else "", |
223 | | - ), |
224 | | - finding_type=FindingType.AI_ANALYSIS, |
225 | | - failure=False, |
226 | | - ) |
227 | | - finding.add_enrichment( |
228 | | - [HolmesResultsBlock(holmes_result=holmes_result)], |
229 | | - enrichment_type=EnrichmentType.ai_analysis, |
230 | | - ) |
231 | | - |
232 | | - event.add_finding(finding) |
233 | | - except Exception as e: |
234 | | - logging.exception( |
235 | | - f"Failed to get holmes analysis for {params.resource}, {params.ask}", |
236 | | - exc_info=True, |
237 | | - ) |
238 | | - handle_holmes_error(e) |
239 | | - |
240 | | - |
241 | 169 | def build_conversation_title(params: HolmesConversationParams) -> str: |
242 | 170 | return ( |
243 | 171 | f"{params.resource}, {params.ask} for issue '{params.context.robusta_issue_id}'" |
@@ -315,42 +243,6 @@ def holmes_conversation(event: ExecutionBaseEvent, params: HolmesConversationPar |
315 | 243 | handle_holmes_error(e) |
316 | 244 |
|
317 | 245 |
|
318 | | -class DelayedHealthCheckParams(HolmesWorkloadHealthParams): |
319 | | - delay_seconds: int = 120 |
320 | | - |
321 | | - |
322 | | -@action |
323 | | -def delayed_health_check( |
324 | | - event: KubernetesAnyChangeEvent, action_params: DelayedHealthCheckParams |
325 | | -): |
326 | | - """ |
327 | | - runs a holmes workload health action with a delay |
328 | | - """ |
329 | | - metadata = event.obj and event.obj.metadata |
330 | | - |
331 | | - if not action_params.ask: |
332 | | - action_params.ask = f"help me diagnose an issue with a workload {metadata.namespace}/{event.obj.kind}/{metadata.name} running in my Kubernetes cluster. Can you assist with identifying potential issues and pinpoint the root cause." |
333 | | - |
334 | | - action_params.resource = ResourceInfo( |
335 | | - name=metadata.name, namespace=metadata.namespace, kind=event.obj.kind |
336 | | - ) |
337 | | - |
338 | | - logging.info( |
339 | | - f"Scheduling health check. {metadata.name} delays: {action_params.delay_seconds}" |
340 | | - ) |
341 | | - event.get_scheduler().schedule_action( |
342 | | - action_func=holmes_workload_health, |
343 | | - task_id=f"health_check_{metadata.name}_{metadata.namespace}", |
344 | | - scheduling_params=FixedDelayRepeat( |
345 | | - repeat=1, seconds_delay=action_params.delay_seconds |
346 | | - ), |
347 | | - named_sinks=event.named_sinks, |
348 | | - action_params=action_params, |
349 | | - replace_existing=True, |
350 | | - standalone_task=True, |
351 | | - ) |
352 | | - |
353 | | - |
354 | 246 | @action |
355 | 247 | def holmes_issue_chat(event: ExecutionBaseEvent, params: HolmesIssueChatParams): |
356 | 248 | holmes_url = HolmesDiscovery.find_holmes_url(params.holmes_url) |
@@ -493,64 +385,6 @@ def holmes_chat(event: ExecutionBaseEvent, params: HolmesChatParams): |
493 | 385 | handle_holmes_error(e) |
494 | 386 |
|
495 | 387 |
|
496 | | -@action |
497 | | -def holmes_workload_chat( |
498 | | - event: ExecutionBaseEvent, params: HolmesWorkloadHealthChatParams |
499 | | -): |
500 | | - holmes_url = HolmesDiscovery.find_holmes_url(params.holmes_url) |
501 | | - if not holmes_url: |
502 | | - raise ActionException( |
503 | | - ErrorCodes.HOLMES_DISCOVERY_FAILED, |
504 | | - "Robusta couldn't connect to the Holmes client.", |
505 | | - ) |
506 | | - |
507 | | - try: |
508 | | - holmes_req = HolmesWorkloadHealthRequest( |
509 | | - ask=params.ask, |
510 | | - conversation_history=params.conversation_history, |
511 | | - workload_health_result=params.workload_health_result, |
512 | | - resource=params.resource, |
513 | | - model=params.model, |
514 | | - ) |
515 | | - result = requests.post( |
516 | | - f"{holmes_url}/api/workload_health_chat", data=holmes_req.json() |
517 | | - ) |
518 | | - result.raise_for_status() |
519 | | - |
520 | | - holmes_result = HolmesChatResult(**json.loads(result.text)) |
521 | | - |
522 | | - finding = Finding( |
523 | | - title=f"AI Chat for Health Check of {params.resource}", |
524 | | - aggregation_key="HolmesWorkloadConversationResult", |
525 | | - subject=FindingSubject( |
526 | | - name=params.resource.name if params.resource else "", |
527 | | - namespace=params.resource.namespace if params.resource else "", |
528 | | - subject_type=( |
529 | | - FindingSubjectType.from_kind(params.resource.kind) |
530 | | - if params.resource |
531 | | - else FindingSubjectType.TYPE_NONE |
532 | | - ), |
533 | | - node=params.resource.node if params.resource else "", |
534 | | - container=params.resource.container if params.resource else "", |
535 | | - ), |
536 | | - finding_type=FindingType.AI_ANALYSIS, |
537 | | - failure=False, |
538 | | - ) |
539 | | - finding.add_enrichment( |
540 | | - [HolmesChatResultsBlock(holmes_result=holmes_result)], |
541 | | - enrichment_type=EnrichmentType.ai_analysis, |
542 | | - ) |
543 | | - |
544 | | - event.add_finding(finding) |
545 | | - |
546 | | - except Exception as e: |
547 | | - logging.exception( |
548 | | - f"Failed to get holmes chat for health check of {params.resource}", |
549 | | - exc_info=True, |
550 | | - ) |
551 | | - handle_holmes_error(e) |
552 | | - |
553 | | - |
554 | 388 | def stream_and_render_graphs(url, holmes_req, event): |
555 | 389 | with requests.post( |
556 | 390 | url, |
|
0 commit comments