@@ -13,6 +13,7 @@ import (
1313 "github.com/stackrox/rox/central/sensor/service/pipeline/reconciliation"
1414 "github.com/stackrox/rox/generated/internalapi/central"
1515 "github.com/stackrox/rox/pkg/centralsensor"
16+ "github.com/stackrox/rox/pkg/features"
1617 "github.com/stackrox/rox/pkg/logging"
1718 "github.com/stackrox/rox/pkg/nodes/enricher"
1819)
@@ -56,7 +57,11 @@ func (p pipelineImpl) Match(msg *central.MsgFromSensor) bool {
5657 return msg .GetEvent ().GetIndexReport () != nil
5758}
5859
59- func (p pipelineImpl ) Run (ctx context.Context , clusterID string , msg * central.MsgFromSensor , _ common.MessageInjector ) error {
60+ func (p pipelineImpl ) Run (ctx context.Context , _ string , msg * central.MsgFromSensor , _ common.MessageInjector ) error {
61+ if ! features .ScannerV4 .Enabled () {
62+ // If Scanner V4 is disabled do not run this pipeline
63+ return nil
64+ }
6065 event := msg .GetEvent ()
6166 report := event .GetIndexReport ()
6267 if report == nil {
@@ -66,37 +71,36 @@ func (p pipelineImpl) Run(ctx context.Context, clusterID string, msg *central.Ms
6671 log .Errorf ("index report from node %s has unsupported action: %q" , event .GetNode ().GetName (), event .GetAction ())
6772 return nil
6873 }
69- log .Debugf ("received node index report with %d packages from %d content sets for node %s " ,
70- len (report .GetContents ().Packages ), len (report .GetContents ().Repositories ), event . GetId ( ))
71- cr : = report .CloneVT ()
74+ log .Debugf ("received node index report for node %s with %d packages from %d content sets" ,
75+ event . GetId (), len (report .GetContents ().Packages ), len (report .GetContents ().Repositories ))
76+ report = report .CloneVT ()
7277
73- // Read the node from the database, if not found we fail.
74- node , found , err := p .nodeDatastore .GetNode (ctx , event .GetId ())
78+ // Query storage for the node this report comes from
79+ nodeId := event .GetId ()
80+ node , found , err := p .nodeDatastore .GetNode (ctx , nodeId )
7581 if err != nil {
76- return errors .WithMessagef (err , "fetching node: %s" , event . GetId () )
82+ return errors .WithMessagef (err , "failed to fetch node %s from database " , nodeId )
7783 }
7884 if ! found {
79- return errors .WithMessagef (err , "node does not exist: %s " , event . GetId () )
85+ return errors .WithMessagef (err , "node %s not found in datastore " , nodeId )
8086 }
8187
82- // Send the Node and Index Report to Scanner for enrichment
83- err = p .enricher .EnrichNodeWithInventory (node , nil , cr )
88+ // Send the Node and Index Report to Scanner for enrichment. The result will be persisted in node.NodeScan
89+ err = p .enricher .EnrichNodeWithInventory (node , nil , report )
8490 if err != nil {
85- return errors .WithMessagef (err , "enriching node %s with index report" , event . GetId () )
91+ return errors .WithMessagef (err , "enriching node %s with index report" , nodeId )
8692 }
87- log .Infof ("Successfully enriched node %s with index report." , node .GetName ())
93+ log .Debugf ("Successfully enriched node %s with %s report - found %d components (id: %s)" ,
94+ node .GetName (), node .GetScan ().GetScannerVersion ().String (), len (node .GetScan ().GetComponents ()), nodeId )
8895
89- // TODO(ROX-26089): Update the whole node in the database with the new and previous information after conversion
90- /*
91- err = p.riskManager.CalculateRiskAndUpsertNode(node)
92- if err != nil {
93- log.Error(err)
94- return err
95- }
96- */
96+ // Update the whole node in the database with the new and previous information.
97+ err = p .riskManager .CalculateRiskAndUpsertNode (node )
98+ if err != nil {
99+ log .Error (err )
100+ return err
101+ }
97102
98103 return nil
99-
100104}
101105
102106func (p pipelineImpl ) Reconcile (_ context.Context , _ string , _ * reconciliation.StoreMap ) error {
0 commit comments