Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
f17fe43
Refactor `Stopper` API
msugakov Nov 29, 2022
d09c9fc
Add tests for `Stopper`
msugakov Nov 30, 2022
237be30
Refresh code that's already using Stopper to the new API
msugakov Nov 29, 2022
07ad2f0
Migrate `Compliance` command handler from stopC/stoppedC to `Stopper`
msugakov Nov 29, 2022
4afdef5
Migrate `AdmCtrlMsgForwarder` to use `Stopper` instead of a signal
msugakov Nov 29, 2022
fe7670c
Migrate `CentralCommunication` to `Stopper`
msugakov Nov 29, 2022
1e200ff
Add a note that SensorComponent's Stop `error` parameter is unused
msugakov Nov 29, 2022
a3f16c9
Migrate `CentralReciever` to use `Stopper`
msugakov Nov 29, 2022
7ffb274
Migrate `CentralSender` to `Stopper`
msugakov Nov 29, 2022
69941fb
Migrate `Enforcer` to `Stopper`
msugakov Nov 30, 2022
0a04b88
Migrate `NodeInventoryHandler` tests to use `Stopper`
msugakov Nov 29, 2022
591525e
Migrate `NodeInventoryHandler` to use `Stopper`
msugakov Nov 29, 2022
82bf205
Migrate `auditlog` `Reader` to `Stopper`
msugakov Nov 30, 2022
b014aaf
Migrate `CVEUnsuppressLoop` to `Stopper`
msugakov Nov 30, 2022
a4b295d
Migrate admission-control `Manager` to `Stopper`
msugakov Nov 30, 2022
1957bd6
Migrate reports `Scheduler` to `Stopper`
msugakov Nov 30, 2022
2a6ed0f
Migrate `Prunning` to `Stopper`
msugakov Nov 30, 2022
972ced0
Migrate processindicator `Datastore` to `Stopper`
msugakov Nov 30, 2022
e2971c0
Migrate vulnerabilityrequest `Manager` to `Stopper`
msugakov Dec 1, 2022
46adb80
Make admission control manager start without error
msugakov Dec 21, 2022
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
18 changes: 9 additions & 9 deletions central/cve/suppress/reprocessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ func newLoopWithDuration(tickerDuration time.Duration, cveStores ...vulnsStore)
cveStores: cveStores,
cveSuppressTickerDuration: tickerDuration,

stopChan: concurrency.NewSignal(),
stopped: concurrency.NewSignal(),
stopper: concurrency.NewStopper(),
}
}

Expand All @@ -79,8 +78,7 @@ type cveUnsuppressLoopImpl struct {

cveStores []vulnsStore

stopChan concurrency.Signal
stopped concurrency.Signal
stopper concurrency.Stopper
}

