Skip to content

Commit 32b933d

Browse files
yhabteaboxzi
authored andcommitted
Drop superfluous rulesMutex
There won't be any concurrent access to the rules, so we don't need to guard it with a mutex.
1 parent 28ffcb6 commit 32b933d

File tree

1 file changed

+2
-13
lines changed

1 file changed

+2
-13
lines changed

pkg/notifications/notifications.go

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"database/sql"
66
"fmt"
77
"net/url"
8-
"sync"
98
"time"
109

1110
"github.com/icinga/icinga-go-library/database"
@@ -33,8 +32,7 @@ type Source struct {
3332
db *database.DB
3433
logger *logging.Logger
3534

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.
3836

3937
ctx context.Context
4038
ctxCancel context.CancelFunc
@@ -96,9 +94,6 @@ func NewNotificationsSource(
9694
//
9795
// The :host_id and :environment_id parameters will be bound to the entity's ID and EnvironmentId fields, respectively.
9896
func (s *Source) evaluateRulesForObject(ctx context.Context, entity database.Entity) ([]int64, error) {
99-
s.rulesMutex.RLock()
100-
defer s.rulesMutex.RUnlock()
101-
10297
outRuleIds := make([]int64, 0, len(s.rules.Rules))
10398

10499
for rule := range s.rules.Iter() {
@@ -408,15 +403,9 @@ func (s *Source) worker() {
408403
continue
409404
}
410405

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...)
416407
if errors.Is(err, notifications.ErrRulesOutdated) {
417-
s.rulesMutex.Lock()
418408
s.rules = newEventRules
419-
s.rulesMutex.Unlock()
420409

421410
eventLogger.Debugw("Re-evaluating rules for event after fetching new rules", zap.String("rules_version", s.rules.Version))
422411

0 commit comments

Comments
 (0)