Skip to content

Commit

Permalink
feat: update module runtime endpoint in the schema
Browse files Browse the repository at this point in the history
  • Loading branch information
stuartwdouglas committed Dec 4, 2024
1 parent 8387b88 commit 4bcdf42
Show file tree
Hide file tree
Showing 18 changed files with 306 additions and 373 deletions.
18 changes: 3 additions & 15 deletions backend/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -535,18 +535,6 @@ func (s *Service) UpdateDeploy(ctx context.Context, req *connect.Request[ftlv1.U
return nil, fmt.Errorf("could not set deployment replicas: %w", err)
}
}
if req.Msg.Endpoint != nil {
err = s.dal.SetDeploymentEndpoint(ctx, deploymentKey, *req.Msg.Endpoint)
if err != nil {
if errors.Is(err, libdal.ErrNotFound) {
logger.Errorf(err, "Deployment not found: %s", deploymentKey)
return nil, connect.NewError(connect.CodeNotFound, errors.New("deployment not found"))
}
logger.Errorf(err, "Could not set deployment endpoint: %s", deploymentKey)
return nil, fmt.Errorf("could not set deployment endpoint: %w", err)
}
}

return connect.NewResponse(&ftlv1.UpdateDeployResponse{}), nil
}

Expand Down Expand Up @@ -1688,12 +1676,12 @@ func (s *Service) syncRoutesAndSchema(ctx context.Context) (ret time.Duration, e
// And we set its replicas to zero
// It may seem a bit odd to do this here but this is where we are actually updating the routing table
// Which is what makes as a deployment 'live' from a clients POV
if v.Schema.Runtime == nil {
if v.Schema.Runtime == nil || v.Schema.Runtime.Deployment == nil {
deploymentLogger.Debugf("Deployment %s has no runtime metadata", v.Key.String())
continue
}
targetEndpoint, ok := v.Endpoint.Get()
if !ok {
targetEndpoint := v.Schema.Runtime.Deployment.Endpoint
if targetEndpoint == "" {
deploymentLogger.Debugf("Failed to get updated endpoint for deployment %s", v.Key.String())
continue
}
Expand Down
17 changes: 0 additions & 17 deletions backend/controller/dal/dal.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,22 +392,6 @@ func (d *DAL) SetDeploymentReplicas(ctx context.Context, key model.DeploymentKey
return nil
}

// SetDeploymentEndpoint sets the deployment endpoint
func (d *DAL) SetDeploymentEndpoint(ctx context.Context, key model.DeploymentKey, endpoint string) (err error) {
// Start the transaction
tx, err := d.Begin(ctx)
if err != nil {
return libdal.TranslatePGError(err)
}
defer tx.CommitOrRollback(ctx, &err)

err = tx.db.SetDeploymentEndpoint(ctx, key, optional.Some(endpoint))
if err != nil {
return libdal.TranslatePGError(err)
}
return nil
}

var ErrReplaceDeploymentAlreadyActive = errors.New("deployment already active")

// ReplaceDeployment replaces an old deployment of a module with a new deployment.
Expand Down Expand Up @@ -530,7 +514,6 @@ func (d *DAL) GetActiveDeployments(ctx context.Context) ([]dalmodel.Deployment,
Replicas: optional.Some(int(in.Replicas)),
Schema: in.Deployment.Schema,
CreatedAt: in.Deployment.CreatedAt,
Endpoint: in.Deployment.Endpoint,
}
}), nil
}
Expand Down
1 change: 0 additions & 1 deletion backend/controller/dal/internal/sql/models.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/controller/dal/internal/sql/querier.go

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

8 changes: 1 addition & 7 deletions backend/controller/dal/internal/sql/queries.sql
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ FROM runners r
ORDER BY r.key;

-- name: GetActiveDeployments :many
SELECT sqlc.embed(d), m.name AS module_name, m.language, COUNT(r.id) AS replicas, d.endpoint
SELECT sqlc.embed(d), m.name AS module_name, m.language, COUNT(r.id) AS replicas
FROM deployments d
JOIN modules m ON d.module_id = m.id
LEFT JOIN runners r ON d.id = r.deployment_id
Expand Down Expand Up @@ -147,12 +147,6 @@ SET min_replicas = $2, last_activated_at = CASE WHEN min_replicas = 0 THEN (NOW(
WHERE key = sqlc.arg('key')::deployment_key
RETURNING 1;

-- name: SetDeploymentEndpoint :exec
UPDATE deployments
SET endpoint = $2
WHERE key = sqlc.arg('key')::deployment_key
RETURNING 1;

-- name: GetExistingDeploymentForModule :one
SELECT *
FROM deployments d
Expand Down
34 changes: 6 additions & 28 deletions backend/controller/dal/internal/sql/queries.sql.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/controller/dal/model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ type Deployment struct {
Schema *schema.Module
CreatedAt time.Time
Labels model.Labels
Endpoint optional.Option[string]
}

func (d Deployment) String() string { return d.Key.String() }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-- migrate:up

ALTER TABLE deployments DROP COLUMN endpoint;

-- migrate:down

Loading

0 comments on commit 4bcdf42

Please sign in to comment.