fix: include all failing dimension values in anomaly alert description#1032
Conversation
Previously, dimension-based anomaly tests only showed a single (arbitrary) dimension value in the alert description. Now the description lists all failing dimension values with their metric and average values, truncated to 5 with an "and N more" suffix when there are many failures. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…by tests Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
👋 @joostboon |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThe SQL macro now collects anomalous rows before building ChangesDimension-aware anomaly description
Estimated code review effort: 2 (Simple) | ~10 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
integration_tests/tests/test_column_anomalies.py (1)
320-323: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd one case that exercises the
max_shown/"and N more"branch.These assertions only cover 1- and 2-dimension failures, but the new formatter has separate behavior once there are more than 5 anomalous dimensions. A >5 case would keep the truncation and suffix logic from regressing silently.
Also applies to: 343-347
🤖 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 `@integration_tests/tests/test_column_anomalies.py` around lines 320 - 323, The current assertions in the anomaly description tests only cover the small-dimension cases, so add a new test case in test_column_anomalies that drives the formatter past the max_shown threshold and verifies the “and N more” suffix. Use the existing description checks around test_result["test_results_description"] to assert the truncated output and the extra-count branch, ensuring the formatter logic in the test results description path does not regress.
🤖 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.
Inline comments:
In `@macros/edr/data_monitoring/anomaly_detection/store_anomaly_test_results.sql`:
- Around line 79-107: The summary in store_anomaly_test_results.sql is counting
and listing duplicate dimension_value entries from anomalous_rows, which can
overstate failures for a single dimension. Update the test_results_description
construction to deduplicate anomalous_rows by dimension_value before generating
dim_parts and total, keeping the latest or highest-priority row per value. Then
apply the existing max_shown cap to the unique list so the reported count and
examples reflect distinct failing dimensions.
---
Nitpick comments:
In `@integration_tests/tests/test_column_anomalies.py`:
- Around line 320-323: The current assertions in the anomaly description tests
only cover the small-dimension cases, so add a new test case in
test_column_anomalies that drives the formatter past the max_shown threshold and
verifies the “and N more” suffix. Use the existing description checks around
test_result["test_results_description"] to assert the truncated output and the
extra-count branch, ensuring the formatter logic in the test results description
path does not regress.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 64f4da88-9811-415a-88a8-6e8bd30533e4
📒 Files selected for processing (2)
integration_tests/tests/test_column_anomalies.pymacros/edr/data_monitoring/anomaly_detection/store_anomaly_test_results.sql
Anomalous rows are bucket-based so the same dimension_value can appear across multiple time buckets. Deduplicate by dimension_value (keeping the latest row per value) before building the summary so the count and listed values reflect distinct failing dimensions. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
… values The anomaly scores query has no order by, so the row kept per dimension value (and the metric/avg shown in the alert) depended on database result order. Sort by bucket_end desc and use the unique filter, which also removes the manual dedup loop and its __NULL__ sentinel. Read the dimension from the anomalous rows themselves instead of the first scored row. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Summary
column_anomalieswithdimensions) previously showed only a single arbitrary dimension value in the result messageIn column INCIDENTS_OPENED, 2 anomalous max values for dimension account_name: Joejuice (214.0, avg 21.0), Acme (15.0, avg 6.3).Test plan
test_column_anomalies_group_byto verify the description format for 1 and 2 failing dimension valuescolumn_anomaliestest withdimensions-- alert now shows all failing dimension valuesbefore and after screenshots:


Summary by CodeRabbit