fix: apply custom dedup rules to pulled alerts (closes #5370)#6242
fix: apply custom dedup rules to pulled alerts (closes #5370)#6242jyoti369 wants to merge 3 commits intokeephq:mainfrom
Conversation
|
@jyoti369 UTs fails: |
Custom deduplication rules (fingerprint_fields) were only applied to webhook alerts via format_alert() but not to pulled alerts via get_alerts(). This caused providers like Prometheus to ignore custom fingerprint fields when pulling alerts, generating fingerprints based on alertname alone instead of the configured fields. Add the same custom dedup rule application to get_alerts() so pulled alerts also respect user-configured fingerprint_fields. Closes keephq#5370
492a69e to
ab10545
Compare
|
E2E failure in 47 E2E tests passed, just this one flaked. Updating branch now to re-trigger CI. |
fixed this, please re-check. |
|
@shahargl All changes are done from my side. The E2E failure (mysql-with-redis) is flaky tests unrelated to this PR - our changes only touch |
|
@shahargl tests are fixed and CI has been re-triggered. Ready for re-review when you get a chance! |
Summary
Fixes #5370 - Prometheus (and all other) providers now respect custom deduplication rules when pulling alerts.
Root Cause
Custom dedup rules (
fingerprint_fields) were applied informat_alert()(webhook path) but not inget_alerts()(pull path). When alerts are pulled via the provider's_get_alerts()method, the fingerprint from the source system was used as-is, ignoring any user-configuredfingerprint_fields.For Prometheus specifically, the native fingerprint is based on
alertnamealone, so alerts with different labels (e.g.env_dc,group) were incorrectly matching as duplicates:Fix
Added custom dedup rule application to
BaseProvider.get_alerts(), mirroring the existing logic informat_alert(). This means ALL providers benefit from the fix when pulling alerts, not just Prometheus.Changed files:
keep/providers/base/base_provider.py- Applyget_custom_deduplication_rule+get_alert_fingerprintinget_alerts()after setting provider metadatatests/test_get_alerts_custom_dedup.py- Unit tests verifying custom dedup rules are applied to pulled alertsTesting
Added 3 unit tests:
labels.alertname,labels.env_dc,labels.groupconfig)Note
Medium Risk
Changes how alert
fingerprints are computed for all pulled alerts when a tenant has custom dedup rules, which can affect deduplication/grouping behavior across the system. Scope is small and covered by new unit tests, but behavior changes may impact existing alert correlation expectations.Overview
Pulled alerts returned by
BaseProvider.get_alerts()now respect tenant custom deduplication rules by recalculating each alert’sfingerprintusing the configuredfingerprint_fields(mirroring the existing webhookformat_alert()behavior).Adds unit tests to ensure a custom rule overwrites the source/native fingerprint, the original fingerprint is preserved when no rule exists, and dot-notation field paths (e.g.
labels.env_dc) work when building the fingerprint.Reviewed by Cursor Bugbot for commit 492a69e. Bugbot is set up for automated code reviews on this repo. Configure here.