diff --git a/backend/controller/controller.go b/backend/controller/controller.go index 30edfe1fe6..6c9100d795 100644 --- a/backend/controller/controller.go +++ b/backend/controller/controller.go @@ -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) } @@ -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 } diff --git a/backend/controller/dal/dal.go b/backend/controller/dal/dal.go index b1586f3aec..f4623f3c5a 100644 --- a/backend/controller/dal/dal.go +++ b/backend/controller/dal/dal.go @@ -249,8 +249,8 @@ 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) } @@ -258,20 +258,16 @@ func (d *DAL) GetControllers(ctx context.Context, allControllers bool) ([]Contro 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)) } @@ -279,7 +275,7 @@ func (d *DAL) GetStatus( 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)) } @@ -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, @@ -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) } diff --git a/backend/controller/sql/querier.go b/backend/controller/sql/querier.go index eac52ac819..f212d3dae3 100644 --- a/backend/controller/sql/querier.go +++ b/backend/controller/sql/querier.go @@ -23,14 +23,14 @@ type Querier interface { DeregisterRunner(ctx context.Context, key model.RunnerKey) (int64, error) EndCronJob(ctx context.Context, nextExecution time.Time, key model.CronJobKey, startTime time.Time) (EndCronJobRow, error) ExpireRunnerReservations(ctx context.Context) (int64, error) + GetActiveControllers(ctx context.Context) ([]Controller, error) GetActiveDeploymentSchemas(ctx context.Context) ([]GetActiveDeploymentSchemasRow, error) GetActiveDeployments(ctx context.Context) ([]GetActiveDeploymentsRow, error) - GetActiveRunners(ctx context.Context, all bool) ([]GetActiveRunnersRow, error) - GetAllIngressRoutes(ctx context.Context, all bool) ([]GetAllIngressRoutesRow, error) + GetActiveIngressRoutes(ctx context.Context) ([]GetActiveIngressRoutesRow, error) + GetActiveRunners(ctx context.Context) ([]GetActiveRunnersRow, error) GetArtefactContentRange(ctx context.Context, start int32, count int32, iD int64) ([]byte, error) // Return the digests that exist in the database. GetArtefactDigests(ctx context.Context, digests [][]byte) ([]GetArtefactDigestsRow, error) - GetControllers(ctx context.Context, all bool) ([]Controller, error) GetCronJobs(ctx context.Context) ([]GetCronJobsRow, error) GetDeployment(ctx context.Context, key model.DeploymentKey) (GetDeploymentRow, error) // Get all artefacts matching the given digests. diff --git a/backend/controller/sql/queries.sql b/backend/controller/sql/queries.sql index 9d728deedd..7df0afcf08 100644 --- a/backend/controller/sql/queries.sql +++ b/backend/controller/sql/queries.sql @@ -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 @@ -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 @@ -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 diff --git a/backend/controller/sql/queries.sql.go b/backend/controller/sql/queries.sql.go index aad9cafe90..45285ce029 100644 --- a/backend/controller/sql/queries.sql.go +++ b/backend/controller/sql/queries.sql.go @@ -211,6 +211,40 @@ func (q *Queries) ExpireRunnerReservations(ctx context.Context) (int64, error) { return count, err } +const getActiveControllers = `-- name: GetActiveControllers :many +SELECT id, key, created, last_seen, state, endpoint +FROM controller c +WHERE c.state <> 'dead' +ORDER BY c.key +` + +func (q *Queries) GetActiveControllers(ctx context.Context) ([]Controller, error) { + rows, err := q.db.Query(ctx, getActiveControllers) + if err != nil { + return nil, err + } + defer rows.Close() + var items []Controller + for rows.Next() { + var i Controller + if err := rows.Scan( + &i.ID, + &i.Key, + &i.Created, + &i.LastSeen, + &i.State, + &i.Endpoint, + ); err != nil { + return nil, err + } + items = append(items, i) + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + const getActiveDeploymentSchemas = `-- name: GetActiveDeploymentSchemas :many SELECT key, schema FROM deployments WHERE min_replicas > 0 ` @@ -288,6 +322,47 @@ func (q *Queries) GetActiveDeployments(ctx context.Context) ([]GetActiveDeployme return items, nil } +const getActiveIngressRoutes = `-- 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 d.min_replicas > 0 +` + +type GetActiveIngressRoutesRow struct { + DeploymentKey model.DeploymentKey + Module string + Verb string + Method string + Path string +} + +func (q *Queries) GetActiveIngressRoutes(ctx context.Context) ([]GetActiveIngressRoutesRow, error) { + rows, err := q.db.Query(ctx, getActiveIngressRoutes) + if err != nil { + return nil, err + } + defer rows.Close() + var items []GetActiveIngressRoutesRow + for rows.Next() { + var i GetActiveIngressRoutesRow + if err := rows.Scan( + &i.DeploymentKey, + &i.Module, + &i.Verb, + &i.Method, + &i.Path, + ); err != nil { + return nil, err + } + items = append(items, i) + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + const getActiveRunners = `-- name: GetActiveRunners :many SELECT DISTINCT ON (r.key) r.key AS runner_key, r.endpoint, @@ -300,8 +375,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 $1::bool = true - OR r.state <> 'dead' +WHERE r.state <> 'dead' ORDER BY r.key ` @@ -315,8 +389,8 @@ type GetActiveRunnersRow struct { DeploymentKey optional.Option[string] } -func (q *Queries) GetActiveRunners(ctx context.Context, all bool) ([]GetActiveRunnersRow, error) { - rows, err := q.db.Query(ctx, getActiveRunners, all) +func (q *Queries) GetActiveRunners(ctx context.Context) ([]GetActiveRunnersRow, error) { + rows, err := q.db.Query(ctx, getActiveRunners) if err != nil { return nil, err } @@ -343,48 +417,6 @@ func (q *Queries) GetActiveRunners(ctx context.Context, all bool) ([]GetActiveRu return items, nil } -const getAllIngressRoutes = `-- name: GetAllIngressRoutes :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 $1::bool = true - OR d.min_replicas > 0 -` - -type GetAllIngressRoutesRow struct { - DeploymentKey model.DeploymentKey - Module string - Verb string - Method string - Path string -} - -func (q *Queries) GetAllIngressRoutes(ctx context.Context, all bool) ([]GetAllIngressRoutesRow, error) { - rows, err := q.db.Query(ctx, getAllIngressRoutes, all) - if err != nil { - return nil, err - } - defer rows.Close() - var items []GetAllIngressRoutesRow - for rows.Next() { - var i GetAllIngressRoutesRow - if err := rows.Scan( - &i.DeploymentKey, - &i.Module, - &i.Verb, - &i.Method, - &i.Path, - ); err != nil { - return nil, err - } - items = append(items, i) - } - if err := rows.Err(); err != nil { - return nil, err - } - return items, nil -} - const getArtefactContentRange = `-- name: GetArtefactContentRange :one SELECT SUBSTRING(a.content FROM $1 FOR $2)::BYTEA AS content FROM artefacts a @@ -430,41 +462,6 @@ func (q *Queries) GetArtefactDigests(ctx context.Context, digests [][]byte) ([]G return items, nil } -const getControllers = `-- name: GetControllers :many -SELECT id, key, created, last_seen, state, endpoint -FROM controller c -WHERE $1::bool = true - OR c.state <> 'dead' -ORDER BY c.key -` - -func (q *Queries) GetControllers(ctx context.Context, all bool) ([]Controller, error) { - rows, err := q.db.Query(ctx, getControllers, all) - if err != nil { - return nil, err - } - defer rows.Close() - var items []Controller - for rows.Next() { - var i Controller - if err := rows.Scan( - &i.ID, - &i.Key, - &i.Created, - &i.LastSeen, - &i.State, - &i.Endpoint, - ); err != nil { - return nil, err - } - items = append(items, i) - } - if err := rows.Err(); err != nil { - return nil, err - } - return items, nil -} - const getCronJobs = `-- name: GetCronJobs :many SELECT j.key as key, d.key as deployment_key, j.module_name as module, j.verb, j.schedule, j.start_time, j.next_execution, j.state FROM cron_jobs j diff --git a/backend/protos/xyz/block/ftl/v1/ftl.proto b/backend/protos/xyz/block/ftl/v1/ftl.proto index 1187a9b59b..b9923c9778 100644 --- a/backend/protos/xyz/block/ftl/v1/ftl.proto +++ b/backend/protos/xyz/block/ftl/v1/ftl.proto @@ -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; @@ -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;