-
Notifications
You must be signed in to change notification settings - Fork 2.5k
inhibit: preserve source-only matches in equal-label index #5449
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -397,6 +397,24 @@ func (r *InhibitRule) findEqualSourceAlert(lset model.LabelSet, now time.Time) ( | |
| return nil, false | ||
| } | ||
|
|
||
| func (r *InhibitRule) findEqualSourceAlertFromCache(lset model.LabelSet, excludeTwoSidedMatch bool, now time.Time) (*types.Alert, bool) { | ||
| equalsFP := r.fingerprintEquals(lset) | ||
| for _, alert := range r.scache.List() { | ||
| if alert.ResolvedAt(now) { | ||
| continue | ||
| } | ||
| if r.fingerprintEquals(alert.Labels) != equalsFP { | ||
| continue | ||
| } | ||
| if excludeTwoSidedMatch && r.TargetMatchers.Matches(alert.Labels) { | ||
| continue | ||
| } | ||
| return alert, true | ||
| } | ||
|
|
||
| return nil, false | ||
| } | ||
|
|
||
| func (r *InhibitRule) gcCallback(alerts []*types.Alert) { | ||
| for _, a := range alerts { | ||
| fp := r.fingerprintEquals(a.Labels) | ||
|
|
@@ -412,7 +430,11 @@ func (r *InhibitRule) hasEqual(lset model.LabelSet, excludeTwoSidedMatch bool, n | |
| equal, found := r.findEqualSourceAlert(lset, now) | ||
| if found { | ||
| if excludeTwoSidedMatch && r.TargetMatchers.Matches(equal.Labels) { | ||
| return model.Fingerprint(0), false | ||
| equal, found = r.findEqualSourceAlertFromCache(lset, excludeTwoSidedMatch, now) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The new method is only called when a source alert is found in cache initially but is disqualified. |
||
| if !found { | ||
| return model.Fingerprint(0), false | ||
| } | ||
| return equal.Fingerprint(), true | ||
| } | ||
| return equal.Fingerprint(), found | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This scans the whole cache whenever the indexed source is two-sided which is O(number of source alerts), allocates a copy, locks the shared cache mutex, etc.
This is basically skipping the optimisations #4607 introduced.
Also the current benchmark matrix does not cover this case.