-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
nflog: use alert set instead of hash for deduplication
Building a hash over an entire set of alerts causes problems, because the hash differs, on any change, whereas we only want to send notifications if the alert and it's state have changed. Therefore this introduces a list of alerts that are active and a list of alerts that are resolved. If the currently active alerts of a group are a subset of the ones that have been notified about before then they are deduplicated. The resolved notifications work the same way, with a separate list of resolved notifications that have already been sent.
- Loading branch information
Showing
9 changed files
with
321 additions
and
191 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package nflogpb | ||
|
||
func (m *Entry) IsFiringSubset(subset map[uint64]struct{}) bool { | ||
set := map[uint64]struct{}{} | ||
for i := range m.FiringAlerts { | ||
set[m.FiringAlerts[i]] = struct{}{} | ||
} | ||
|
||
return isSubset(set, subset) | ||
} | ||
|
||
func (m *Entry) IsResolvedSubset(subset map[uint64]struct{}) bool { | ||
set := map[uint64]struct{}{} | ||
for i := range m.ResolvedAlerts { | ||
set[m.ResolvedAlerts[i]] = struct{}{} | ||
} | ||
|
||
return isSubset(set, subset) | ||
} | ||
|
||
func isSubset(set, subset map[uint64]struct{}) bool { | ||
for k, _ := range subset { | ||
_, exists := set[k] | ||
if !exists { | ||
return false | ||
} | ||
} | ||
|
||
return true | ||
} |
Oops, something went wrong.