Skip to content

Commit

Permalink
#1443 Fix for empty region displayed from kube hosts
Browse files Browse the repository at this point in the history
  • Loading branch information
saurabh2253 committed Sep 29, 2023
1 parent a555605 commit ad720f8
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions deepfence_worker/cronjobs/neo4j.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,13 @@ func CleanUpDB(ctx context.Context, task *asynq.Task) error {

// Delete old with no data
if _, err = session.Run(`
MATCH (n:Node)
MATCH (n:Node) <-[:HOSTS]- (cr:CloudRegion)
WHERE n.active = false
AND NOT exists((n) <-[:SCANNED]-())
OR n.updated_at < TIMESTAMP()-$old_time_ms
WITH n LIMIT 10000
WITH n, cr LIMIT 10000
SET cr.cr_shown = CASE WHEN n.kubernetes_cluster_id= "" or n.kubernetes_cluster_id is null THEN cr.cr_shown - 1 ELSE cr.cr_shown END,

This comment has been minimized.

Copy link
@noboruma

noboruma Sep 30, 2023

Collaborator

It's a bit unfortunate because cr_shown can be read as cloudregion_shown or cloudresource_shown. It is actually the later.
Let's rename cr_shown with nodes_shown or resource_shown - because now we are adding nodes count to the mix

cr.active = cr.cr_shown <> 0
DETACH DELETE n`,
map[string]interface{}{
"time_ms": dbReportCleanUpTimeout.Milliseconds(),
Expand Down Expand Up @@ -422,6 +424,15 @@ func LinkCloudResources(ctx context.Context, task *asynq.Task) error {
return err
}

if _, err = session.Run(`
MATCH (n:Node) <-[:HOSTS]- (cr:CloudRegion)
WHERE n.active = true and (n.kubernetes_cluster_id= "" or n.kubernetes_cluster_id is null)
WITH cr, count(n) as cnt
SET cr.cr_shown = COALESCE(cr.cr_shown, 0) + cnt`,
map[string]interface{}{}, txConfig); err != nil {
return err
}

if _, err = session.Run(`
MATCH (cr:CloudRegion)
WHERE NOT cr.cr_shown IS NULL
Expand Down

0 comments on commit ad720f8

Please sign in to comment.