From 038f1440466b6290a1036e655a3539aa3c3988ed Mon Sep 17 00:00:00 2001 From: Denise Li Date: Tue, 16 Apr 2024 17:50:39 -0400 Subject: [PATCH] Revert "feat: Remove runners and ingress from dal GetStatus (#1280)" This reverts commit b54627d228400fee572071ab6d20eabdcddb4b63. --- backend/controller/controller.go | 35 +++++++++++++- backend/controller/dal/dal.go | 56 +++++++++++++++++++++-- backend/protos/xyz/block/ftl/v1/ftl.proto | 26 +++++++++-- 3 files changed, 107 insertions(+), 10 deletions(-) diff --git a/backend/controller/controller.go b/backend/controller/controller.go index 3ca6c6ff64..30edfe1fe6 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) + status, err := s.dal.GetStatus(ctx, req.Msg.AllControllers, req.Msg.AllRunners, req.Msg.AllIngressRoutes) if err != nil { return nil, fmt.Errorf("could not get status: %w", err) } @@ -310,6 +310,28 @@ func (s *Service) Status(ctx context.Context, req *connect.Request[ftlv1.StatusR }) s.routesMu.RUnlock() replicas := map[string]int32{} + protoRunners, err := slices.MapErr(status.Runners, func(r dal.Runner) (*ftlv1.StatusResponse_Runner, error) { + var deployment *string + if d, ok := r.Deployment.Get(); ok { + asString := d.String() + deployment = &asString + replicas[asString]++ + } + labels, err := structpb.NewStruct(r.Labels) + if err != nil { + return nil, fmt.Errorf("could not marshal attributes for runner %s: %w", r.Key, err) + } + return &ftlv1.StatusResponse_Runner{ + Key: r.Key.String(), + Endpoint: r.Endpoint, + State: r.State.ToProto(), + Deployment: deployment, + Labels: labels, + }, nil + }) + if err != nil { + return nil, err + } deployments, err := slices.MapErr(status.Deployments, func(d dal.Deployment) (*ftlv1.StatusResponse_Deployment, error) { labels, err := structpb.NewStruct(d.Labels) if err != nil { @@ -336,8 +358,17 @@ func (s *Service) Status(ctx context.Context, req *connect.Request[ftlv1.StatusR State: c.State.ToProto(), } }), + Runners: protoRunners, Deployments: deployments, - Routes: routes, + IngressRoutes: slices.Map(status.IngressRoutes, func(r dal.IngressRouteEntry) *ftlv1.StatusResponse_IngressRoute { + return &ftlv1.StatusResponse_IngressRoute{ + DeploymentKey: r.Deployment.String(), + Verb: &schemapb.Ref{Module: r.Module, Name: r.Verb}, + Method: r.Method, + Path: r.Path, + } + }), + Routes: routes, } return connect.NewResponse(resp), nil } diff --git a/backend/controller/dal/dal.go b/backend/controller/dal/dal.go index be44ba1261..b1586f3aec 100644 --- a/backend/controller/dal/dal.go +++ b/backend/controller/dal/dal.go @@ -191,9 +191,11 @@ type Controller struct { } type Status struct { - Controllers []Controller - Deployments []Deployment - Routes []Route + Controllers []Controller + Runners []Runner + Deployments []Deployment + IngressRoutes []IngressRouteEntry + Routes []Route } // A Reservation of a Runner. @@ -261,15 +263,26 @@ func (d *DAL) GetControllers(ctx context.Context, allControllers bool) ([]Contro }), nil } -func (d *DAL) GetStatus(ctx context.Context, allControllers bool) (Status, error) { +func (d *DAL) GetStatus( + ctx context.Context, + allControllers, allRunners, allIngressRoutes bool, +) (Status, error) { controllers, err := d.GetControllers(ctx, allControllers) if err != nil { return Status{}, fmt.Errorf("could not get control planes: %w", translatePGError(err)) } + runners, err := d.db.GetActiveRunners(ctx, allRunners) + 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) + if err != nil { + return Status{}, fmt.Errorf("could not get ingress routes: %w", translatePGError(err)) + } routes, err := d.db.GetRoutingTable(ctx, nil) if err != nil { return Status{}, fmt.Errorf("could not get routing table: %w", translatePGError(err)) @@ -292,9 +305,44 @@ func (d *DAL) GetStatus(ctx context.Context, allControllers bool) (Status, error if err != nil { return Status{}, err } + domainRunners, err := slices.MapErr(runners, func(in sql.GetActiveRunnersRow) (Runner, error) { + var deployment optional.Option[model.DeploymentKey] + if keyStr, ok := in.DeploymentKey.Get(); ok { + key, err := model.ParseDeploymentKey(keyStr) + if err != nil { + return Runner{}, fmt.Errorf("invalid deployment key %q: %w", keyStr, err) + } + deployment = optional.Some(key) + } + attrs := model.Labels{} + if err := json.Unmarshal(in.Labels, &attrs); err != nil { + return Runner{}, fmt.Errorf("invalid attributes JSON for runner %s: %w", in.RunnerKey, err) + } + + return Runner{ + Key: in.RunnerKey, + Endpoint: in.Endpoint, + State: RunnerState(in.State), + Deployment: deployment, + Labels: attrs, + }, nil + }) + if err != nil { + return Status{}, err + } return Status{ Controllers: controllers, Deployments: statusDeployments, + Runners: domainRunners, + IngressRoutes: slices.Map(ingressRoutes, func(in sql.GetAllIngressRoutesRow) IngressRouteEntry { + return IngressRouteEntry{ + Deployment: in.DeploymentKey, + Module: in.Module, + Verb: in.Verb, + Method: in.Method, + Path: in.Path, + } + }), Routes: slices.Map(routes, func(row sql.GetRoutingTableRow) Route { return Route{ Module: row.ModuleName.MustGet(), diff --git a/backend/protos/xyz/block/ftl/v1/ftl.proto b/backend/protos/xyz/block/ftl/v1/ftl.proto index e5e8daed80..1187a9b59b 100644 --- a/backend/protos/xyz/block/ftl/v1/ftl.proto +++ b/backend/protos/xyz/block/ftl/v1/ftl.proto @@ -184,9 +184,9 @@ message StreamDeploymentLogsRequest { message StreamDeploymentLogsResponse {} message StatusRequest { + bool all_runners = 1; bool all_controllers = 2; - - reserved 1, 3; + bool all_ingress_routes = 3; } message StatusResponse { message Controller { @@ -196,6 +196,16 @@ message StatusResponse { } repeated Controller controllers = 1; + message Runner { + string key = 1; + repeated string languages = 2; + string endpoint = 3; + RunnerState state = 4; + optional string deployment = 5; + google.protobuf.Struct labels = 6; + } + repeated Runner runners = 2; + message Deployment { string key = 1; string language = 2; @@ -207,6 +217,16 @@ message StatusResponse { } repeated Deployment deployments = 3; + message IngressRoute { + string deployment_key = 1; + schema.Ref verb = 5; + string method = 3; + string path = 4; + + reserved 2; + } + repeated IngressRoute ingress_routes = 4; + message Route { string module = 1; string runner = 2; @@ -214,8 +234,6 @@ message StatusResponse { string endpoint = 4; } repeated Route routes = 5; - - reserved 2, 4; } message ProcessListRequest {}