Skip to content

Commit

Permalink
GetStatus() should always return just the active controllers/runners/…
Browse files Browse the repository at this point in the history
…ingress paths (#1282)

Fixes issue #1171

Generated file changes produced by running `./bin/sqlc generate`

Manually tested by running `ftl status` and `ftl serve`, the two
commands that use `GetStatus()` via `StatusRequest`:

1. In tab 1, ran `ftl dev ./examples/go`. Confirmed everything started
as expected.
2. Opened a new tab 2, ran `ftl status`. Confirmed everything got
returned.
3. Went back to tab 1, Ctrl+C.
4. Went back to tab 2 and ran `ftl status` again. Confirmed got `ftl:
error: unavailable: dial tcp 127.0.0.1:8892: connect: connection
refused`.
5. Went back to tab 1 and ran `ftl serve`. Confirmed serving executed as
expected.
6. Went back to tab 2 and ran `ftl status` again. Confirmed everything
got returned again.
  • Loading branch information
deniseli authored Apr 17, 2024
1 parent 35242c7 commit cff05fe
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 115 deletions.
4 changes: 2 additions & 2 deletions backend/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ func (s *Service) ProcessList(ctx context.Context, req *connect.Request[ftlv1.Pr
}

func (s *Service) Status(ctx context.Context, req *connect.Request[ftlv1.StatusRequest]) (*connect.Response[ftlv1.StatusResponse], error) {
status, err := s.dal.GetStatus(ctx, req.Msg.AllControllers, req.Msg.AllRunners, req.Msg.AllIngressRoutes)
status, err := s.dal.GetStatus(ctx)
if err != nil {
return nil, fmt.Errorf("could not get status: %w", err)
}
Expand Down Expand Up @@ -1061,7 +1061,7 @@ func (s *Service) heartbeatController(ctx context.Context) (time.Duration, error
}

func (s *Service) updateControllersList(ctx context.Context) (time.Duration, error) {
controllers, err := s.dal.GetControllers(ctx, false)
controllers, err := s.dal.GetActiveControllers(ctx)
if err != nil {
return 0, err
}
Expand Down
20 changes: 8 additions & 12 deletions backend/controller/dal/dal.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,37 +249,33 @@ type DAL struct {
// RouteChanges is a Topic that receives changes to the routing table.
}

func (d *DAL) GetControllers(ctx context.Context, allControllers bool) ([]Controller, error) {
controllers, err := d.db.GetControllers(ctx, allControllers)
func (d *DAL) GetActiveControllers(ctx context.Context) ([]Controller, error) {
controllers, err := d.db.GetActiveControllers(ctx)
if err != nil {
return nil, translatePGError(err)
}
return slices.Map(controllers, func(in sql.Controller) Controller {
return Controller{
Key: in.Key,
Endpoint: in.Endpoint,
State: ControllerState(in.State),
}
}), nil
}

func (d *DAL) GetStatus(
ctx context.Context,
allControllers, allRunners, allIngressRoutes bool,
) (Status, error) {
controllers, err := d.GetControllers(ctx, allControllers)
func (d *DAL) GetStatus(ctx context.Context) (Status, error) {
controllers, err := d.GetActiveControllers(ctx)
if err != nil {
return Status{}, fmt.Errorf("could not get control planes: %w", translatePGError(err))
}
runners, err := d.db.GetActiveRunners(ctx, allRunners)
runners, err := d.db.GetActiveRunners(ctx)
if err != nil {
return Status{}, fmt.Errorf("could not get active runners: %w", translatePGError(err))
}
deployments, err := d.db.GetActiveDeployments(ctx)
if err != nil {
return Status{}, fmt.Errorf("could not get active deployments: %w", translatePGError(err))
}
ingressRoutes, err := d.db.GetAllIngressRoutes(ctx, allIngressRoutes)
ingressRoutes, err := d.db.GetActiveIngressRoutes(ctx)
if err != nil {
return Status{}, fmt.Errorf("could not get ingress routes: %w", translatePGError(err))
}
Expand Down Expand Up @@ -334,7 +330,7 @@ func (d *DAL) GetStatus(
Controllers: controllers,
Deployments: statusDeployments,
Runners: domainRunners,
IngressRoutes: slices.Map(ingressRoutes, func(in sql.GetAllIngressRoutesRow) IngressRouteEntry {
IngressRoutes: slices.Map(ingressRoutes, func(in sql.GetActiveIngressRoutesRow) IngressRouteEntry {
return IngressRouteEntry{
Deployment: in.DeploymentKey,
Module: in.Module,
Expand Down Expand Up @@ -1095,7 +1091,7 @@ func (d *DAL) InsertCallEvent(ctx context.Context, call *CallEvent) error {
}

func (d *DAL) GetActiveRunners(ctx context.Context) ([]Runner, error) {
rows, err := d.db.GetActiveRunners(ctx, false)
rows, err := d.db.GetActiveRunners(ctx)
if err != nil {
return nil, translatePGError(err)
}
Expand Down
6 changes: 3 additions & 3 deletions backend/controller/sql/querier.go

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

13 changes: 5 additions & 8 deletions backend/controller/sql/queries.sql
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,7 @@ SELECT DISTINCT ON (r.key) r.key AS runner_key
THEN d.key END, NULL) AS deployment_key
FROM runners r
LEFT JOIN deployments d on d.id = r.deployment_id
WHERE sqlc.arg('all')::bool = true
OR r.state <> 'dead'
WHERE r.state <> 'dead'
ORDER BY r.key;

-- name: GetActiveDeployments :many
Expand Down Expand Up @@ -427,11 +426,10 @@ WITH matches AS (
SELECT COUNT(*)
FROM matches;

-- name: GetControllers :many
-- name: GetActiveControllers :many
SELECT *
FROM controller c
WHERE sqlc.arg('all')::bool = true
OR c.state <> 'dead'
WHERE c.state <> 'dead'
ORDER BY c.key;

-- name: CreateIngressRoute :exec
Expand All @@ -447,12 +445,11 @@ FROM ingress_routes ir
WHERE r.state = 'assigned'
AND ir.method = $1;

-- name: GetAllIngressRoutes :many
-- name: GetActiveIngressRoutes :many
SELECT d.key AS deployment_key, ir.module, ir.verb, ir.method, ir.path
FROM ingress_routes ir
INNER JOIN deployments d ON ir.deployment_id = d.id
WHERE sqlc.arg('all')::bool = true
OR d.min_replicas > 0;
WHERE d.min_replicas > 0;


-- name: InsertEvent :exec
Expand Down
159 changes: 78 additions & 81 deletions backend/controller/sql/queries.sql.go

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

9 changes: 0 additions & 9 deletions backend/protos/xyz/block/ftl/v1/ftl.proto
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,6 @@ message GetDeploymentResponse {
repeated DeploymentArtefact artefacts = 2;
}

enum ControllerState {
CONTROLLER_LIVE = 0;
CONTROLLER_DEAD = 1;
}

enum RunnerState {
// The Runner is waiting for a deployment.
RUNNER_IDLE = 0;
Expand Down Expand Up @@ -184,15 +179,11 @@ message StreamDeploymentLogsRequest {
message StreamDeploymentLogsResponse {}

message StatusRequest {
bool all_runners = 1;
bool all_controllers = 2;
bool all_ingress_routes = 3;
}
message StatusResponse {
message Controller {
string key = 1;
string endpoint = 2;
ControllerState state = 4;
}
repeated Controller controllers = 1;

Expand Down

0 comments on commit cff05fe

Please sign in to comment.