From dc76af8dd68847f53a0d0f95b0e5ea96bec0271a Mon Sep 17 00:00:00 2001 From: Christian Zunker Date: Tue, 17 Oct 2023 15:01:21 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=B9=20Change=20handling=20of=20multi?= =?UTF-8?q?=20asset=20errors?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #1848 Signed-off-by: Christian Zunker --- explorer/scan/local_scanner.go | 16 +++++++--------- providers/assets.go | 13 +++++++------ 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/explorer/scan/local_scanner.go b/explorer/scan/local_scanner.go index aa97dfbba2..39a8a05bce 100644 --- a/explorer/scan/local_scanner.go +++ b/explorer/scan/local_scanner.go @@ -187,7 +187,8 @@ func (s *LocalScanner) distributeJob(job *Job, ctx context.Context, upstream *up asset := assetList[i] resolvedAsset, err := im.ResolveAsset(asset) if err != nil { - return nil, false, err + log.Error().Err(err).Str("asset", asset.Name).Msg("unable to resolve asset") + continue } runtime, err := providers.Coordinator.RuntimeFor(asset, providers.DefaultRuntime()) @@ -202,7 +203,7 @@ func (s *LocalScanner) distributeJob(job *Job, ctx context.Context, upstream *up Asset: resolvedAsset, Upstream: upstream, }); err != nil { - log.Error().Err(err).Msg("unable to connect to asset") + log.Error().Err(err).Str("asset", asset.Name).Msg("unable to connect to asset") continue } @@ -215,18 +216,15 @@ func (s *LocalScanner) distributeJob(job *Job, ctx context.Context, upstream *up return nil, false, err } for i := range processedAssets { + if processedAssets[i].State == inventory.State_STATE_ERROR { + // we couldn't connect to the asset or something else happened, so skip it for further steps + continue + } assetCandidates = append(assetCandidates, &assetWithRuntime{ asset: processedAssets[i], runtime: runtime, }) } - // TODO: we want to keep better track of errors, since there may be - // multiple assets coming in. It's annoying to abort the scan if we get one - // error at this stage. - - // we grab the asset from the connection, because it contains all the - // detected metadata (and IDs) - // assets = append(assets, runtime.Provider.Connection.Asset) } // for each asset candidate, we initialize a new runtime and connect to it. diff --git a/providers/assets.go b/providers/assets.go index 19763efa18..b345ad4c7a 100644 --- a/providers/assets.go +++ b/providers/assets.go @@ -23,9 +23,7 @@ func ProcessAssetCandidates(runtime *Runtime, connectRes *pp.ConnectRes, upstrea } log.Debug().Msgf("resolved %d assets", len(assetCandidates)) - if err := detectAssets(runtime, assetCandidates, upstreamConfig); err != nil { - return nil, err - } + detectAssets(runtime, assetCandidates, upstreamConfig) if platformID != "" { res, err := filterAssetByPlatformID(assetCandidates, platformID) @@ -39,7 +37,7 @@ func ProcessAssetCandidates(runtime *Runtime, connectRes *pp.ConnectRes, upstrea } // detectAssets connects to all assets that do not have a platform ID yet -func detectAssets(runtime *Runtime, assetCandidates []*inventory.Asset, upstreamConfig *upstream.UpstreamConfig) error { +func detectAssets(runtime *Runtime, assetCandidates []*inventory.Asset, upstreamConfig *upstream.UpstreamConfig) { for i := range assetCandidates { asset := assetCandidates[i] // If the assets have platform IDs, then we have already connected to them via the @@ -50,7 +48,9 @@ func detectAssets(runtime *Runtime, assetCandidates []*inventory.Asset, upstream // Make sure the provider for the asset is present if err := runtime.DetectProvider(asset); err != nil { - return err + log.Error().Err(err).Str("asset", asset.Name).Msg("could not detect provider for asset") + asset.State = inventory.State_STATE_ERROR + continue } err := runtime.Connect(&pp.ConnectReq{ @@ -59,12 +59,13 @@ func detectAssets(runtime *Runtime, assetCandidates []*inventory.Asset, upstream Upstream: upstreamConfig, }) if err != nil { + log.Error().Err(err).Str("asset", asset.Name).Msg("could not connect to asset") + asset.State = inventory.State_STATE_ERROR continue } // Use the updated asset assetCandidates[i] = runtime.Provider.Connection.Asset } - return nil } func filterAssetByPlatformID(assetList []*inventory.Asset, selectionID string) (*inventory.Asset, error) {