-
Notifications
You must be signed in to change notification settings - Fork 1
Move Rule evaluation to Source #324
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
Draft
oxzi
wants to merge
24
commits into
main
Choose a base branch
from
icingadb-source
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
86a9fa7
Move Rule evaluation to Source
oxzi ff8dd90
Don't store matched event rule IDs
yhabteab 5e02972
Drop `object_extra_tags` & all its references
yhabteab 4208b5c
Remove `icinga2` client & all its references
yhabteab 89bef39
Use the newly introduced notifications event utils from `igl`
yhabteab af7f7cf
Track event rules version in `RuntimeConfig`
yhabteab b9b10b1
listener: use HTTP X-* header constants from IGL
yhabteab 8de8cf7
listener: reject requests with status `412` on version mismatch
yhabteab d586494
go.mod(WIP): require not yet merged branch of IGL
yhabteab f7aa219
Update IGL for Notifications Changes
oxzi bb487d6
Source: Allow cached password comparison
oxzi dc4396a
Icinga DB Source: Address Review
oxzi 282e65a
Icinga DB Source: Address Review
oxzi efa458a
Relative Event URLs and stringified Event IDs
oxzi aea56a9
config.SourceRulesInfo: Minimize Version Conflicts
oxzi b480b42
listener: Reflect RulesInfo IGL update
oxzi 572b53f
Outsource pkg/{plugin,rpc} to IGL
oxzi 3a076e1
config: Rework SourceRulesInfo Version
oxzi 953e8ec
Reintroduce Extra Tags for Events
oxzi 495278e
event: Fix URL encoding
oxzi 777d5ba
Incident.applyMatchingRules: Simplify Source ID comparison
oxzi 8793629
config/listener: Mirco Fixes For Review
oxzi e4cb124
Micro Fixes for Rules at Source
oxzi af0bdd5
config: Rule Source ID Changes
oxzi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -66,7 +66,6 @@ database: | |
| # options: | ||
| #channel: | ||
| #database: | ||
| #icinga2: | ||
| #incident: | ||
| #listener: | ||
| #runtime-updates: | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -4,10 +4,78 @@ import ( | |
| "fmt" | ||
| "github.com/icinga/icinga-notifications/internal/rule" | ||
| "slices" | ||
| "time" | ||
| ) | ||
|
|
||
| // SourceRuleVersion for SourceRulesInfo, consisting of two numbers, one static and one incrementable. | ||
| type SourceRuleVersion struct { | ||
| Major int64 | ||
| Minor int64 | ||
| } | ||
|
|
||
| // NewSourceRuleVersion creates a new source version based on the current timestamp and a zero counter. | ||
| func NewSourceRuleVersion() SourceRuleVersion { | ||
| return SourceRuleVersion{ | ||
| Major: time.Now().UnixMilli(), | ||
| Minor: 0, | ||
| } | ||
| } | ||
|
|
||
| // Increment the version counter. | ||
| func (sourceVersion *SourceRuleVersion) Increment() { | ||
| sourceVersion.Minor++ | ||
| } | ||
|
|
||
| // String implements fmt.Stringer and returns a pretty-printable representation. | ||
| func (sourceVersion *SourceRuleVersion) String() string { | ||
| return fmt.Sprintf("%x-%x", sourceVersion.Major, sourceVersion.Minor) | ||
| } | ||
|
|
||
| // SourceRulesInfo holds information about the rules associated with a specific source. | ||
| type SourceRulesInfo struct { | ||
| // Version is the version of the rules for the source. | ||
| // | ||
| // Multiple source's versions are independent of another. | ||
| Version SourceRuleVersion | ||
|
|
||
| // RuleIDs is a list of rule IDs associated with a specific source. | ||
| // | ||
| // It is used to quickly access the rules for a specific source without iterating over all rules. | ||
| RuleIDs []int64 | ||
| } | ||
|
|
||
| // applyPendingRules synchronizes changed rules. | ||
| func (r *RuntimeConfig) applyPendingRules() { | ||
| // Keep track of sources the rules were updated for, so we can update their version later. | ||
| updatedSources := make(map[int64]struct{}) | ||
|
|
||
| if r.RulesBySource == nil { | ||
| r.RulesBySource = make(map[int64]*SourceRulesInfo) | ||
| } | ||
|
|
||
| addToRulesBySource := func(elem *rule.Rule) { | ||
| if sourceInfo, ok := r.RulesBySource[elem.SourceID]; ok { | ||
| sourceInfo.RuleIDs = append(sourceInfo.RuleIDs, elem.ID) | ||
| } else { | ||
| r.RulesBySource[elem.SourceID] = &SourceRulesInfo{ | ||
| Version: NewSourceRuleVersion(), | ||
| RuleIDs: []int64{elem.ID}, | ||
| } | ||
| } | ||
|
|
||
| updatedSources[elem.SourceID] = struct{}{} | ||
| } | ||
|
|
||
| delFromRulesBySource := func(elem *rule.Rule) { | ||
| if sourceInfo, ok := r.RulesBySource[elem.SourceID]; ok { | ||
| sourceInfo.RuleIDs = slices.DeleteFunc(sourceInfo.RuleIDs, func(id int64) bool { | ||
| return id == elem.ID | ||
| }) | ||
| } | ||
|
|
||
| updatedSources[elem.SourceID] = struct{}{} | ||
| } | ||
|
|
||
| incrementalApplyPending( | ||
| r, | ||
| &r.Rules, &r.configChange.Rules, | ||
|
|
@@ -21,6 +89,9 @@ func (r *RuntimeConfig) applyPendingRules() { | |
| } | ||
|
|
||
| newElement.Escalations = make(map[int64]*rule.Escalation) | ||
|
|
||
| addToRulesBySource(newElement) | ||
|
|
||
| return nil | ||
| }, | ||
| func(curElement, update *rule.Rule) error { | ||
|
|
@@ -38,13 +109,35 @@ func (r *RuntimeConfig) applyPendingRules() { | |
| curElement.TimePeriod = nil | ||
| } | ||
|
|
||
| if curElement.SourceID != update.SourceID { | ||
| delFromRulesBySource(curElement) | ||
| curElement.SourceID = update.SourceID | ||
| addToRulesBySource(curElement) | ||
| } | ||
|
|
||
| // ObjectFilter{,Expr} are being initialized by config.IncrementalConfigurableInitAndValidatable. | ||
| curElement.ObjectFilter = update.ObjectFilter | ||
| curElement.ObjectFilterExpr = update.ObjectFilterExpr | ||
|
Comment on lines
118
to
119
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 comment is outdated now. |
||
|
|
||
| updatedSources[curElement.SourceID] = struct{}{} | ||
|
|
||
| return nil | ||
| }, | ||
| nil) | ||
| func(delElement *rule.Rule) error { | ||
| delFromRulesBySource(delElement) | ||
|
|
||
| return nil | ||
| }, | ||
| ) | ||
|
|
||
| // After applying the rules, we need to update the version of the sources that were modified. | ||
| // This is done to ensure that the version is incremented whenever a rule is added, modified, | ||
| // or deleted only once per applyPendingRules call, even if multiple rules from the same source | ||
| // were changed. | ||
| for sourceID := range updatedSources { | ||
| if sourceInfo, ok := r.RulesBySource[sourceID]; ok { | ||
| sourceInfo.Version.Increment() | ||
| } | ||
| } | ||
|
|
||
| incrementalApplyPending( | ||
| r, | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Oh, and JSON doesn't like trailing commas 🙈