Skip to content

Commit bca1aba

Browse files
committed
refact parser, leakybucket: internal concurrency safe name generator
1 parent 388bace commit bca1aba

File tree

7 files changed

+1565
-14
lines changed

7 files changed

+1565
-14
lines changed

go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ require (
4747
github.com/google/go-querystring v1.1.0
4848
github.com/google/uuid v1.6.0
4949
github.com/google/winops v0.0.0-20230712152054-af9b550d0601
50-
github.com/goombaio/namegenerator v0.0.0-20181006234301-989e774b106e
5150
github.com/gorilla/websocket v1.5.0
5251
github.com/hashicorp/go-hclog v1.5.0
5352
github.com/hashicorp/go-plugin v1.6.3

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,6 @@ github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
261261
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
262262
github.com/google/winops v0.0.0-20230712152054-af9b550d0601 h1:XvlrmqZIuwxuRE88S9mkxX+FkV+YakqbiAC5Z4OzDnM=
263263
github.com/google/winops v0.0.0-20230712152054-af9b550d0601/go.mod h1:rT1mcjzuvcDDbRmUTsoH6kV0DG91AkFe9UCjASraK5I=
264-
github.com/goombaio/namegenerator v0.0.0-20181006234301-989e774b106e h1:XmA6L9IPRdUr28a+SK/oMchGgQy159wvzXA5tJ7l+40=
265-
github.com/goombaio/namegenerator v0.0.0-20181006234301-989e774b106e/go.mod h1:AFIo+02s+12CEg8Gzz9kzhCbmbq6JcKNrhHffCGA9z4=
266264
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
267265
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=
268266
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=

pkg/leakybucket/bucket.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"github.com/crowdsecurity/go-cs-lib/trace"
1717

1818
"github.com/crowdsecurity/crowdsec/pkg/metrics"
19+
"github.com/crowdsecurity/crowdsec/pkg/namegenerator"
1920
"github.com/crowdsecurity/crowdsec/pkg/pipeline"
2021
)
2122

@@ -106,7 +107,7 @@ func FromFactory(bucketFactory BucketFactory) *Leaky {
106107
l := &Leaky{
107108
Name: bucketFactory.Name,
108109
Limiter: limiter,
109-
Uuid: seed.Generate(),
110+
Uuid: namegenerator.GetRandomName(),
110111
Queue: pipeline.NewQueue(Qsize),
111112
CacheSize: bucketFactory.CacheSize,
112113
Out: make(chan *pipeline.Queue, 1),

pkg/leakybucket/manager_load.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111

1212
"github.com/expr-lang/expr"
1313
"github.com/expr-lang/expr/vm"
14-
"github.com/goombaio/namegenerator"
1514
log "github.com/sirupsen/logrus"
1615
yaml "gopkg.in/yaml.v2"
1716

@@ -22,6 +21,7 @@ import (
2221
"github.com/crowdsecurity/crowdsec/pkg/enrichment"
2322
"github.com/crowdsecurity/crowdsec/pkg/exprhelpers"
2423
"github.com/crowdsecurity/crowdsec/pkg/logging"
24+
"github.com/crowdsecurity/crowdsec/pkg/namegenerator"
2525
"github.com/crowdsecurity/crowdsec/pkg/pipeline"
2626
"github.com/crowdsecurity/crowdsec/pkg/types"
2727
)
@@ -73,9 +73,6 @@ type BucketFactory struct {
7373
orderEvent bool
7474
}
7575

76-
// we use one NameGenerator for all the future buckets
77-
var seed = namegenerator.NewNameGenerator(time.Now().UTC().UnixNano())
78-
7976
func validateLeakyType(bucketFactory *BucketFactory) error {
8077
if bucketFactory.Capacity <= 0 { // capacity must be a positive int
8178
return fmt.Errorf("bad capacity for leaky '%d'", bucketFactory.Capacity)
@@ -286,7 +283,7 @@ func loadBucketFactoriesFromFile(item *cwhub.Item, hub *cwhub.Hub, buckets *Buck
286283
}
287284

288285
bucketFactory.Filename = filepath.Clean(itemPath)
289-
bucketFactory.BucketName = seed.Generate()
286+
bucketFactory.BucketName = namegenerator.GetRandomName()
290287
bucketFactory.ret = response
291288

292289
bucketFactory.Simulated = simulationConfig.IsSimulated(bucketFactory.Name)

0 commit comments

Comments
 (0)