Skip to content

Commit

Permalink
Add scan status message if it was marked as error by cleanup job #2057 (
Browse files Browse the repository at this point in the history
  • Loading branch information
ramanan-ravi authored Apr 24, 2024
1 parent f4205e9 commit e04d1bc
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 17 deletions.
2 changes: 1 addition & 1 deletion deepfence_agent/plugins/YaraHunter
2 changes: 1 addition & 1 deletion deepfence_agent/plugins/compliance
2 changes: 1 addition & 1 deletion deepfence_bootstrapper/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ require (
github.com/deepfence/df-utils v0.0.0-00010101000000-000000000000
github.com/deepfence/golang_deepfence_sdk/client v0.0.0-00010101000000-000000000000
github.com/deepfence/golang_deepfence_sdk/utils v0.0.0-00010101000000-000000000000
github.com/deepfence/kubernetes-scanner/v2 v2.1.0
github.com/deepfence/kubernetes-scanner/v2 v2.2.0
github.com/minio/selfupdate v0.6.0
github.com/opencontainers/runtime-spec v1.1.0
github.com/rs/zerolog v1.31.0
Expand Down
4 changes: 2 additions & 2 deletions deepfence_bootstrapper/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
github.com/decred/dcrd/crypto/blake256 v1.0.1/go.mod h1:2OfgNZ5wDpcsFmHmCK5gZTPcCXqlm2ArzUIkw9czNJo=
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 h1:8UrgZ3GkP4i/CLijOJx79Yu+etlyjdBU4sfcs2WYQMs=
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0/go.mod h1:v57UDF4pDQJcEfFUCRop3lJL149eHGSe9Jvczhzjo/0=
github.com/deepfence/kubernetes-scanner/v2 v2.1.0 h1:pmdoDdHHnh78MSI8K/x7dP45VUMSO4uRvktPRTMamaU=
github.com/deepfence/kubernetes-scanner/v2 v2.1.0/go.mod h1:QkeSAu2KIwiREWL/S1gLzI2xWC5vwY1eB9GH8rAzzTw=
github.com/deepfence/kubernetes-scanner/v2 v2.2.0 h1:u3mqAmziRTeSJ7ypOoETZnIEw4S+a4D+nkROnu/ESY0=
github.com/deepfence/kubernetes-scanner/v2 v2.2.0/go.mod h1:P8ve7sQ26di52eU5EvG+h1ZTwNjrXeG4lAJ3BcbCdSw=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
github.com/docker/docker v0.7.3-0.20180827131323-0c5f8d2b9b23/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
Expand Down
4 changes: 4 additions & 0 deletions deepfence_utils/utils/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ const (
ScanStatusDeletePending = "DELETE_PENDING"
)

const (
ScanRetryFailedStatusMessage = "scan failed to complete, please check agent logs"
)

// Neo4j Node Labels
const (
NodeTypeCloudProvider = "CloudProvider"
Expand Down
28 changes: 16 additions & 12 deletions deepfence_worker/cronjobs/neo4j.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,13 +298,14 @@ func CleanUpDB(ctx context.Context, task *asynq.Task) error {
MATCH (n:`+string(ts)+`) -[:SCANNED]-> (r)
WHERE n.retries >= 3
WITH n, r LIMIT 10000
SET n.status = $new_status
SET n.status = $new_status, n.status_message = $new_status_message
WITH n, r
MATCH (r) WHERE r.`+ingestersUtil.LatestScanIDField[ts]+`=n.node_id
SET r.`+ingestersUtil.ScanStatusField[ts]+`=n.status`,
map[string]interface{}{
"time_ms": dbScanTimeout.Milliseconds(),
"new_status": utils.ScanStatusFailed,
"time_ms": dbScanTimeout.Milliseconds(),
"new_status": utils.ScanStatusFailed,
"new_status_message": utils.ScanRetryFailedStatusMessage,
}, txConfig); err != nil {
log.Error().Msgf("Error in Clean up DB task: %v", err)
return err
Expand All @@ -315,10 +316,11 @@ func CleanUpDB(ctx context.Context, task *asynq.Task) error {
MATCH (:AgentVersion) -[n:SCHEDULED]-> (:Node)
WHERE n.retries >= 3
WITH n LIMIT 10000
SET n.status = $new_status`,
SET n.status = $new_status, n.status_message = $new_status_message`,
map[string]interface{}{
"time_ms": dbUpgradeTimeout.Milliseconds(),
"new_status": utils.ScanStatusFailed,
"time_ms": dbUpgradeTimeout.Milliseconds(),
"new_status": utils.ScanStatusFailed,
"new_status_message": utils.ScanRetryFailedStatusMessage,
}, txConfig); err != nil {
log.Error().Msgf("Error in Clean up DB task: %v", err)
return err
Expand All @@ -328,10 +330,11 @@ func CleanUpDB(ctx context.Context, task *asynq.Task) error {
MATCH (n:AgentDiagnosticLogs)
WHERE n.retries >= 3
WITH n LIMIT 10000
SET n.status = $new_status`,
SET n.status = $new_status, n.status_message = $new_status_message`,
map[string]interface{}{
"time_ms": dbUpgradeTimeout.Milliseconds(),
"new_status": utils.ScanStatusFailed,
"time_ms": dbUpgradeTimeout.Milliseconds(),
"new_status": utils.ScanStatusFailed,
"new_status_message": utils.ScanRetryFailedStatusMessage,
}, txConfig); err != nil {
log.Error().Msgf("Error in Clean up DB task: %v", err)
return err
Expand All @@ -341,10 +344,11 @@ func CleanUpDB(ctx context.Context, task *asynq.Task) error {
MATCH (n:CloudScannerDiagnosticLogs)
WHERE n.retries >= 3
WITH n LIMIT 10000
SET n.status = $new_status`,
SET n.status = $new_status, n.status_message = $new_status_message`,
map[string]interface{}{
"time_ms": dbUpgradeTimeout.Milliseconds(),
"new_status": utils.ScanStatusFailed,
"time_ms": dbUpgradeTimeout.Milliseconds(),
"new_status": utils.ScanStatusFailed,
"new_status_message": utils.ScanRetryFailedStatusMessage,
}, txConfig); err != nil {
log.Error().Msgf("Error in Clean up DB task: %v", err)
return err
Expand Down

0 comments on commit e04d1bc

Please sign in to comment.