don't run blackhole cleanup routine when replaying logs

This commit is contained in:
Sebastien Blot 2022-08-16 15:12:56 +02:00
parent 662764929d
commit 5ae97d582c
No known key found for this signature in database
GPG key ID: DFC2902F40449F6A
3 changed files with 14 additions and 11 deletions

View file

@ -70,12 +70,15 @@ func runCrowdsec(cConfig *csconfig.Config, parsers *parser.Parsers) error {
parserWg.Wait()
bucketWg := &sync.WaitGroup{}
bucketsTomb.Go(func() error {
bucketWg.Add(1)
leakybucket.CleanupBlackhole(&bucketsTomb)
bucketWg.Done()
return nil
})
log.Infof("BucketsGCEnabled: %v", cConfig.Crowdsec.BucketsGCEnabled)
if !cConfig.Crowdsec.BucketsGCEnabled {
bucketsTomb.Go(func() error {
bucketWg.Add(1)
leakybucket.CleanupBlackhole(&bucketsTomb)
bucketWg.Done()
return nil
})
}
bucketsTomb.Go(func() error {
bucketWg.Add(1)
/*restore previous state as well if present*/

View file

@ -149,6 +149,8 @@ func LoadAcquisition(cConfig *csconfig.Config) error {
flags.Labels = labels
flags.Labels["type"] = flags.SingleFileType
cConfig.Crowdsec.BucketsGCEnabled = true
dataSources, err = acquisition.LoadAcquisitionFromDSN(flags.OneShotDSN, flags.Labels)
if err != nil {
return errors.Wrapf(err, "failed to configure datasource for %s", flags.OneShotDSN)

View file

@ -15,8 +15,7 @@ type Blackhole struct {
}
type BlackholeExpiration struct {
blExpiration time.Time
cleanupExpiration time.Time //we need a separate expiration for the cleanup to properly handle timemachine buckets
blExpiration time.Time
}
func NewBlackhole(bucketFactory *BucketFactory) (*Blackhole, error) {
@ -44,7 +43,7 @@ func CleanupBlackhole(bucketsTomb *tomb.Tomb) error {
return nil
case <-ticker.C:
BlackholeTracking.Range(func(key, value interface{}) bool {
cleanupDate := value.(BlackholeExpiration).cleanupExpiration
cleanupDate := value.(BlackholeExpiration).blExpiration
if cleanupDate.Before(time.Now().UTC()) {
log.Debugf("Expiring blackhole for %s", key)
BlackholeTracking.Delete(key)
@ -72,8 +71,7 @@ func (bl *Blackhole) OnBucketOverflow(bucketFactory *BucketFactory) func(*Leaky,
}
BlackholeTracking.Store(leaky.Mapkey, BlackholeExpiration{
blExpiration: leaky.Ovflw_ts.Add(bl.duration),
cleanupExpiration: time.Now().UTC().Add(bl.duration),
blExpiration: leaky.Ovflw_ts.Add(bl.duration),
})
leaky.logger.Debugf("Blackhole triggered for %s (expiration : %s)", leaky.Mapkey, leaky.Ovflw_ts.Add(bl.duration))