up
This commit is contained in:
parent
5ae97d582c
commit
56f457d4e3
2 changed files with 16 additions and 11 deletions
|
@ -70,11 +70,12 @@ func runCrowdsec(cConfig *csconfig.Config, parsers *parser.Parsers) error {
|
||||||
parserWg.Wait()
|
parserWg.Wait()
|
||||||
|
|
||||||
bucketWg := &sync.WaitGroup{}
|
bucketWg := &sync.WaitGroup{}
|
||||||
log.Infof("BucketsGCEnabled: %v", cConfig.Crowdsec.BucketsGCEnabled)
|
//Only start the blackhole GC routine if buckets GC is not enabled, ie we are replaying a file
|
||||||
|
//This is because the GC routine expects events to happen in real time, which is not the case during a replay.
|
||||||
if !cConfig.Crowdsec.BucketsGCEnabled {
|
if !cConfig.Crowdsec.BucketsGCEnabled {
|
||||||
bucketsTomb.Go(func() error {
|
bucketsTomb.Go(func() error {
|
||||||
bucketWg.Add(1)
|
bucketWg.Add(1)
|
||||||
leakybucket.CleanupBlackhole(&bucketsTomb)
|
leakybucket.BlackholeGC(&bucketsTomb)
|
||||||
bucketWg.Done()
|
bucketWg.Done()
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
|
|
@ -30,7 +30,18 @@ func NewBlackhole(bucketFactory *BucketFactory) (*Blackhole, error) {
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func CleanupBlackhole(bucketsTomb *tomb.Tomb) error {
|
func CleanupBlackhole(lastEvent time.Time) {
|
||||||
|
BlackholeTracking.Range(func(key, value interface{}) bool {
|
||||||
|
cleanupDate := value.(BlackholeExpiration).blExpiration
|
||||||
|
if cleanupDate.Before(lastEvent) {
|
||||||
|
log.Debugf("Expiring blackhole for %s", key)
|
||||||
|
BlackholeTracking.Delete(key)
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func BlackholeGC(bucketsTomb *tomb.Tomb) error {
|
||||||
ticker := time.NewTicker(10 * time.Second)
|
ticker := time.NewTicker(10 * time.Second)
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
|
@ -42,14 +53,7 @@ func CleanupBlackhole(bucketsTomb *tomb.Tomb) error {
|
||||||
})
|
})
|
||||||
return nil
|
return nil
|
||||||
case <-ticker.C:
|
case <-ticker.C:
|
||||||
BlackholeTracking.Range(func(key, value interface{}) bool {
|
CleanupBlackhole(time.Now().UTC())
|
||||||
cleanupDate := value.(BlackholeExpiration).blExpiration
|
|
||||||
if cleanupDate.Before(time.Now().UTC()) {
|
|
||||||
log.Debugf("Expiring blackhole for %s", key)
|
|
||||||
BlackholeTracking.Delete(key)
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue