Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

loop performance optimizations / 2 #3364

Merged
merged 4 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pkg/alertcontext/alertcontext.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,8 @@ func EventToContext(events []types.Event) (models.Meta, []error) {

tmpContext := make(map[string][]string)

for _, evt := range events {
tmpErrors := EvalAlertContextRules(evt, nil, nil, tmpContext)
for i := range events {
tmpErrors := EvalAlertContextRules(events[i], nil, nil, tmpContext)
errors = append(errors, tmpErrors...)
}

Expand Down
20 changes: 10 additions & 10 deletions pkg/dumps/parser_dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,25 +145,25 @@
}

func (t *tree) processBuckets(bucketPour BucketPourInfo) {
for bname, evtlist := range bucketPour {
for _, evt := range evtlist {
if evt.Line.Raw == "" {
for bname, events := range bucketPour {
for i := range events {
if events[i].Line.Raw == "" {
continue
}

// it might be bucket overflow being reprocessed, skip this
if _, ok := t.state[evt.Line.Time]; !ok {
t.state[evt.Line.Time] = make(map[string]map[string]ParserResult)
t.assoc[evt.Line.Time] = evt.Line.Raw
if _, ok := t.state[events[i].Line.Time]; !ok {
t.state[events[i].Line.Time] = make(map[string]map[string]ParserResult)
t.assoc[events[i].Line.Time] = events[i].Line.Raw

Check warning on line 157 in pkg/dumps/parser_dump.go

View check run for this annotation

Codecov / codecov/patch

pkg/dumps/parser_dump.go#L156-L157

Added lines #L156 - L157 were not covered by tests
}

// there is a trick : to know if an event successfully exit the parsers, we check if it reached the pour() phase
// there is a trick: to know if an event successfully exit the parsers, we check if it reached the pour() phase
// we thus use a fake stage "buckets" and a fake parser "OK" to know if it entered
if _, ok := t.state[evt.Line.Time]["buckets"]; !ok {
t.state[evt.Line.Time]["buckets"] = make(map[string]ParserResult)
if _, ok := t.state[events[i].Line.Time]["buckets"]; !ok {
t.state[events[i].Line.Time]["buckets"] = make(map[string]ParserResult)
}

t.state[evt.Line.Time]["buckets"][bname] = ParserResult{Success: true}
t.state[events[i].Line.Time]["buckets"][bname] = ParserResult{Success: true}
}
}
}
Expand Down
24 changes: 12 additions & 12 deletions pkg/leakybucket/manager_load.go
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@
return fmt.Errorf("can't parse state file %s: %w", file, err)
}

for k, v := range state {
for k := range state {
var tbucket *Leaky

log.Debugf("Reloading bucket %s", k)
Expand All @@ -509,30 +509,30 @@
found := false

for _, h := range bucketFactories {
if h.Name != v.Name {
if h.Name != state[k].Name {
continue
}

log.Debugf("found factory %s/%s -> %s", h.Author, h.Name, h.Description)
// check in which mode the bucket was
if v.Mode == types.TIMEMACHINE {
if state[k].Mode == types.TIMEMACHINE {
tbucket = NewTimeMachine(h)
} else if v.Mode == types.LIVE {
} else if state[k].Mode == types.LIVE {
tbucket = NewLeaky(h)
} else {
log.Errorf("Unknown bucket type : %d", v.Mode)
log.Errorf("Unknown bucket type : %d", state[k].Mode)

Check warning on line 523 in pkg/leakybucket/manager_load.go

View check run for this annotation

Codecov / codecov/patch

pkg/leakybucket/manager_load.go#L523

Added line #L523 was not covered by tests
}
/*Trying to restore queue state*/
tbucket.Queue = v.Queue
tbucket.Queue = state[k].Queue
/*Trying to set the limiter to the saved values*/
tbucket.Limiter.Load(v.SerializedState)
tbucket.Limiter.Load(state[k].SerializedState)
tbucket.In = make(chan *types.Event)
tbucket.Mapkey = k
tbucket.Signal = make(chan bool, 1)
tbucket.First_ts = v.First_ts
tbucket.Last_ts = v.Last_ts
tbucket.Ovflw_ts = v.Ovflw_ts
tbucket.Total_count = v.Total_count
tbucket.First_ts = state[k].First_ts
tbucket.Last_ts = state[k].Last_ts
tbucket.Ovflw_ts = state[k].Ovflw_ts
tbucket.Total_count = state[k].Total_count
buckets.Bucket_map.Store(k, tbucket)
h.tomb.Go(func() error {
return LeakRoutine(tbucket)
Expand All @@ -545,7 +545,7 @@
}

if !found {
return fmt.Errorf("unable to find holder for bucket %s: %s", k, spew.Sdump(v))
return fmt.Errorf("unable to find holder for bucket %s: %s", k, spew.Sdump(state[k]))

Check warning on line 548 in pkg/leakybucket/manager_load.go

View check run for this annotation

Codecov / codecov/patch

pkg/leakybucket/manager_load.go#L548

Added line #L548 was not covered by tests
}
}

Expand Down
Loading