fix: improve inhibition performance#4607
Conversation
a91f2cf to
f2a5647
Compare
|
There is a flaky test which I narrowed to this case: {
name: "matching and unresolved",
initial: map[model.Fingerprint]*types.Alert{
1: {
Alert: model.Alert{
Labels: model.LabelSet{"a": "b", "c": "d"},
StartsAt: now.Add(-time.Minute),
EndsAt: now.Add(-time.Second),
},
},
2: {
Alert: model.Alert{
Labels: model.LabelSet{"a": "b", "c": "f"},
StartsAt: now.Add(-time.Minute),
EndsAt: now.Add(time.Hour),
},
},
},
equal: model.LabelNames{"a"},
input: model.LabelSet{"a": "b"},
result: true,
},The test is flaky since we use a The test can be made consistent by simply switching to a |
|
An idea to fix the flaky test and the logic would be to always compare a new source alert |
This change adds a new index per inhibition rule which: 1. extracts the subset of source alert labelset which are in equals 2. calculates the fingerprint of the above 3. maps the calculated fingerprint to the source alert fingerprint 4. performs the same calculation for target alerts 5. uses the above index to find the equal source alerts quickly This significantly improves the inhibition performance, since there is no need to loop over all source alerts and the equal labels. The equals index items are garbage collected by callback from `scache`. Signed-off-by: Siavash Safi <siavash@cloudflare.com>
f2a5647 to
e60f4f0
Compare
|
Fixed the flaky test in the last change. |
SuperQ
left a comment
There was a problem hiding this comment.
LGTM, thanks for fixing the flaky test.

This change adds a new index per inhibition rule which:
This significantly improves the inhibition performance, since there is no need to loop over all source alerts and the equal labels.
The equals index items are garbage collected by callback from
scache.Fixes #4606
Benchmarks