Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
17 changes: 8 additions & 9 deletions central/detection/lifecycle/manager_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,21 +110,20 @@ func (m *managerImpl) buildIndicatorFilter() {
return
}

var processesToRemove []string
processesToRemove := make([]string, 0, len(deploymentIDs))
walkFn := func() error {
deploymentIDSet := set.NewStringSet(deploymentIDs...)
processesToRemove = processesToRemove[:0]
return m.processesDataStore.WalkAll(ctx, func(pi *storage.ProcessIndicator) error {
if !deploymentIDSet.Contains(pi.GetDeploymentId()) {
// Don't remove as these processes will be removed by GC
// but don't add to the filter
return nil
}

// Only process indicators for existing deployments
fn := func(pi *storage.ProcessIndicator) error {
if !m.processFilter.Add(pi) {
processesToRemove = append(processesToRemove, pi.GetId())
}
return nil
})
}

query := search.NewQueryBuilder().AddExactMatches(search.DeploymentID, deploymentIDs...).ProtoQuery()
return m.processesDataStore.WalkByQuery(ctx, query, fn)
}
if err := pgutils.RetryIfPostgres(ctx, walkFn); err != nil {
utils.Should(errors.Wrap(err, "error building indicator filter"))
Expand Down
2 changes: 1 addition & 1 deletion central/pod/datastore/datastore_impl_real_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (s *PodDatastoreSuite) SetupTest() {

func (s *PodDatastoreSuite) getProcessIndicatorsFromDB() []*storage.ProcessIndicator {
indicatorsFromDB := []*storage.ProcessIndicator{}
err := s.indicatorDataStore.WalkAll(s.plopAndPiCtx,
err := s.indicatorDataStore.WalkByQuery(s.plopAndPiCtx, nil,
func(processIndicator *storage.ProcessIndicator) error {
indicatorsFromDB = append(indicatorsFromDB, processIndicator)
return nil
Expand Down
2 changes: 1 addition & 1 deletion central/processindicator/datastore/datastore.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type DataStore interface {
RemoveProcessIndicators(ctx context.Context, ids []string) error
PruneProcessIndicators(ctx context.Context, ids []string) (int, error)

WalkAll(ctx context.Context, fn func(pi *storage.ProcessIndicator) error) error
WalkByQuery(ctx context.Context, query *v1.Query, fn func(obj *storage.ProcessIndicator) error) error

// IterateOverProcessIndicatorsRiskView iterates over minimal fields from process indicator for risk evaluation
IterateOverProcessIndicatorsRiskView(ctx context.Context, q *v1.Query, fn func(*views.ProcessIndicatorRiskView) error) error
Expand Down
4 changes: 2 additions & 2 deletions central/processindicator/datastore/datastore_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,14 @@ func (ds *datastoreImpl) AddProcessIndicators(ctx context.Context, indicators ..
return nil
}

func (ds *datastoreImpl) WalkAll(ctx context.Context, fn func(pi *storage.ProcessIndicator) error) error {
func (ds *datastoreImpl) WalkByQuery(ctx context.Context, q *v1.Query, fn func(pi *storage.ProcessIndicator) error) error {
if ok, err := deploymentExtensionSAC.ReadAllowed(ctx); err != nil {
return err
} else if !ok {
return sac.ErrResourceAccessDenied
}

return ds.storage.Walk(ctx, fn)
return ds.storage.WalkByQuery(ctx, q, fn)
}

func (ds *datastoreImpl) RemoveProcessIndicators(ctx context.Context, ids []string) error {
Expand Down
12 changes: 6 additions & 6 deletions central/processindicator/datastore/mocks/datastore.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions central/processindicator/store/mocks/store.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions central/processindicator/store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ type Store interface {
DeleteMany(ctx context.Context, id []string) error

Walk(context.Context, func(pi *storage.ProcessIndicator) error) error
WalkByQuery(context.Context, *v1.Query, func(pi *storage.ProcessIndicator) error) error
DeleteByQuery(ctx context.Context, query *v1.Query) error
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func (suite *PLOPDataStoreTestSuite) getPlopsFromDB() []*storage.ProcessListenin

func (suite *PLOPDataStoreTestSuite) getProcessIndicatorsFromDB() []*storage.ProcessIndicator {
indicatorsFromDB := []*storage.ProcessIndicator{}
err := suite.indicatorDataStore.WalkAll(suite.hasWriteCtx,
err := suite.indicatorDataStore.WalkByQuery(suite.hasWriteCtx, nil,
func(processIndicator *storage.ProcessIndicator) error {
indicatorsFromDB = append(indicatorsFromDB, processIndicator)
return nil
Expand Down
Loading