Skip to content

Commit 4624f98

Browse files
authored
pkg/leakybucket: remove global bucketStore, unused parameters + tags (#4286)
1 parent 991682f commit 4624f98

File tree

4 files changed

+22
-24
lines changed

4 files changed

+22
-24
lines changed

cmd/crowdsec/crowdsec.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ func startParserRoutines(ctx context.Context, g *errgroup.Group, cConfig *csconf
8282
}
8383
}
8484

85-
func startBucketRoutines(ctx context.Context, g *errgroup.Group, cConfig *csconfig.Config, pourCollector *leakybucket.PourCollector) {
85+
func startBucketRoutines(ctx context.Context, g *errgroup.Group, cConfig *csconfig.Config, pourCollector *leakybucket.PourCollector, bucketStore *leakybucket.BucketStore) {
8686
for idx := range cConfig.Crowdsec.BucketsRoutinesCount {
8787
log.WithField("idx", idx).Info("Starting bucket routine")
8888
g.Go(func() error {
@@ -98,7 +98,7 @@ func startHeartBeat(ctx context.Context, _ *csconfig.Config, apiClient *apiclien
9898
apiClient.HeartBeat.StartHeartBeat(ctx)
9999
}
100100

101-
func startOutputRoutines(ctx context.Context, cConfig *csconfig.Config, parsers *parser.Parsers, apiClient *apiclient.ApiClient, sd *StateDumper) {
101+
func startOutputRoutines(ctx context.Context, cConfig *csconfig.Config, parsers *parser.Parsers, apiClient *apiclient.ApiClient, sd *StateDumper, bucketStore *leakybucket.BucketStore) {
102102
for idx := range cConfig.Crowdsec.OutputRoutinesCount {
103103
log.WithField("idx", idx).Info("Starting output routine")
104104
outputsTomb.Go(func() error {
@@ -144,12 +144,13 @@ func runCrowdsec(
144144
hub *cwhub.Hub,
145145
datasources []acquisitionTypes.DataSource,
146146
sd *StateDumper,
147+
bucketStore *leakybucket.BucketStore,
147148
) error {
148149
inEvents = make(chan pipeline.Event)
149150
logLines = make(chan pipeline.Event)
150151

151152
startParserRoutines(ctx, g, cConfig, parsers, sd.StageParse)
152-
startBucketRoutines(ctx, g, cConfig, sd.Pour)
153+
startBucketRoutines(ctx, g, cConfig, sd.Pour, bucketStore)
153154

154155
apiClient, err := apiclient.GetLAPIClient()
155156
if err != nil {
@@ -158,7 +159,7 @@ func runCrowdsec(
158159

159160
startHeartBeat(ctx, cConfig, apiClient)
160161

161-
startOutputRoutines(ctx, cConfig, parsers, apiClient, sd)
162+
startOutputRoutines(ctx, cConfig, parsers, apiClient, sd, bucketStore)
162163

163164
if err := startLPMetrics(ctx, cConfig, apiClient, hub, datasources); err != nil {
164165
return err
@@ -187,6 +188,8 @@ func serveCrowdsec(
187188

188189
var g errgroup.Group
189190

191+
bucketStore := leakybucket.NewBucketStore()
192+
190193
crowdsecTomb.Go(func() error {
191194
defer trace.CatchPanic("crowdsec/serveCrowdsec")
192195

@@ -197,7 +200,7 @@ func serveCrowdsec(
197200

198201
agentReady <- true
199202

200-
if err := runCrowdsec(cctx, &g, cConfig, parsers, hub, datasources, sd); err != nil {
203+
if err := runCrowdsec(cctx, &g, cConfig, parsers, hub, datasources, sd, bucketStore); err != nil {
201204
log.Fatalf("unable to start crowdsec routines: %s", err)
202205
}
203206
}()

cmd/crowdsec/main.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ var (
4343
dataSources []acquisitionTypes.DataSource
4444
// the state of the buckets
4545
holders []leakybucket.BucketFactory
46-
bucketStore *leakybucket.BucketStore
4746

4847
logLines chan pipeline.Event
4948
inEvents chan pipeline.Event
@@ -54,13 +53,11 @@ var (
5453
func LoadBuckets(cConfig *csconfig.Config, hub *cwhub.Hub) error {
5554
var err error
5655

57-
bucketStore = leakybucket.NewBucketStore()
58-
5956
scenarios := hub.GetInstalledByType(cwhub.SCENARIOS, false)
6057

6158
log.Infof("Loading %d scenario files", len(scenarios))
6259

63-
holders, outEvents, err = leakybucket.LoadBuckets(cConfig.Crowdsec, hub, scenarios, bucketStore, flags.OrderEvent)
60+
holders, outEvents, err = leakybucket.LoadBuckets(cConfig.Crowdsec, hub, scenarios, flags.OrderEvent)
6461
if err != nil {
6562
return err
6663
}

pkg/leakybucket/bucketstore_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ func testOneBucket(t *testing.T, hub *cwhub.Hub, dir string) {
123123

124124
cscfg := &csconfig.CrowdsecServiceCfg{}
125125

126-
holders, response, err := LoadBuckets(cscfg, hub, scenarios, bucketStore, false)
126+
holders, response, err := LoadBuckets(cscfg, hub, scenarios, false)
127127
require.NoError(t, err)
128128

129129
testFile(t, filepath.Join(dir, "test.json"), holders, response, bucketStore)

pkg/leakybucket/manager_load.go

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -58,18 +58,18 @@ type BucketSpec struct {
5858
type BucketFactory struct {
5959
Spec BucketSpec
6060

61-
logger *log.Entry // logger is bucket-specific logger (used by Debug as well)
62-
BucketName string `yaml:"-"`
63-
Filename string `yaml:"-"`
64-
RunTimeFilter *vm.Program `json:"-"`
65-
RunTimeGroupBy *vm.Program `json:"-"`
66-
DataDir string `yaml:"-"`
67-
leakspeed time.Duration // internal representation of `Leakspeed`
68-
duration time.Duration // internal representation of `Duration`
69-
ret chan pipeline.Event // the bucket-specific output chan for overflows
70-
processors []Processor // processors is the list of hooks for pour/overflow/create (cf. uniq, blackhole etc.)
61+
logger *log.Entry // logger is bucket-specific logger (used by Debug as well)
62+
BucketName string
63+
Filename string
64+
RunTimeFilter *vm.Program `json:"-"`
65+
RunTimeGroupBy *vm.Program `json:"-"`
66+
DataDir string
67+
leakspeed time.Duration // internal representation of `Leakspeed`
68+
duration time.Duration // internal representation of `Duration`
69+
ret chan pipeline.Event // the bucket-specific output chan for overflows
70+
processors []Processor // processors is the list of hooks for pour/overflow/create (cf. uniq, blackhole etc.)
7171
hash string
72-
Simulated bool `yaml:"simulated"` // Set to true if the scenario instantiating the bucket was in the exclusion list
72+
Simulated bool // Set to true if the scenario instantiating the bucket was in the exclusion list
7373
orderEvent bool
7474
}
7575

@@ -104,7 +104,6 @@ type SimulationChecker interface {
104104
func loadBucketFactoriesFromFile(
105105
item *cwhub.Item,
106106
hub *cwhub.Hub,
107-
bucketStore *BucketStore,
108107
response chan pipeline.Event,
109108
orderEvent bool,
110109
simcheck SimulationChecker,
@@ -186,7 +185,6 @@ func LoadBuckets(
186185
cscfg *csconfig.CrowdsecServiceCfg,
187186
hub *cwhub.Hub,
188187
scenarios []*cwhub.Item,
189-
bucketStore *BucketStore,
190188
orderEvent bool,
191189
) ([]BucketFactory, chan pipeline.Event, error) {
192190
allFactories := []BucketFactory{}
@@ -195,7 +193,7 @@ func LoadBuckets(
195193
for _, item := range scenarios {
196194
log.Debugf("Loading '%s'", item.State.LocalPath)
197195

198-
factories, err := loadBucketFactoriesFromFile(item, hub, bucketStore, response, orderEvent, &cscfg.SimulationConfig)
196+
factories, err := loadBucketFactoriesFromFile(item, hub, response, orderEvent, &cscfg.SimulationConfig)
199197
if err != nil {
200198
return nil, nil, err
201199
}

0 commit comments

Comments
 (0)