Skip to content

Commit

Permalink
✨ use ephemeral runtimes for discovered assets (#792)
Browse files Browse the repository at this point in the history
* ✨ use ephemeral runtimes for discovered assets

We were already instantiating new runtimes for every asset that was
discovered. However, until the introduction of ephemeral runtimes, these
had the disadvantage that any runtime that was shut down would also shut
down the plug instance, which is shared.

In this new paradigm, we introduce explicitly ephemeral runtimes, which
are not shared. They have their own plugin instance that can safely be
shut down without impacting other providers.

For more details see: mondoohq/cnquery#2050

Signed-off-by: Dominik Richter <[email protected]>

* ✨ add the v8 asset sync compat from snquery

Signed-off-by: Dominik Richter <[email protected]>

* update cnquery

Signed-off-by: Ivan Milchev <[email protected]>

---------

Signed-off-by: Dominik Richter <[email protected]>
Signed-off-by: Ivan Milchev <[email protected]>
Co-authored-by: Ivan Milchev <[email protected]>
  • Loading branch information
arlimus and imilchev authored Oct 3, 2023
1 parent 7a6b20c commit bd4d3c9
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ require (
github.com/spf13/pflag v1.0.6-0.20201009195203-85dd5c8bc61c
github.com/spf13/viper v1.16.0
github.com/stretchr/testify v1.8.4
go.mondoo.com/cnquery v0.0.0-20231002111758-82a0179e7dbd
go.mondoo.com/cnquery v0.0.0-20231003111545-2bdc01cb42e5
go.mondoo.com/ranger-rpc v0.5.1
go.opentelemetry.io/otel v1.19.0
golang.org/x/sync v0.3.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -923,8 +923,8 @@ gitlab.com/bosi/decorder v0.4.1 h1:VdsdfxhstabyhZovHafFw+9eJ6eU0d2CkFNJcZz/NU4=
gitlab.com/bosi/decorder v0.4.1/go.mod h1:jecSqWUew6Yle1pCr2eLWTensJMmsxHsBwt+PVbkAqA=
go-simpler.org/assert v0.6.0 h1:QxSrXa4oRuo/1eHMXSBFHKvJIpWABayzKldqZyugG7E=
go-simpler.org/assert v0.6.0/go.mod h1:74Eqh5eI6vCK6Y5l3PI8ZYFXG4Sa+tkr70OIPJAUr28=
go.mondoo.com/cnquery v0.0.0-20231002111758-82a0179e7dbd h1:61ziiW1w0vR+004KFqgzp5JG8QlsS5NMnU4FkH2bjOk=
go.mondoo.com/cnquery v0.0.0-20231002111758-82a0179e7dbd/go.mod h1:CyLGmRezek/8PswuVkmSLLScZqpMbACwFqL21eGeyYU=
go.mondoo.com/cnquery v0.0.0-20231003111545-2bdc01cb42e5 h1:BIsAK2L4e09WoDArcGhe3h7uT2rCZISxqFXG4FdygVA=
go.mondoo.com/cnquery v0.0.0-20231003111545-2bdc01cb42e5/go.mod h1:CyLGmRezek/8PswuVkmSLLScZqpMbACwFqL21eGeyYU=
go.mondoo.com/ranger-rpc v0.5.1 h1:OaVQntDJWDRgbc9nXBP4wOCR9h9Bij8LgHHs86IguGk=
go.mondoo.com/ranger-rpc v0.5.1/go.mod h1:3YKcqFrlPgaB4FZ4EoLgdmRtwMQdO7RoAkZYFn+F1eY=
go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=
Expand Down
5 changes: 3 additions & 2 deletions policy/scan/local_scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ func (s *LocalScanner) distributeJob(job *Job, ctx context.Context, upstream *up
for i := range assetCandidates {
candidate := assetCandidates[i]

runtime, err := providers.Coordinator.RuntimeFor(candidate.asset, candidate.runtime)
runtime, err := providers.Coordinator.EphemeralRuntimeFor(candidate.asset)
if err != nil {
return nil, false, err
}
Expand Down Expand Up @@ -320,6 +320,7 @@ func (s *LocalScanner) distributeJob(job *Job, ctx context.Context, upstream *up
return nil, false, err
}

inventory.DeprecatedV8CompatAssets(justAssets)
resp, err := services.SynchronizeAssets(ctx, &policy.SynchronizeAssetsReq{
SpaceMrn: client.SpaceMrn,
List: justAssets,
Expand Down Expand Up @@ -419,7 +420,7 @@ func (s *LocalScanner) distributeJob(job *Job, ctx context.Context, upstream *up
runtime: runtime,
})

// we don't need the runtime anymore, so close it
// shut down all ephemeral runtimes
runtime.Close()
}
finished = true
Expand Down

0 comments on commit bd4d3c9

Please sign in to comment.