Skip to content

Commit 6829870

Browse files
authored
Bugfix/correlation/minor bugfixes (#696)
* ensure smooth cache cleanup and mutex release * sleep for the rule sleep time * fixing identation * updating standard rules each 48 hours
1 parent 903a212 commit 6829870

File tree

4 files changed

+8
-6
lines changed

4 files changed

+8
-6
lines changed

correlation/cache/cache.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ func Status() {
3232
func Search(allOf []rules.AllOf, oneOf []rules.OneOf, seconds int64) []string {
3333
var elements []string
3434
cacheStorageMutex.RLock()
35+
defer cacheStorageMutex.RUnlock()
36+
3537
cToBreak := 0
3638
ait := time.Now().UTC().Unix() - func() int64 {
3739
switch seconds {
@@ -75,7 +77,7 @@ func Search(allOf []rules.AllOf, oneOf []rules.OneOf, seconds int64) []string {
7577
}
7678
}
7779
}
78-
cacheStorageMutex.RUnlock()
80+
7981
return elements
8082
}
8183

@@ -107,7 +109,7 @@ func Clean() {
107109
for {
108110
var clean bool
109111

110-
if len(CacheStorage) > 500 {
112+
if len(CacheStorage) > 1 {
111113
if utils.AssignedMemory >= 80 {
112114
clean = true
113115
} else {
@@ -128,7 +130,7 @@ func Clean() {
128130

129131
if clean {
130132
cacheStorageMutex.Lock()
131-
CacheStorage = CacheStorage[500:]
133+
CacheStorage = CacheStorage[1:]
132134
cacheStorageMutex.Unlock()
133135
} else {
134136
time.Sleep(5 * time.Second)

correlation/correlation/finder.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func Finder(rule rules.Rule) {
4848
}
4949

5050
if !execute {
51-
time.Sleep(1 * time.Minute)
51+
time.Sleep(sleep)
5252
continue
5353
}
5454

correlation/rules/rules.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ type OneOf struct {
5151
type Cache struct {
5252
AllOf []AllOf `yaml:"allOf"`
5353
OneOf []OneOf `yaml:"oneOf"`
54-
TimeLapse int64 `yaml:"timeLapse"`
54+
TimeLapse int64 `yaml:"timeLapse"`
5555
MinCount int `yaml:"minCount"`
5656
Save []SavedField `yaml:"save"`
5757
}

correlation/rules/update.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func Update(updateReady chan bool) {
2626
}
2727

2828
log.Println("Rules updated")
29-
time.Sleep(24 * time.Hour)
29+
time.Sleep(48 * time.Hour)
3030
}
3131
}
3232

0 commit comments

Comments
 (0)