Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🧹 Change handling of multi asset errors #2272

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
🧹 Change handling of multi asset errors
Fixes #1848

Signed-off-by: Christian Zunker <christian@mondoo.com>
  • Loading branch information
czunker committed Oct 17, 2023
commit dc76af8dd68847f53a0d0f95b0e5ea96bec0271a
16 changes: 7 additions & 9 deletions explorer/scan/local_scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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
}

Expand All @@ -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.
Expand Down
13 changes: 7 additions & 6 deletions providers/assets.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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{
Expand All @@ -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) {
Expand Down
Loading