Skip to content

Commit

Permalink
Revert "feat: Remove runners and ingress from dal GetStatus (#1280)"
Browse files Browse the repository at this point in the history
This reverts commit b54627d.
  • Loading branch information
deniseli authored Apr 16, 2024
1 parent 67c6b7e commit 038f144
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 10 deletions.
35 changes: 33 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)
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)
}
Expand All @@ -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 {
Expand All @@ -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
}
Expand Down
56 changes: 52 additions & 4 deletions backend/controller/dal/dal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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))
Expand All @@ -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(),
Expand Down
26 changes: 22 additions & 4 deletions backend/protos/xyz/block/ftl/v1/ftl.proto
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,9 @@ message StreamDeploymentLogsRequest {
message StreamDeploymentLogsResponse {}

message StatusRequest {

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

View workflow job for this annotation

GitHub Actions / Proto Breaking Change Check

Previously present reserved range "[1]" on message "StatusRequest" was deleted.

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

View workflow job for this annotation

GitHub Actions / Proto Breaking Change Check

Previously present reserved range "[3]" on message "StatusRequest" was deleted.
bool all_runners = 1;
bool all_controllers = 2;

reserved 1, 3;
bool all_ingress_routes = 3;
}
message StatusResponse {

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

View workflow job for this annotation

GitHub Actions / Proto Breaking Change Check

Previously present reserved range "[2]" on message "StatusResponse" was deleted.

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

View workflow job for this annotation

GitHub Actions / Proto Breaking Change Check

Previously present reserved range "[4]" on message "StatusResponse" was deleted.
message Controller {
Expand All @@ -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;
Expand All @@ -207,15 +217,23 @@ 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;
string deployment = 3;
string endpoint = 4;
}
repeated Route routes = 5;

reserved 2, 4;
}

message ProcessListRequest {}
Expand Down

0 comments on commit 038f144

Please sign in to comment.