Skip to content

Commit

Permalink
fix: log provisioners when they are registered (#3210)
Browse files Browse the repository at this point in the history
  • Loading branch information
jvmakine authored Oct 28, 2024
1 parent 8c6f740 commit 3fc312a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
4 changes: 2 additions & 2 deletions backend/provisioner/deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ func TestDeployment_Progress(t *testing.T) {

t.Run("progresses each provisioner in order", func(t *testing.T) {
registry := provisioner.ProvisionerRegistry{}
registry.Register(&MockProvisioner{Token: "foo"}, provisioner.ResourceTypePostgres)
registry.Register(&MockProvisioner{Token: "bar"}, provisioner.ResourceTypeMysql)
registry.Register("mock", &MockProvisioner{Token: "foo"}, provisioner.ResourceTypePostgres)
registry.Register("mock", &MockProvisioner{Token: "bar"}, provisioner.ResourceTypeMysql)

graph := &provisioner.ResourceGraph{}
graph.AddNode(&proto.Resource{ResourceId: "a", Resource: &proto.Resource_Mysql{}})
Expand Down
28 changes: 20 additions & 8 deletions backend/provisioner/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"sort"
"strings"

"github.com/google/go-cmp/cmp"
"google.golang.org/protobuf/testing/protocmp"
Expand Down Expand Up @@ -47,6 +48,14 @@ type ProvisionerBinding struct {
Types []ResourceType
}

func (p ProvisionerBinding) String() string {
types := []string{}
for _, t := range p.Types {
types = append(types, string(t))
}
return fmt.Sprintf("%s (%s)", p.ID, strings.Join(types, ","))
}

// ProvisionerRegistry contains all known resource handlers in the order they should be executed
type ProvisionerRegistry struct {
Default *ProvisionerBinding
Expand All @@ -59,13 +68,12 @@ func (reg *ProvisionerRegistry) listProvisioners() []*ProvisionerBinding {
if reg.Default != nil {
result = append(result, reg.Default)
}
for _, p := range reg.Provisioners {
result = append(result, p)
}
result = append(result, reg.Provisioners...)
return result
}

func registryFromConfig(ctx context.Context, cfg *provisionerPluginConfig, controller ftlv1connect.ControllerServiceClient) (*ProvisionerRegistry, error) {
logger := log.FromContext(ctx)
var def provisionerconnect.ProvisionerPluginServiceClient
if cfg.Default != "" {
d, err := provisionerIDToProvisioner(ctx, cfg.Default, controller)
Expand All @@ -83,7 +91,8 @@ func registryFromConfig(ctx context.Context, cfg *provisionerPluginConfig, contr
if err != nil {
return nil, err
}
result.Register(provisioner, plugin.Resources...)
binding := result.Register(plugin.ID, provisioner, plugin.Resources...)
logger.Debugf("Registered provisioner %s", binding)
}
return result, nil
}
Expand Down Expand Up @@ -112,11 +121,14 @@ func provisionerIDToProvisioner(ctx context.Context, id string, controller ftlv1
}

// Register to the registry, to be executed after all the previously added handlers
func (reg *ProvisionerRegistry) Register(handler provisionerconnect.ProvisionerPluginServiceClient, types ...ResourceType) {
reg.Provisioners = append(reg.Provisioners, &ProvisionerBinding{
func (reg *ProvisionerRegistry) Register(id string, handler provisionerconnect.ProvisionerPluginServiceClient, types ...ResourceType) *ProvisionerBinding {
binding := &ProvisionerBinding{
Provisioner: handler,
Types: types,
})
ID: id,
}
reg.Provisioners = append(reg.Provisioners, binding)
return binding
}

// CreateDeployment to take the system to the desired state
Expand All @@ -133,7 +145,7 @@ func (reg *ProvisionerRegistry) CreateDeployment(ctx context.Context, module str
existing := existingByHandler[binding.Provisioner]

if !resourcesEqual(desired, existing) {
logger.Debugf("Adding task for module %s with provisioner %s", module, binding.ID)
logger.Debugf("Adding task for module %s: %s", module, binding)
result = append(result, &Task{
module: module,
handler: binding.Provisioner,
Expand Down

0 comments on commit 3fc312a

Please sign in to comment.