feat(operator): include check cost in Slack alerts - #2282
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughChangesLLM usage attribution
Estimated code review effort: 2 (Simple) | ~10 minutes Sequence Diagram(s)sequenceDiagram
participant CheckExecution
participant AlertAPI
participant SlackDestination
CheckExecution->>AlertAPI: produce CheckResult with LLM usage
AlertAPI->>SlackDestination: pass usage-enriched LLMResult
SlackDestination->>SlackDestination: append cost and token context
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
✅ Deploy Preview for holmes-docs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
holmes/checks/checks.py (1)
139-164: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winConsider consolidating the PASS/FAIL branches to reduce duplication.
The two
CheckResultconstructions differ only instatusandmessage; the remaining fields (including the four new usage fields) are identical. Consolidating would prevent future field divergence as more metrics are added.♻️ Optional refactor to eliminate duplication
- if check_response.passed: - result = CheckResult( - check_name=check.name, - status=CheckStatus.PASS, - message=f"Check passed. {check_response.rationale}", - query=check.query, - duration=duration, - rationale=check_response.rationale, - total_cost=response.total_cost, - total_tokens=response.total_tokens, - prompt_tokens=response.prompt_tokens, - completion_tokens=response.completion_tokens, - ) - else: - result = CheckResult( - check_name=check.name, - status=CheckStatus.FAIL, - message=f"Check failed. {check_response.rationale}", - query=check.query, - duration=duration, - rationale=check_response.rationale, - total_cost=response.total_cost, - total_tokens=response.total_tokens, - prompt_tokens=response.prompt_tokens, - completion_tokens=response.completion_tokens, - ) + status = CheckStatus.PASS if check_response.passed else CheckStatus.FAIL + verb = "passed" if check_response.passed else "failed" + result = CheckResult( + check_name=check.name, + status=status, + message=f"Check {verb}. {check_response.rationale}", + query=check.query, + duration=duration, + rationale=check_response.rationale, + total_cost=response.total_cost, + total_tokens=response.total_tokens, + prompt_tokens=response.prompt_tokens, + completion_tokens=response.completion_tokens, + )🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@holmes/checks/checks.py` around lines 139 - 164, Consolidate the duplicated CheckResult construction in the check evaluation flow by selecting status and the corresponding message from check_response.passed, then instantiate CheckResult once with the shared fields, including usage metrics. Preserve the existing PASS/FAIL statuses and message text.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@holmes/checks/checks.py`:
- Around line 139-164: Consolidate the duplicated CheckResult construction in
the check evaluation flow by selecting status and the corresponding message from
check_response.passed, then instantiate CheckResult once with the shared fields,
including usage metrics. Preserve the existing PASS/FAIL statuses and message
text.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: aa9b0c0f-c513-4aa7-aaaa-a3eec0797ab7
📒 Files selected for processing (6)
holmes/checks/checks.pyholmes/checks/checks_api.pyholmes/checks/models.pyholmes/plugins/destinations/slack/plugin.pytests/checks/test_checks_api.pytests/plugins/destinations/test_slack.py
Summary
Preserves aggregate LLM usage from operator-driven health checks and displays it in Slack failure alerts.
Investigation costand input/output token line in the existing Slack messageWhy
Operator health checks can make several LLM calls. The check usage recorder already receives aggregate stats, but the Slack alert path re-created an empty
LLMResult, discarding that data before formatting the message.Validation
ruff checkfor touched source and test filespytest tests/checks/test_checks_api.py tests/plugins/destinations/test_slack.py --no-cov(3 passed)pytest tests -m 'not llm' -q; its output was truncated by the local runner after progressing through the suite.Summary by CodeRabbit
New Features
Tests