Skip to content

Commit 93931cb

Browse files
committed
refact parser, leakybucket: internal concurrency safe name generator
1 parent a6b61ed commit 93931cb

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
@@ -51,7 +51,6 @@ require (
5151
github.com/google/go-querystring v1.1.0
5252
github.com/google/uuid v1.6.0
5353
github.com/google/winops v0.0.0-20230712152054-af9b550d0601
54-
github.com/goombaio/namegenerator v0.0.0-20181006234301-989e774b106e
5554
github.com/gorilla/websocket v1.5.0
5655
github.com/hashicorp/go-hclog v1.5.0
5756
github.com/hashicorp/go-plugin v1.6.3

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,8 +279,6 @@ github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
279279
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
280280
github.com/google/winops v0.0.0-20230712152054-af9b550d0601 h1:XvlrmqZIuwxuRE88S9mkxX+FkV+YakqbiAC5Z4OzDnM=
281281
github.com/google/winops v0.0.0-20230712152054-af9b550d0601/go.mod h1:rT1mcjzuvcDDbRmUTsoH6kV0DG91AkFe9UCjASraK5I=
282-
github.com/goombaio/namegenerator v0.0.0-20181006234301-989e774b106e h1:XmA6L9IPRdUr28a+SK/oMchGgQy159wvzXA5tJ7l+40=
283-
github.com/goombaio/namegenerator v0.0.0-20181006234301-989e774b106e/go.mod h1:AFIo+02s+12CEg8Gzz9kzhCbmbq6JcKNrhHffCGA9z4=
284282
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
285283
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=
286284
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
"gopkg.in/tomb.v2"
1716
yaml "gopkg.in/yaml.v2"
@@ -23,6 +22,7 @@ import (
2322
"github.com/crowdsecurity/crowdsec/pkg/enrichment"
2423
"github.com/crowdsecurity/crowdsec/pkg/exprhelpers"
2524
"github.com/crowdsecurity/crowdsec/pkg/logging"
25+
"github.com/crowdsecurity/crowdsec/pkg/namegenerator"
2626
"github.com/crowdsecurity/crowdsec/pkg/pipeline"
2727
"github.com/crowdsecurity/crowdsec/pkg/types"
2828
)
@@ -75,9 +75,6 @@ type BucketFactory struct {
7575
orderEvent bool
7676
}
7777

78-
// we use one NameGenerator for all the future buckets
79-
var seed = namegenerator.NewNameGenerator(time.Now().UTC().UnixNano())
80-
8178
func validateLeakyType(bucketFactory *BucketFactory) error {
8279
if bucketFactory.Capacity <= 0 { // capacity must be a positive int
8380
return fmt.Errorf("bad capacity for leaky '%d'", bucketFactory.Capacity)
@@ -288,7 +285,7 @@ func loadBucketFactoriesFromFile(item *cwhub.Item, hub *cwhub.Hub, buckets *Buck
288285
}
289286

290287
bucketFactory.Filename = filepath.Clean(itemPath)
291-
bucketFactory.BucketName = seed.Generate()
288+
bucketFactory.BucketName = namegenerator.GetRandomName()
292289
bucketFactory.ret = response
293290

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

0 commit comments

Comments
 (0)