Repository navigation
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (6)
🚧 Files skipped from review as they are similar to previous changes (2)
Included review availability: Your plan provides up to 8 included reviews per hour; 6 remain after this review. 📝 WalkthroughWalkthroughThe change adds removal support to per-alertname limit buckets, handles resolved alerts only when their firing alerts were admitted, migrates provider and store APIs to ChangesAlert limits and type migration
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant AlertInput
participant store.Alerts
participant limit.Bucket
participant provider.mem
AlertInput->>store.Alerts: Submit alert.Alert
store.Alerts->>limit.Bucket: Admit firing or remove resolved fingerprint
limit.Bucket-->>store.Alerts: Return limit result
store.Alerts-->>provider.mem: Return stored alert or limitError
provider.mem->>provider.mem: Record state-labeled limit metric
Merge Risk: ⚪ Minimal · up to The change limits firing alerts, forwards only matching resolutions, frees admitted slots, and labels limited-alert metrics by state. The supplied tests cover these behaviors, so no actionable merge-blocking risk remains. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Docstring CoverageExplanation Docstring coverage is 19.05% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 21 functions across 6 files. (2 skipped: 2 unsupported.)
✨ 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 |
| // If the bucket is full, oldest expired item is evicted based on priority and the new value is added. | ||
| // Otherwise the new value is ignored and the method returns false. | ||
| func (b *Bucket[V]) Upsert(value V, priority time.Time) (ok bool) { | ||
| if b.capacity < 1 { |
There was a problem hiding this comment.
Do we need this check? Would there be a point for a capacity 0 bucket? Should we fail at NewBucket instead in that case?
There was a problem hiding this comment.
The bucket limiter was added as a generic implementation, zero here means drop all, we can change it in future to allow all.
d71ba20 to
74c0127
Compare
Rework the per-alertname alert limit so resolved notifications no longer consume limit slots, and change how they are handled. - limit: add Bucket.Remove to free a tracked slot by value/fingerprint. - store: apply the per-alert limit only to firing alerts. A resolved notification is forwarded only if its firing counterpart was previously admitted (its fingerprint is still tracked); removing it frees the slot the firing alert was holding. Resolves with no admitted firing are dropped as noise, since nothing downstream ever received a firing for them from us. - provider/mem: add a `state` label (firing/resolved) to alertmanager_alerts_limited_total so dropped firing alerts and dropped resolved notifications can be distinguished. - docs: document the new resolved handling and metric label in alertmanager.md and configuration.md. - tests: add Bucket.Remove coverage (presence return, slot freeing, double remove, heap eviction-order integrity, concurrency) and store coverage for the drop-if-unseen resolved semantics. Signed-off-by: Siavash Safi <siavash@cloudflare.com>
74c0127 to
4d4ecc3
Compare
Resolve the release-note and alert-limit documentation conflicts against current main. Signed-off-by: Siavash Safi <siavash@cloudflare.com>
Carry the store limit decision in the returned error so metric labels do not depend on a later time check. Use alert terminology for incoming resolved alerts. Signed-off-by: Siavash Safi <siavash@cloudflare.com>
ultrotter
left a comment
There was a problem hiding this comment.
Please take a look at the comments. It also needs a rebase as I removed the types package in the meantime :) Let's make sure not to introduce "alert" variables that shadow the alert pacakge.
| bucket, ok := a.limits[name] | ||
| if !ok || !bucket.Remove(fp) { | ||
| return limitError{resolved: true} | ||
| } |
There was a problem hiding this comment.
Resolutions will naturally keep coming from prometheus for a while, and may not just come once for an alert... So is this logic what we want? We'll get a lot of errors by removing the alert from the store once resolved, while we keep getting "resolved" messages for a while?
It may be that we want to keep the slot occupied in case of a resolve, until the alert is indeed fully gone from the store, so that we can handle flap (which before would pass even if new alerts were limited) and also the next resolve messages.
Or alternatively we can forward if a.alerts[fp] exists, and only return the error if it doesn't, otherwise be ok with normal followup resolves
| } | ||
|
|
||
| latest := b.items[b.items.Len()-1] | ||
| return latest.expired(time.Now()) |
There was a problem hiding this comment.
Can we double check this logic? It seems the invariant is that the root is the minimum, not that the latest is necessarily the maximum:
func TestBucketIsStaleWithLiveItem(t *testing.T) {
bucket := NewBucketstring
now := time.Now()
// Backing array ends up as [expiredOld, live, expiredRecent]: each push is
// appended and only sifts up if earlier than its parent (index 0, the
// oldest), which neither "live" nor "expiredRecent" is.
require.True(t, bucket.Upsert("expiredOld", now.Add(-2*time.Hour)))
require.True(t, bucket.Upsert("live", now.Add(1*time.Hour)))
require.True(t, bucket.Upsert("expiredRecent", now.Add(-1*time.Hour)))
require.Equal(t, "expiredRecent", bucket.items[len(bucket.items)-1].value,
"precondition: last array slot must be an expired leaf")
require.False(t, bucket.IsStale(), "bucket still holds a live item and must not be stale")
}
--- FAIL: TestBucketIsStaleWithLiveItem (0.00s)
bucket_test.go:599: Should be false
Messages: bucket still holds a live item and must not be stale
If so we can't quite rely on this logic and we need to fix it.
|
|
||
| type limitError struct { | ||
| resolved bool | ||
| } |
There was a problem hiding this comment.
This interface gets then repeated a few times in mem.go and tests.
Would it make more sense to go with something like:
var (
ErrLimited = errors.New("alert limited")
// ErrLimitedResolved wraps ErrLimited for a resolved alert that had no
// admitted firing counterpart.
ErrLimitedResolved = fmt.Errorf("%w: resolved alert without admitted firing", ErrLimited)
)
Then tests could be this way:
if errors.Is(err, store.ErrLimited) {
state := "firing"
if errors.Is(err, store.ErrLimitedResolved) {
state = "resolved"
}
...
}
And we would avoid the interface re-declaration?
Rework the per-alertname alert limit so resolved notifications no longer consume limit slots, and change how they are handled.
statelabel (firing/resolved) to alertmanager_alerts_limited_total so dropped firing alerts and dropped resolved notifications can be distinguished.Pull Request Checklist
Please check all the applicable boxes.
benchstatto compare benchmarksWhich user-facing changes does this PR introduce?