avoid create a new name generator at each bucket instanciation, it's not that cheap (#1591)
This commit is contained in:
parent
67841d54ee
commit
ff72a3c1c7
|
@ -9,7 +9,6 @@ import (
|
||||||
//"log"
|
//"log"
|
||||||
"github.com/crowdsecurity/crowdsec/pkg/time/rate"
|
"github.com/crowdsecurity/crowdsec/pkg/time/rate"
|
||||||
"github.com/crowdsecurity/crowdsec/pkg/types"
|
"github.com/crowdsecurity/crowdsec/pkg/types"
|
||||||
"github.com/goombaio/namegenerator"
|
|
||||||
"gopkg.in/tomb.v2"
|
"gopkg.in/tomb.v2"
|
||||||
|
|
||||||
//rate "time/rate"
|
//rate "time/rate"
|
||||||
|
@ -158,7 +157,7 @@ func FromFactory(bucketFactory BucketFactory) *Leaky {
|
||||||
l := &Leaky{
|
l := &Leaky{
|
||||||
Name: bucketFactory.Name,
|
Name: bucketFactory.Name,
|
||||||
Limiter: limiter,
|
Limiter: limiter,
|
||||||
Uuid: namegenerator.NewNameGenerator(time.Now().UTC().UnixNano()).Generate(),
|
Uuid: seed.Generate(),
|
||||||
Queue: NewQueue(Qsize),
|
Queue: NewQueue(Qsize),
|
||||||
CacheSize: bucketFactory.CacheSize,
|
CacheSize: bucketFactory.CacheSize,
|
||||||
Out: make(chan *Queue, 1),
|
Out: make(chan *Queue, 1),
|
||||||
|
|
|
@ -74,6 +74,9 @@ type BucketFactory struct {
|
||||||
wgDumpState *sync.WaitGroup `yaml:"-"`
|
wgDumpState *sync.WaitGroup `yaml:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//we use one NameGenerator for all the future buckets
|
||||||
|
var seed namegenerator.Generator = namegenerator.NewNameGenerator(time.Now().UTC().UnixNano())
|
||||||
|
|
||||||
func ValidateFactory(bucketFactory *BucketFactory) error {
|
func ValidateFactory(bucketFactory *BucketFactory) error {
|
||||||
if bucketFactory.Name == "" {
|
if bucketFactory.Name == "" {
|
||||||
return fmt.Errorf("bucket must have name")
|
return fmt.Errorf("bucket must have name")
|
||||||
|
@ -147,8 +150,6 @@ func LoadBuckets(cscfg *csconfig.CrowdsecServiceCfg, files []string, tomb *tomb.
|
||||||
response chan types.Event
|
response chan types.Event
|
||||||
)
|
)
|
||||||
|
|
||||||
var seed namegenerator.Generator = namegenerator.NewNameGenerator(time.Now().UTC().UnixNano())
|
|
||||||
|
|
||||||
response = make(chan types.Event, 1)
|
response = make(chan types.Event, 1)
|
||||||
for _, f := range files {
|
for _, f := range files {
|
||||||
log.Debugf("Loading '%s'", f)
|
log.Debugf("Loading '%s'", f)
|
||||||
|
|
Loading…
Reference in a new issue