Skip to content

Commit

Permalink
chore: use a single sumtype for all schema modifying events
Browse files Browse the repository at this point in the history
  • Loading branch information
jvmakine committed Jan 24, 2025
1 parent 74f685f commit ca242ea
Show file tree
Hide file tree
Showing 40 changed files with 3,544 additions and 3,157 deletions.
16 changes: 8 additions & 8 deletions backend/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,17 +358,17 @@ func (s *Service) setDeploymentReplicas(ctx context.Context, key key.Deployment,
return fmt.Errorf("could not get deployment: %w", err)
}

err = s.schemaState.State.Publish(ctx, &schemaservice.DeploymentReplicasUpdatedEvent{Key: key, Replicas: minReplicas})
err = s.schemaState.State.Publish(ctx, &schema.DeploymentReplicasUpdatedEvent{Key: key, Replicas: minReplicas})
if err != nil {
return fmt.Errorf("could not update deployment replicas: %w", err)
}
if minReplicas == 0 {
err = s.schemaState.State.Publish(ctx, &schemaservice.DeploymentDeactivatedEvent{Key: key, ModuleRemoved: true})
err = s.schemaState.State.Publish(ctx, &schema.DeploymentDeactivatedEvent{Key: key, ModuleRemoved: true})
if err != nil {
return fmt.Errorf("could not deactivate deployment: %w", err)
}
} else if deployment.GetRuntime().GetScaling().GetMinReplicas() == 0 {
err = s.schemaState.State.Publish(ctx, &schemaservice.DeploymentActivatedEvent{Key: key, ActivatedAt: time.Now(), MinReplicas: minReplicas})
err = s.schemaState.State.Publish(ctx, &schema.DeploymentActivatedEvent{Key: key, ActivatedAt: time.Now(), MinReplicas: minReplicas})
if err != nil {
return fmt.Errorf("could not activate deployment: %w", err)
}
Expand Down Expand Up @@ -400,7 +400,7 @@ func (s *Service) ReplaceDeploy(ctx context.Context, c *connect.Request[ftlv1.Re
return nil, connect.NewError(connect.CodeNotFound, errors.New("deployment not found"))
}
minReplicas := int(c.Msg.MinReplicas)
err = s.schemaState.State.Publish(ctx, &schemaservice.DeploymentActivatedEvent{Key: newDeploymentKey, ActivatedAt: time.Now(), MinReplicas: minReplicas})
err = s.schemaState.State.Publish(ctx, &schema.DeploymentActivatedEvent{Key: newDeploymentKey, ActivatedAt: time.Now(), MinReplicas: minReplicas})
if err != nil {
return nil, fmt.Errorf("replace deployment failed to activate: %w", err)
}
Expand All @@ -421,18 +421,18 @@ func (s *Service) ReplaceDeploy(ctx context.Context, c *connect.Request[ftlv1.Re
if oldKey.String() == newDeploymentKey.String() {
return nil, fmt.Errorf("replace deployment failed: deployment already exists from %v to %v", oldKey, newDeploymentKey)
}
err = s.schemaState.State.Publish(ctx, &schemaservice.DeploymentReplicasUpdatedEvent{Key: newDeploymentKey, Replicas: minReplicas})
err = s.schemaState.State.Publish(ctx, &schema.DeploymentReplicasUpdatedEvent{Key: newDeploymentKey, Replicas: minReplicas})
if err != nil {
return nil, fmt.Errorf("replace deployment failed to set new deployment replicas from %v to %v: %w", oldKey, newDeploymentKey, err)
}
err = s.schemaState.State.Publish(ctx, &schemaservice.DeploymentDeactivatedEvent{Key: oldKey})
err = s.schemaState.State.Publish(ctx, &schema.DeploymentDeactivatedEvent{Key: oldKey})
if err != nil {
return nil, fmt.Errorf("replace deployment failed to deactivate old deployment %v: %w", oldKey, err)
}
replacedDeploymentKey = optional.Some(oldKey)
} else {
// Set the desired replicas for the new deployment
err = s.schemaState.State.Publish(ctx, &schemaservice.DeploymentReplicasUpdatedEvent{Key: newDeploymentKey, Replicas: minReplicas})
err = s.schemaState.State.Publish(ctx, &schema.DeploymentReplicasUpdatedEvent{Key: newDeploymentKey, Replicas: minReplicas})
if err != nil {
return nil, fmt.Errorf("replace deployment failed to set replicas for %v: %w", newDeploymentKey, err)
}
Expand Down Expand Up @@ -935,7 +935,7 @@ func (s *Service) CreateDeployment(ctx context.Context, req *connect.Request[ftl

dkey := key.NewDeploymentKey(module.Name)
module.ModRuntime().ModDeployment().CreatedAt = time.Now()
err = s.schemaState.State.Publish(ctx, &schemaservice.DeploymentCreatedEvent{
err = s.schemaState.State.Publish(ctx, &schema.DeploymentCreatedEvent{
Key: dkey,
Schema: module,
})
Expand Down
306 changes: 75 additions & 231 deletions backend/protos/xyz/block/ftl/provisioner/v1beta1/plugin.pb.go

Large diffs are not rendered by default.

11 changes: 1 addition & 10 deletions backend/protos/xyz/block/ftl/provisioner/v1beta1/plugin.proto
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,6 @@ message StatusRequest {
xyz.block.ftl.schema.v1.Module desired_module = 2;
}

message ProvisioningEvent {
oneof value {
xyz.block.ftl.schema.v1.ModuleRuntimeEvent module_runtime_event = 1;
xyz.block.ftl.schema.v1.DatabaseRuntimeEvent database_runtime_event = 2;
xyz.block.ftl.schema.v1.TopicRuntimeEvent topic_runtime_event = 3;
xyz.block.ftl.schema.v1.VerbRuntimeEvent verb_runtime_event = 4;
}
}

message StatusResponse {
message ProvisioningRunning {}

Expand All @@ -48,7 +39,7 @@ message StatusResponse {
}

message ProvisioningSuccess {
repeated ProvisioningEvent events = 1;
repeated xyz.block.ftl.schema.v1.Event events = 1;
}

oneof status {
Expand Down
110 changes: 50 additions & 60 deletions backend/protos/xyz/block/ftl/v1/schemaservice.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion backend/protos/xyz/block/ftl/v1/schemaservice.proto
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ message PullSchemaResponse {
}

message UpdateDeploymentRuntimeRequest {

Check failure on line 38 in backend/protos/xyz/block/ftl/v1/schemaservice.proto

View workflow job for this annotation

GitHub Actions / Proto Breaking Change Check

Previously present field "1" with name "deployment" on message "UpdateDeploymentRuntimeRequest" was deleted.
string deployment = 1;
ftl.schema.v1.ModuleRuntimeEvent event = 2;
}

Expand Down
10 changes: 6 additions & 4 deletions backend/provisioner/controller_provisioner.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"connectrpc.com/connect"

"github.com/alecthomas/types/optional"
ftlv1 "github.com/block/ftl/backend/protos/xyz/block/ftl/v1"
"github.com/block/ftl/backend/protos/xyz/block/ftl/v1/ftlv1connect"
"github.com/block/ftl/common/schema"
Expand All @@ -16,7 +17,7 @@ import (
// NewControllerProvisioner creates a new provisioner that uses the FTL controller to provision modules
func NewControllerProvisioner(client ftlv1connect.ControllerServiceClient) *InMemProvisioner {
return NewEmbeddedProvisioner(map[schema.ResourceType]InMemResourceProvisionerFn{
schema.ResourceTypeModule: func(ctx context.Context, moduleName string, res schema.Provisioned) (*RuntimeEvent, error) {
schema.ResourceTypeModule: func(ctx context.Context, moduleName string, res schema.Provisioned) (schema.Event, error) {
logger := log.FromContext(ctx)
logger.Debugf("Provisioning module: %s", moduleName)

Expand All @@ -36,10 +37,11 @@ func NewControllerProvisioner(client ftlv1connect.ControllerServiceClient) *InMe
return nil, fmt.Errorf("failed to parse deployment key: %w", err)
}

return &RuntimeEvent{
Module: &schema.ModuleRuntimeDeployment{
return &schema.ModuleRuntimeEvent{
Module: module.Name,
Deployment: optional.Some(schema.ModuleRuntimeDeployment{
DeploymentKey: deploymentKey,
},
}),
}, nil
},
})
Expand Down
Loading

0 comments on commit ca242ea

Please sign in to comment.