// Start starts the CVE unsuppress loop.
Expand All @@ -91,13 +89,15 @@ func (l *cveUnsuppressLoopImpl) Start() {

// Stop stops the CVE unsuppress loop.
func (l *cveUnsuppressLoopImpl) Stop() {
l.stopChan.Signal()
l.stopped.Wait()
l.stopper.Client().Stop()
_ = l.stopper.Client().Stopped().Wait()
}

func (l *cveUnsuppressLoopImpl) unsuppressCVEsWithExpiredSuppressState() {
if l.stopped.IsDone() {
select {
case <-l.stopper.Flow().StopRequested():
return
default:
}

totalUnsuppressedCVEs := 0
Expand Down Expand Up @@ -142,13 +142,13 @@ func getCVEsWithExpiredSuppressState(cveStore vulnsStore) ([]string, error) {
}

func (l *cveUnsuppressLoopImpl) loop() {
defer l.stopped.Signal()
defer l.stopper.Flow().ReportStopped()
defer l.cveSuppressTicker.Stop()

go l.unsuppressCVEsWithExpiredSuppressState()
for {
select {
case <-l.stopChan.Done():
case <-l.stopper.Flow().StopRequested():
return
case <-l.cveSuppressTicker.C:
l.unsuppressCVEsWithExpiredSuppressState()
Expand Down
5 changes: 2 additions & 3 deletions central/processindicator/datastore/datastore.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type DataStore interface {
WalkAll(ctx context.Context, fn func(pi *storage.ProcessIndicator) error) error

// Stop signals all goroutines associated with this object to terminate.
Stop() bool
Stop()
// Wait waits until all goroutines associated with this object have terminated, or cancelWhen gets triggered.
// A return value of false indicates that cancelWhen was triggered.
Wait(cancelWhen concurrency.Waitable) bool
Expand All @@ -50,8 +50,7 @@ func New(store store.Store, indexer index.Indexer, searcher search.Searcher, pru
searcher: searcher,
prunerFactory: prunerFactory,
prunedArgsLengthCache: make(map[processindicator.ProcessWithContainerInfo]int),
stopSig: concurrency.NewSignal(),
stoppedSig: concurrency.NewSignal(),
stopper: concurrency.NewStopper(),
}
ctx := sac.WithAllAccess(context.Background())
if err := d.buildIndex(ctx); err != nil {
Expand Down
14 changes: 7 additions & 7 deletions central/processindicator/datastore/datastore_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type datastoreImpl struct {
prunerFactory pruner.Factory
prunedArgsLengthCache map[processindicator.ProcessWithContainerInfo]int

stopSig, stoppedSig concurrency.Signal
stopper concurrency.Stopper
}

func checkReadAccess(ctx context.Context, indicator *storage.ProcessIndicator) (bool, error) {
Expand Down Expand Up @@ -170,19 +170,19 @@ func (ds *datastoreImpl) RemoveProcessIndicatorsByPod(ctx context.Context, id st
}

func (ds *datastoreImpl) prunePeriodically(ctx context.Context) {
defer ds.stoppedSig.Signal()
defer ds.stopper.Flow().ReportStopped()

if ds.prunerFactory == nil {
return
}

t := time.NewTicker(ds.prunerFactory.Period())
defer t.Stop()
for !ds.stopSig.IsDone() {
for {
select {
case <-t.C:
ds.prune(ctx)
case <-ds.stopSig.Done():
case <-ds.stopper.Flow().StopRequested():
return
}
}
Expand Down Expand Up @@ -248,12 +248,12 @@ func (ds *datastoreImpl) prune(ctx context.Context) {
}
}

func (ds *datastoreImpl) Stop() bool {
return ds.stopSig.Signal()
func (ds *datastoreImpl) Stop() {
ds.stopper.Client().Stop()
}

func (ds *datastoreImpl) Wait(cancelWhen concurrency.Waitable) bool {
return concurrency.WaitInContext(&ds.stoppedSig, cancelWhen)
return concurrency.WaitInContext(ds.stopper.Client().Stopped(), cancelWhen)
}

func (ds *datastoreImpl) fullReindex(ctx context.Context) error {
Expand Down
6 changes: 2 additions & 4 deletions central/processindicator/datastore/mocks/datastore.go

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

15 changes: 7 additions & 8 deletions central/pruning/pruning.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,7 @@ func newGarbageCollector(alerts alertDatastore.DataStore,
k8sRoles: k8sRoles,
k8sRoleBindings: k8sRoleBindings,
logimbueStore: logimbueStore,
stopSig: concurrency.NewSignal(),
stoppedSig: concurrency.NewSignal(),
stopper: concurrency.NewStopper(),
}
}

Expand All @@ -120,8 +119,7 @@ type garbageCollectorImpl struct {
k8sRoles k8sRoleDataStore.DataStore
k8sRoleBindings roleBindingDataStore.DataStore
logimbueStore logimbueDataStore.Store
stopSig concurrency.Signal
stoppedSig concurrency.Signal
stopper concurrency.Stopper
}

func (g *garbageCollectorImpl) Start() {
Expand Down Expand Up @@ -159,6 +157,8 @@ func (g *garbageCollectorImpl) pruneBasedOnConfig() {
}

func (g *garbageCollectorImpl) runGC() {
defer g.stopper.Flow().ReportStopped()

lastClusterPruneTime = time.Now().Add(-24 * time.Hour)
lastLogImbuePruneTime = time.Now().Add(-24 * time.Hour)
g.pruneBasedOnConfig()
Expand All @@ -168,8 +168,7 @@ func (g *garbageCollectorImpl) runGC() {
select {
case <-t.C:
g.pruneBasedOnConfig()
case <-g.stopSig.Done():
g.stoppedSig.Signal()
case <-g.stopper.Flow().StopRequested():
return
}
}
Expand Down Expand Up @@ -876,6 +875,6 @@ func (g *garbageCollectorImpl) pruneLogImbues() {
}

func (g *garbageCollectorImpl) Stop() {
g.stopSig.Signal()
<-g.stoppedSig.Done()
g.stopper.Client().Stop()
_ = g.stopper.Client().Stopped().Wait()
}
16 changes: 7 additions & 9 deletions central/reports/scheduler/schedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,7 @@ type scheduler struct {

reportsToRun chan *ReportRequest

stoppedSig concurrency.Signal
stopped concurrency.Signal
stopper concurrency.Stopper

Schema *graphql.Schema
}
Expand Down Expand Up @@ -178,8 +177,7 @@ func New(reportConfigDS reportConfigDS.DataStore, notifierDS notifierDataStore.D
reportsToRun: make(chan *ReportRequest, 100),
Schema: ourSchema,

stoppedSig: concurrency.NewSignal(),
stopped: concurrency.NewSignal(),
stopper: concurrency.NewStopper(),
}
return s
}
Expand Down Expand Up @@ -230,10 +228,10 @@ func (s *scheduler) SubmitReport(reportRequest *ReportRequest) {
}

func (s *scheduler) runReports() {
defer s.stopped.Signal()
for !s.stoppedSig.IsDone() {
defer s.stopper.Flow().ReportStopped()
for {
select {
case <-s.stoppedSig.Done():
case <-s.stopper.Flow().StopRequested():
return
case req := <-s.reportsToRun:
log.Infof("Executing report '%s' at %v", req.ReportConfig.GetName(), time.Now().Format(time.RFC822))
Expand Down Expand Up @@ -416,6 +414,6 @@ func (s *scheduler) Start() {
}

func (s *scheduler) Stop() {
s.stoppedSig.Signal()
s.stopped.Wait()
s.stopper.Client().Stop()
_ = s.stopper.Client().Stopped().Wait()
}
15 changes: 7 additions & 8 deletions central/vulnerabilityrequest/manager/requestmgr/manager_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ type managerImpl struct {
reObserveTimedDeferralsTickerDuration time.Duration
reObserveWhenFixedDeferralsTickerDuration time.Duration

stopSig concurrency.Signal
stopped concurrency.Signal
stopper concurrency.Stopper
}

func (m *managerImpl) Start() {
Expand All @@ -70,8 +69,8 @@ func (m *managerImpl) Start() {
}

func (m *managerImpl) Stop() {
m.stopSig.Signal()
m.stopped.Wait()
m.stopper.Client().Stop()
_ = m.stopper.Client().Stopped().Wait()
}

func (m *managerImpl) Create(ctx context.Context, req *storage.VulnerabilityRequest) error {
Expand Down Expand Up @@ -372,7 +371,7 @@ func (m *managerImpl) getExpiredDeferrals() ([]*storage.VulnerabilityRequest, er
}

func (m *managerImpl) reObserveExpiredDeferrals() {
if m.stopped.IsDone() {
if m.stopper.Client().Stopped().IsDone() {
return
}

Expand Down Expand Up @@ -438,7 +437,7 @@ func (m *managerImpl) getFixableDeferrals() ([]*storage.VulnerabilityRequest, er
}

func (m *managerImpl) reObserveFixableDeferrals() {
if m.stopped.IsDone() {
if m.stopper.Client().Stopped().IsDone() {
return
}

Expand All @@ -459,7 +458,7 @@ func (m *managerImpl) reObserveFixableDeferrals() {
}

func (m *managerImpl) runExpiredDeferralsProcessor() {
defer m.stopped.Signal()
defer m.stopper.Flow().ReportStopped()
reObserveTimedDeferralsTicker := time.NewTicker(m.reObserveTimedDeferralsTickerDuration)
defer reObserveTimedDeferralsTicker.Stop()
reObserveWhenFixedDeferralsTicker := time.NewTicker(m.reObserveWhenFixedDeferralsTickerDuration)
Expand All @@ -471,7 +470,7 @@ func (m *managerImpl) runExpiredDeferralsProcessor() {

for {
select {
case <-m.stopSig.Done():
case <-m.stopper.Flow().StopRequested():
return
case <-reObserveTimedDeferralsTicker.C:
go m.reObserveExpiredDeferrals()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,7 @@ func (s *VulnRequestManagerTestSuite) SetupTest() {
activeReqCache: s.activeReqCache,
reObserveTimedDeferralsTickerDuration: expiryLoopDurationForTest,
reObserveWhenFixedDeferralsTickerDuration: expiryLoopDurationForTest,
stopSig: concurrency.NewSignal(),
stopped: concurrency.NewSignal(),
stopper: concurrency.NewStopper(),
}
}

Expand Down
3 changes: 1 addition & 2 deletions central/vulnerabilityrequest/manager/requestmgr/singleton.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ func New(

reObserveTimedDeferralsTickerDuration: env.VulnDeferralTimedReObserveInterval.DurationSetting(),
reObserveWhenFixedDeferralsTickerDuration: env.VulnDeferralFixableReObserveInterval.DurationSetting(),
stopSig: concurrency.NewSignal(),
stopped: concurrency.NewSignal(),
stopper: concurrency.NewStopper(),
}
}
6 changes: 3 additions & 3 deletions compliance/collection/auditlog/auditlog.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ type Reader interface {
// StartReader will start the audit log reader process which will continuously read and send events until stopped.
// Returns true if the reader can be started (log exists and can be read). Log file missing is not considered an error.
StartReader(ctx context.Context) (bool, error)
// StopReader will stop the reader if it's started. Will return false if it was already stopped.
StopReader() bool
Copy link
Copy Markdown
Contributor Author

@msugakov msugakov Nov 30, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was nothing that looks at the returned value of StopReader().

// StopReader will stop the reader if it's started.
StopReader()
}

// NewReader returns a new instance of Reader
func NewReader(client sensor.ComplianceService_CommunicateClient, nodeName string, clusterID string, startState *storage.AuditLogFileState) Reader {
return &auditLogReaderImpl{
logPath: defaultLogPath,
stopC: concurrency.NewSignal(),
stopper: concurrency.NewStopper(),
sender: newAuditLogSender(client, nodeName, clusterID),
startState: startState,
}
Expand Down
Loading