|
5 | 5 | "database/sql" |
6 | 6 | "fmt" |
7 | 7 | "net/url" |
8 | | - "sync" |
9 | 8 | "time" |
10 | 9 |
|
11 | 10 | "github.com/icinga/icinga-go-library/database" |
@@ -33,8 +32,7 @@ type Source struct { |
33 | 32 | db *database.DB |
34 | 33 | logger *logging.Logger |
35 | 34 |
|
36 | | - rules *notifications.SourceRulesInfo // rules holds the latest rules fetched from Icinga Notifications. |
37 | | - rulesMutex sync.RWMutex // rulesMutex protects access to the rules field. |
| 35 | + rules *notifications.SourceRulesInfo // rules holds the latest rules fetched from Icinga Notifications. |
38 | 36 |
|
39 | 37 | ctx context.Context |
40 | 38 | ctxCancel context.CancelFunc |
@@ -96,9 +94,6 @@ func NewNotificationsSource( |
96 | 94 | // |
97 | 95 | // The :host_id and :environment_id parameters will be bound to the entity's ID and EnvironmentId fields, respectively. |
98 | 96 | func (s *Source) evaluateRulesForObject(ctx context.Context, entity database.Entity) ([]int64, error) { |
99 | | - s.rulesMutex.RLock() |
100 | | - defer s.rulesMutex.RUnlock() |
101 | | - |
102 | 97 | outRuleIds := make([]int64, 0, len(s.rules.Rules)) |
103 | 98 |
|
104 | 99 | for rule := range s.rules.Iter() { |
@@ -408,15 +403,9 @@ func (s *Source) worker() { |
408 | 403 | continue |
409 | 404 | } |
410 | 405 |
|
411 | | - s.rulesMutex.RLock() |
412 | | - ruleVersion := s.rules.Version |
413 | | - s.rulesMutex.RUnlock() |
414 | | - |
415 | | - newEventRules, err := s.notificationsClient.ProcessEvent(s.ctx, ev, ruleVersion, eventRuleIds...) |
| 406 | + newEventRules, err := s.notificationsClient.ProcessEvent(s.ctx, ev, s.rules.Version, eventRuleIds...) |
416 | 407 | if errors.Is(err, notifications.ErrRulesOutdated) { |
417 | | - s.rulesMutex.Lock() |
418 | 408 | s.rules = newEventRules |
419 | | - s.rulesMutex.Unlock() |
420 | 409 |
|
421 | 410 | eventLogger.Debugw("Re-evaluating rules for event after fetching new rules", zap.String("rules_version", s.rules.Version)) |
422 | 411 |
|
|
0 commit comments