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

feat: run plugin setup concurrently #151

Merged
merged 2 commits into from
Feb 25, 2022
Merged
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
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ require (
github.com/pkg/browser v0.0.0-20210904010418-6d279e18f982
github.com/spf13/cobra v1.2.1
github.com/spf13/viper v1.8.1
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
google.golang.org/genproto v0.0.0-20210602131652-f16073e35f0c
google.golang.org/grpc v1.38.0
google.golang.org/protobuf v1.26.0
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@ golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a/go.mod h1:RxMgew5VJxzue5/jJ
golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
Expand Down
1 change: 1 addition & 0 deletions pkg/plugin/system/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ go_library(
"//pkg/plugin/system/bep",
"@com_github_spf13_cobra//:cobra",
"@in_gopkg_yaml_v2//:yaml_v2",
"@org_golang_x_sync//errgroup",
],
)

Expand Down
38 changes: 21 additions & 17 deletions pkg/plugin/system/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import (
"reflect"
"time"

yaml "gopkg.in/yaml.v2"

"github.com/spf13/cobra"
"golang.org/x/sync/errgroup"
jbedard marked this conversation as resolved.
Show resolved Hide resolved
yaml "gopkg.in/yaml.v2"

rootFlags "aspect.build/cli/pkg/aspect/root/flags"
"aspect.build/cli/pkg/aspecterrors"
Expand Down Expand Up @@ -71,28 +71,32 @@ func (ps *pluginSystem) Configure(streams ioutils.Streams) error {
return fmt.Errorf("failed to configure plugin system: %w", err)
}

g := new(errgroup.Group)

for _, p := range aspectplugins {
// TODO(f0rmiga): make this loop concurrent so that all plugins are
// configured faster.
p := p

aspectplugin, err := ps.clientFactory.New(p, streams)
if err != nil {
return fmt.Errorf("failed to configure plugin system: %w", err)
}
g.Go(func() error {
aspectplugin, err := ps.clientFactory.New(p, streams)
if err != nil {
return fmt.Errorf("failed to configure plugin system: %w", err)
}

propertiesBytes, err := yaml.Marshal(p.Properties)
if err != nil {
return fmt.Errorf("failed to configure plugin system: %w", err)
}
propertiesBytes, err := yaml.Marshal(p.Properties)
if err != nil {
return fmt.Errorf("failed to configure plugin system: %w", err)
}

if err := aspectplugin.Setup(propertiesBytes); err != nil {
return fmt.Errorf("failed to setup plugin: %w", err)
}
if err := aspectplugin.Setup(propertiesBytes); err != nil {
return fmt.Errorf("failed to configure plugin system: %w", err)
jbedard marked this conversation as resolved.
Show resolved Hide resolved
}

ps.addPlugin(aspectplugin)
ps.addPlugin(aspectplugin)
return nil
})
}

return nil
return g.Wait()
}

func (ps *pluginSystem) addPlugin(plugin *client.PluginInstance) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/plugin/system/system_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ func TestConfigure(t *testing.T) {

err := ps.Configure(streams)

g.Expect(err).To(MatchError("failed to setup plugin: setup error"))
g.Expect(err).To(MatchError("failed to configure plugin system: setup error"))
})

t.Run("marshaled properties are passed to plugin.Setup", func(t *testing.T) {
Expand Down