Skip to content

Commit

Permalink
refactor(cmd/bpfsnitch): use LRU cache for banned cgroup IDs
Browse files Browse the repository at this point in the history
  • Loading branch information
nullswan committed Sep 12, 2024
1 parent 0f80fd3 commit 2f2a7a8
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions cmd/bpfsnitch/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,15 @@ func run() error {
return fmt.Errorf("failed to create sha resolver: %w", err)
}

// TODO: LRU Cache
bannedCgroupIds := make(map[uint64]struct{})

bannedCgroupIds := lru.New[uint64, struct{}](1000)

Check failure on line 86 in cmd/bpfsnitch/main.go

View workflow job for this annotation

GitHub Actions / lint

var-naming: var bannedCgroupIds should be bannedCgroupIDs (revive)
pidToShaLRU := lru.New[uint64, string](1000)
for {
select {
case <-ctx.Done():
log.Info("Context done, exiting")
return nil
case event := <-syscallEventChan:
if _, ok := bannedCgroupIds[event.CgroupId]; ok {
if _, ok := bannedCgroupIds.Get(event.CgroupId); ok {
continue
}

Expand All @@ -116,7 +114,7 @@ func run() error {

contentStr := string(content)
if !strings.Contains(contentStr, "k8s.io") {
bannedCgroupIds[event.CgroupId] = struct{}{}
bannedCgroupIds.Put(event.CgroupId, struct{}{})
continue
}
sha = contentStr[strings.LastIndex(contentStr, "/")+1:]
Expand Down

0 comments on commit 2f2a7a8

Please sign in to comment.