Skip to content

Commit 7448ee5

Browse files
committed
chore: adjust some logs for the async-adapter
1 parent e144fee commit 7448ee5

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

cmd/harbor-scanner-sysdig-secure/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ func main() {
3737

3838
adapter := getAdapter()
3939
if viper.GetBool("async_mode") {
40+
log.Info("Async-Mode enabled")
4041
adapter = scanner.NewAsyncAdapter(ctx, adapter, log.StandardLogger(), scanner.DefaultAsyncAdapterRefreshRate)
4142
}
4243

pkg/scanner/async_adapter.go

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ type AsyncAdapter struct {
2323
requestsChan chan harbor.ScanRequestID // channel where new requests about reports will be published
2424
repliesChan chan *asyncReportReply // channel where replies about retrieval of reports will be published
2525
results map[harbor.ScanRequestID]*asyncReportReply
26-
stopChan chan struct{}
26+
stopChan chan struct{} // channel where stop signal will be published so that all the background tasks can stop running
2727
wrapped Adapter
2828
}
2929

@@ -88,11 +88,11 @@ func (a *AsyncAdapter) awaitReportAvailability(scanID harbor.ScanRequestID) {
8888
for {
8989
select {
9090
case <-a.stopChan:
91-
a.log.Debugf("stopping background task of '%s'", scanID)
91+
a.log.Debugf("Stopping async task of '%s'", scanID)
9292
ticker.Stop()
9393
return
9494
case <-ticker.C:
95-
a.log.Infof("checking status of report '%s'", scanID)
95+
a.log.Infof("Checking status of report '%s'", scanID)
9696
report, err := a.wrapped.GetVulnerabilityReport(scanID)
9797
if err != ErrVulnerabilityReportNotReady {
9898
ticker.Stop()
@@ -106,33 +106,32 @@ func (a *AsyncAdapter) awaitReportAvailability(scanID harbor.ScanRequestID) {
106106
func (a *AsyncAdapter) listen(ctx context.Context) {
107107

108108
go func(ctx context.Context) {
109-
a.log.Infof("start listening for updates")
109+
a.log.Infof("Start listening for async updates")
110110
for {
111-
a.log.Infof("listening for updates")
112111
select {
113112
case <-ctx.Done():
114-
a.log.Infof("stop listening for updates: sending signal to stop background tasks")
113+
a.log.Infof("Stop listening for updates: sending signal to stop background tasks")
115114
a.stopChan <- struct{}{}
116115
return
117116
case id := <-a.consumptionChan:
118-
a.log.Debugf("received consumption for report '%s', deleting it from cache", id)
117+
a.log.Debugf("Received consumption for report '%s', deleting it from cache", id)
119118
a.lock.Lock()
120119
delete(a.results, id)
121120
a.lock.Unlock()
122121
a.log.Debugf("report '%s' deleted from cache", id)
123122
case id := <-a.requestsChan:
124-
a.log.Debugf("received new request for report '%s', adding it to cache", id)
123+
a.log.Debugf("Received new request for report '%s', adding it to cache", id)
125124
a.lock.Lock()
126125
a.results[id] = nil
127126
a.lock.Unlock()
128-
a.log.Debugf("report '%s' added to cache", id)
127+
a.log.Debugf("Report '%s' added to cache", id)
129128
case reply := <-a.repliesChan:
130129
if reply != nil {
131-
a.log.Infof("report '%s' completed, updating cache", reply.scanID)
130+
a.log.Infof("Report '%s' completed, updating cache", reply.scanID)
132131
a.lock.Lock()
133132
a.results[reply.scanID] = reply
134133
a.lock.Unlock()
135-
a.log.Debugf("report '%s' updated in cache", reply.scanID)
134+
a.log.Debugf("Report '%s' updated in cache", reply.scanID)
136135
}
137136
}
138137
}

0 commit comments

Comments
 (0)