Skip to content

Commit 2572aec

Browse files
authored
improve vulnerability processing (#150)
* Optimize UpdateIssueLabels with incremental updates * Increase visibility timeout * Improve logging for error processing source * Remove ioutil
1 parent 371fc3f commit 2572aec

File tree

4 files changed

+15
-16
lines changed

4 files changed

+15
-16
lines changed

cmd/vulnerability-db-consumer/config.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Copyright 2020 Adevinta
55
package main
66

77
import (
8-
"io/ioutil"
8+
"io"
99
"os"
1010

1111
log "github.com/sirupsen/logrus"
@@ -39,8 +39,8 @@ type dbConfig struct {
3939

4040
type sqsConfig struct {
4141
NProcessors uint8 `toml:"number_of_processors"`
42-
WaitTime uint8 `toml:"wait_time"`
43-
Timeout uint8
42+
WaitTime int `toml:"wait_time"`
43+
Timeout int
4444
QueueARN string `toml:"queue_arn"`
4545
Endpoint string `toml:"endpoint"`
4646
}
@@ -73,7 +73,7 @@ func parseConfig(cfgFilePath string) (*config, error) {
7373
}
7474
defer cfgFile.Close()
7575

76-
cfgData, err := ioutil.ReadAll(cfgFile)
76+
cfgData, err := io.ReadAll(cfgFile)
7777

7878
var conf config
7979
if _, err := toml.Decode(string(cfgData[:]), &conf); err != nil {

config.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ name = "$PG_NAME"
1717
[sqs]
1818
number_of_processors = $SQS_NUMBER_OF_PROCESSORS
1919
wait_time = 20
20-
timeout = 30
20+
timeout = 600
2121
queue_arn = "$SQS_QUEUE_ARN"
2222
endpoint = "$AWS_SQS_ENDPOINT"
2323

pkg/processor/processor.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,11 @@ func (p *CheckProcessor) ProcessMessage(m string) error {
148148
l.Debugf("Processing source with %d source findings: %#v", len(sourceFindings), source)
149149
source, err = p.store.ProcessSourceExecution(source, sourceFindings)
150150
if err != nil {
151-
l.Errorf("Error while processing source: %#v", err)
152-
if !store.IsDuplicateErr(err) {
153-
return err
151+
if store.IsDuplicateErr(err) {
152+
l.Warnf("duplicated source: %#v", err)
153+
return nil
154154
}
155+
return err
155156
}
156157

157158
l.Debug("Sending open findings")

pkg/store/issues.go

+6-8
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,18 @@ func (db *psqlxStore) UpdateIssueLabels(issueID string, labels []string) error {
3737
return err
3838
}
3939

40-
_, err = tx.Exec("DELETE FROM issue_labels WHERE issue_id = $1", issueID)
40+
l := pq.Array(labels)
41+
_, err = tx.Exec("DELETE FROM issue_labels WHERE issue_id = $1 and label <> ANY($2::TEXT[])", issueID, l)
4142
if err != nil {
4243
tx.Rollback()
4344
return err
4445
}
4546

46-
for _, label := range labels {
47-
_, err := tx.Exec("INSERT INTO issue_labels (issue_id, label) VALUES ($1, $2)", issueID, label)
48-
if err != nil {
49-
tx.Rollback()
50-
return err
51-
}
47+
_, err = tx.Exec("INSERT INTO issue_labels SELECT $1, unnest($2::TEXT[]) ON CONFLICT DO NOTHING", issueID, l)
48+
if err != nil {
49+
tx.Rollback()
50+
return err
5251
}
53-
5452
return tx.Commit()
5553
}
5654

0 commit comments

Comments
 (0)