diff --git a/backend/common/model/deployment_name.go b/backend/common/model/deployment_name.go index 702ac9ca8..e7323695a 100644 --- a/backend/common/model/deployment_name.go +++ b/backend/common/model/deployment_name.go @@ -9,12 +9,12 @@ import ( "fmt" "strings" - "github.com/alecthomas/types" + "github.com/alecthomas/types/optional" ) type DeploymentName string -type MaybeDeploymentName types.Option[DeploymentName] +type MaybeDeploymentName optional.Option[DeploymentName] var _ interface { sql.Scanner diff --git a/backend/common/model/request_name.go b/backend/common/model/request_name.go index dd92bb26b..c83a0d1bc 100644 --- a/backend/common/model/request_name.go +++ b/backend/common/model/request_name.go @@ -10,13 +10,13 @@ import ( "regexp" "strings" - "github.com/alecthomas/types" + "github.com/alecthomas/types/optional" ) // A RequestName represents an inbound request into the cluster. type RequestName string -type MaybeRequestName types.Option[RequestName] +type MaybeRequestName optional.Option[RequestName] var _ interface { sql.Scanner diff --git a/backend/common/rpc/headers/headers.go b/backend/common/rpc/headers/headers.go index ed5eb630a..13db07c73 100644 --- a/backend/common/rpc/headers/headers.go +++ b/backend/common/rpc/headers/headers.go @@ -4,7 +4,7 @@ import ( "fmt" "net/http" - "github.com/alecthomas/types" + "github.com/alecthomas/types/optional" "github.com/TBD54566975/ftl/backend/common/model" "github.com/TBD54566975/ftl/backend/schema" @@ -69,16 +69,16 @@ func GetCallers(header http.Header) ([]*schema.VerbRef, error) { // GetCaller returns the module.verb of the caller, if any. // // Will return an error if the header is malformed. -func GetCaller(header http.Header) (types.Option[*schema.VerbRef], error) { +func GetCaller(header http.Header) (optional.Option[*schema.VerbRef], error) { headers := header.Values(VerbHeader) if len(headers) == 0 { - return types.None[*schema.VerbRef](), nil + return optional.None[*schema.VerbRef](), nil } ref, err := schema.ParseVerbRef(headers[len(headers)-1]) if err != nil { - return types.None[*schema.VerbRef](), err + return optional.None[*schema.VerbRef](), err } - return types.Some(ref), nil + return optional.Some(ref), nil } // AddCaller to an outgoing request. diff --git a/backend/controller/console.go b/backend/controller/console.go index b15a7952a..f34c4563f 100644 --- a/backend/controller/console.go +++ b/backend/controller/console.go @@ -8,7 +8,7 @@ import ( "time" "connectrpc.com/connect" - "github.com/alecthomas/types" + "github.com/alecthomas/types/optional" "google.golang.org/protobuf/types/known/durationpb" "google.golang.org/protobuf/types/known/timestamppb" @@ -269,13 +269,13 @@ func eventsQueryProtoToDAL(pb *pbconsole.EventsQuery) ([]dal.EventFilter, error) } query = append(query, dal.FilterIDRange(lowerThan, higherThan)) case *pbconsole.EventsQuery_Filter_Call: - var sourceModule types.Option[string] + var sourceModule optional.Option[string] if filter.Call.SourceModule != nil { - sourceModule = types.Some(*filter.Call.SourceModule) + sourceModule = optional.Some(*filter.Call.SourceModule) } - var destVerb types.Option[string] + var destVerb optional.Option[string] if filter.Call.DestVerb != nil { - destVerb = types.Some(*filter.Call.DestVerb) + destVerb = optional.Some(*filter.Call.DestVerb) } query = append(query, dal.FilterCall(sourceModule, filter.Call.DestModule, destVerb)) diff --git a/backend/controller/controller.go b/backend/controller/controller.go index 1ca3d3aa4..92a30169f 100644 --- a/backend/controller/controller.go +++ b/backend/controller/controller.go @@ -18,7 +18,7 @@ import ( "connectrpc.com/connect" "github.com/alecthomas/concurrency" "github.com/alecthomas/kong" - "github.com/alecthomas/types" + "github.com/alecthomas/types/optional" "github.com/jackc/pgx/v5" "github.com/jackc/pgx/v5/pgxpool" "github.com/jellydator/ttlcache/v3" @@ -396,13 +396,13 @@ func (s *Service) StreamDeploymentLogs(ctx context.Context, stream *connect.Clie if err != nil { return nil, connect.NewError(connect.CodeInvalidArgument, fmt.Errorf("%s: %w", "invalid deployment key", err)) } - var requestName types.Option[model.RequestName] + var requestName optional.Option[model.RequestName] if msg.RequestName != nil { _, rkey, err := model.ParseRequestName(*msg.RequestName) if err != nil { return nil, connect.NewError(connect.CodeInvalidArgument, fmt.Errorf("%s: %w", "invalid request key", err)) } - requestName = types.Some(rkey) + requestName = optional.Some(rkey) } err = s.dal.InsertLogEvent(ctx, &dal.LogEvent{ @@ -412,7 +412,7 @@ func (s *Service) StreamDeploymentLogs(ctx context.Context, stream *connect.Clie Level: msg.LogLevel, Attributes: msg.Attributes, Message: msg.Message, - Error: types.Ptr(msg.Error), + Error: optional.Ptr(msg.Error), }) if err != nil { return nil, err @@ -671,9 +671,9 @@ func (s *Service) Call(ctx context.Context, req *connect.Request[ftlv1.CallReque headers.AddCaller(req.Header(), schema.VerbRefFromProto(req.Msg.Verb)) resp, err := client.verb.Call(ctx, req) - var maybeResponse types.Option[*ftlv1.CallResponse] + var maybeResponse optional.Option[*ftlv1.CallResponse] if resp != nil { - maybeResponse = types.Some(resp.Msg) + maybeResponse = optional.Some(resp.Msg) } s.recordCall(ctx, &Call{ deploymentName: route.Deployment, @@ -681,7 +681,7 @@ func (s *Service) Call(ctx context.Context, req *connect.Request[ftlv1.CallReque startTime: start, destVerb: verbRef, callers: callers, - callError: types.Nil(err), + callError: optional.Nil(err), request: req.Msg, response: maybeResponse, }) @@ -996,7 +996,7 @@ func (s *Service) watchModuleChanges(ctx context.Context, sendChange func(respon initialCount := len(seedDeployments) deploymentChanges := make(chan dal.DeploymentNotification, len(seedDeployments)) for _, deployment := range seedDeployments { - deploymentChanges <- dal.DeploymentNotification{Message: types.Some(deployment)} + deploymentChanges <- dal.DeploymentNotification{Message: optional.Some(deployment)} } logger.Infof("Seeded %d deployments", initialCount) diff --git a/backend/controller/dal/dal.go b/backend/controller/dal/dal.go index c85c3b445..2343bd4e6 100644 --- a/backend/controller/dal/dal.go +++ b/backend/controller/dal/dal.go @@ -11,7 +11,7 @@ import ( "strings" "time" - "github.com/alecthomas/types" + "github.com/alecthomas/types/optional" sets "github.com/deckarep/golang-set/v2" "github.com/jackc/pgerrcode" "github.com/jackc/pgx/v5" @@ -84,9 +84,9 @@ func DeploymentArtefactFromProto(in *ftlv1.DeploymentArtefact) (DeploymentArtefa } func runnerFromDB(row sql.GetRunnerRow) Runner { - var deployment types.Option[model.DeploymentName] + var deployment optional.Option[model.DeploymentName] if name, ok := row.DeploymentName.Get(); ok { - deployment = types.Some(model.DeploymentName(name)) + deployment = optional.Some(model.DeploymentName(name)) } attrs := model.Labels{} if err := json.Unmarshal(row.Labels, &attrs); err != nil { @@ -105,10 +105,10 @@ type Runner struct { Key model.RunnerKey Endpoint string State RunnerState - ReservationTimeout types.Option[time.Duration] - Module types.Option[string] + ReservationTimeout optional.Option[time.Duration] + Module optional.Option[string] // Assigned deployment key, if any. - Deployment types.Option[model.DeploymentName] + Deployment optional.Option[model.DeploymentName] Labels model.Labels } @@ -309,9 +309,9 @@ func (d *DAL) GetStatus( return Status{}, err } domainRunners, err := slices.MapErr(runners, func(in sql.GetActiveRunnersRow) (Runner, error) { - var deployment types.Option[model.DeploymentName] + var deployment optional.Option[model.DeploymentName] if name, ok := in.DeploymentName.Get(); ok { - deployment = types.Some(model.DeploymentName(name)) + deployment = optional.Some(model.DeploymentName(name)) } attrs := model.Labels{} if err := json.Unmarshal(in.Labels, &attrs); err != nil { @@ -367,7 +367,7 @@ func (d *DAL) GetRunnersForDeployment(ctx context.Context, deployment model.Depl Key: model.RunnerKey(row.Key), Endpoint: row.Endpoint, State: RunnerState(row.State), - Deployment: types.Some(deployment), + Deployment: optional.Some(deployment), Labels: attrs, }) } @@ -507,9 +507,9 @@ func (d *DAL) GetDeployment(ctx context.Context, name model.DeploymentName) (*mo // ErrConflict will be returned if a runner with the same endpoint and a // different key already exists. func (d *DAL) UpsertRunner(ctx context.Context, runner Runner) error { - var pgDeploymentName types.Option[string] + var pgDeploymentName optional.Option[string] if dkey, ok := runner.Deployment.Get(); ok { - pgDeploymentName = types.Some(dkey.String()) + pgDeploymentName = optional.Some(dkey.String()) } attrBytes, err := json.Marshal(runner.Labels) if err != nil { @@ -595,7 +595,7 @@ func (d *DAL) ReserveRunnerForDeployment(ctx context.Context, deployment model.D Key: model.RunnerKey(runner.Key), Endpoint: runner.Endpoint, State: RunnerState(runner.State), - Deployment: types.Some(deployment), + Deployment: optional.Some(deployment), Labels: runnerLabels, }, }, nil @@ -667,7 +667,7 @@ func (d *DAL) ReplaceDeployment(ctx context.Context, newDeploymentName model.Dep return translatePGError(err) } - var replacedDeployment types.Option[string] + var replacedDeployment optional.Option[string] // If there's an existing deployment, set its desired replicas to 0 oldDeployment, err := tx.GetExistingDeploymentForModule(ctx, newDeployment.ModuleName) @@ -679,7 +679,7 @@ func (d *DAL) ReplaceDeployment(ctx context.Context, newDeploymentName model.Dep if count == 1 { return fmt.Errorf("%s: %w", "deployment already exists", ErrConflict) } - replacedDeployment = types.Some(oldDeployment.Name.String()) + replacedDeployment = optional.Some(oldDeployment.Name.String()) } else if !isNotFound(err) { return translatePGError(err) } else { @@ -782,7 +782,7 @@ type Process struct { Deployment model.DeploymentName MinReplicas int Labels model.Labels - Runner types.Option[ProcessRunner] + Runner optional.Option[ProcessRunner] } // GetProcessList returns a list of all "processes". @@ -792,13 +792,13 @@ func (d *DAL) GetProcessList(ctx context.Context) ([]Process, error) { return nil, translatePGError(err) } return slices.MapErr(rows, func(row sql.GetProcessListRow) (Process, error) { - var runner types.Option[ProcessRunner] + var runner optional.Option[ProcessRunner] if endpoint, ok := row.Endpoint.Get(); ok { var labels model.Labels if err := json.Unmarshal(row.RunnerLabels, &labels); err != nil { return Process{}, fmt.Errorf("invalid labels JSON for runner %s: %w", row.RunnerKey, err) } - runner = types.Some(ProcessRunner{ + runner = optional.Some(ProcessRunner{ Key: model.RunnerKey(row.RunnerKey.MustGet()), Endpoint: endpoint, Labels: labels, @@ -905,9 +905,9 @@ func (d *DAL) InsertLogEvent(ctx context.Context, log *LogEvent) error { if err != nil { return err } - var requestName types.Option[string] + var requestName optional.Option[string] if name, ok := log.RequestName.Get(); ok { - requestName = types.Some(string(name)) + requestName = optional.Some(string(name)) } return translatePGError(d.db.InsertLogEvent(ctx, sql.InsertLogEventParams{ DeploymentName: log.DeploymentName, @@ -984,13 +984,13 @@ func (d *DAL) UpsertController(ctx context.Context, key model.ControllerKey, add } func (d *DAL) InsertCallEvent(ctx context.Context, call *CallEvent) error { - var sourceModule, sourceVerb types.Option[string] + var sourceModule, sourceVerb optional.Option[string] if sr, ok := call.SourceVerb.Get(); ok { - sourceModule, sourceVerb = types.Some(sr.Module), types.Some(sr.Name) + sourceModule, sourceVerb = optional.Some(sr.Module), optional.Some(sr.Name) } - var requestName types.Option[string] + var requestName optional.Option[string] if rn, ok := call.RequestName.Get(); ok { - requestName = types.Some(string(rn)) + requestName = optional.Some(string(rn)) } return translatePGError(d.db.InsertCallEvent(ctx, sql.InsertCallEventParams{ DeploymentName: call.DeploymentName.String(), diff --git a/backend/controller/dal/dal_test.go b/backend/controller/dal/dal_test.go index 4ffd12f00..bdfa2ccad 100644 --- a/backend/controller/dal/dal_test.go +++ b/backend/controller/dal/dal_test.go @@ -9,14 +9,15 @@ import ( "testing" "time" + "github.com/alecthomas/assert/v2" + "github.com/alecthomas/types/optional" + "github.com/TBD54566975/ftl/backend/common/log" "github.com/TBD54566975/ftl/backend/common/model" "github.com/TBD54566975/ftl/backend/common/sha256" "github.com/TBD54566975/ftl/backend/controller/sql/sqltest" "github.com/TBD54566975/ftl/backend/schema" ftlv1 "github.com/TBD54566975/ftl/protos/xyz/block/ftl/v1" - "github.com/alecthomas/assert/v2" - "github.com/alecthomas/types" ) //nolint:maintidx @@ -128,7 +129,7 @@ func TestDAL(t *testing.T) { Labels: labels, Endpoint: "http://localhost:8080", State: RunnerStateReserved, - Deployment: types.Some(deploymentName), + Deployment: optional.Some(deploymentName), } t.Run("GetDeploymentsNeedingReconciliation", func(t *testing.T) { @@ -190,7 +191,7 @@ func TestDAL(t *testing.T) { Labels: labels, Endpoint: "http://localhost:8080", State: RunnerStateAssigned, - Deployment: types.Some(deploymentName), + Deployment: optional.Some(deploymentName), }) assert.NoError(t, err) }) @@ -209,7 +210,7 @@ func TestDAL(t *testing.T) { Labels: labels, Endpoint: "http://localhost:8080", State: RunnerStateAssigned, - Deployment: types.Some(deploymentName), + Deployment: optional.Some(deploymentName), }}, runners) }) @@ -222,7 +223,7 @@ func TestDAL(t *testing.T) { callEvent := &CallEvent{ Time: time.Now().Round(time.Millisecond), DeploymentName: deploymentName, - RequestName: types.Some(requestName), + RequestName: optional.Some(requestName), Request: []byte("{}"), Response: []byte(`{"time": "now"}`), DestVerb: schema.VerbRef{Module: "time", Name: "time"}, @@ -235,7 +236,7 @@ func TestDAL(t *testing.T) { logEvent := &LogEvent{ Time: time.Now().Round(time.Millisecond), DeploymentName: deploymentName, - RequestName: types.Some(requestName), + RequestName: optional.Some(requestName), Level: int32(log.Warn), Attributes: map[string]string{"attr": "value"}, Message: "A log entry", @@ -270,7 +271,7 @@ func TestDAL(t *testing.T) { }) t.Run("ByCall", func(t *testing.T) { - events, err := dal.QueryEvents(ctx, 1000, FilterTypes(EventTypeCall), FilterCall(types.None[string](), "time", types.None[string]())) + events, err := dal.QueryEvents(ctx, 1000, FilterTypes(EventTypeCall), FilterCall(optional.None[string](), "time", optional.None[string]())) assert.NoError(t, err) assertEventsEqual(t, []Event{callEvent}, events) }) @@ -299,7 +300,7 @@ func TestDAL(t *testing.T) { Labels: labels, Endpoint: "http://localhost:8080", State: RunnerStateAssigned, - Deployment: types.Some(model.NewDeploymentName("test")), + Deployment: optional.Some(model.NewDeploymentName("test")), }) assert.Error(t, err) assert.IsError(t, err, ErrNotFound) diff --git a/backend/controller/dal/events.go b/backend/controller/dal/events.go index 3e72fff27..b716388b1 100644 --- a/backend/controller/dal/events.go +++ b/backend/controller/dal/events.go @@ -7,7 +7,7 @@ import ( "strconv" "time" - "github.com/alecthomas/types" + "github.com/alecthomas/types/optional" "github.com/jackc/pgx/v5" "github.com/TBD54566975/ftl/backend/common/log" @@ -37,13 +37,13 @@ type Event interface { type LogEvent struct { ID int64 DeploymentName model.DeploymentName - RequestName types.Option[model.RequestName] + RequestName optional.Option[model.RequestName] Time time.Time Level int32 Attributes map[string]string Message string - Error types.Option[string] - Stack types.Option[string] + Error optional.Option[string] + Stack optional.Option[string] } func (e *LogEvent) GetID() int64 { return e.ID } @@ -52,15 +52,15 @@ func (e *LogEvent) event() {} type CallEvent struct { ID int64 DeploymentName model.DeploymentName - RequestName types.Option[model.RequestName] + RequestName optional.Option[model.RequestName] Time time.Time - SourceVerb types.Option[schema.VerbRef] + SourceVerb optional.Option[schema.VerbRef] DestVerb schema.VerbRef Duration time.Duration Request []byte Response []byte - Error types.Option[string] - Stack types.Option[string] + Error optional.Option[string] + Stack optional.Option[string] } func (e *CallEvent) GetID() int64 { return e.ID } @@ -73,7 +73,7 @@ type DeploymentCreatedEvent struct { Language string ModuleName string MinReplicas int - ReplacedDeployment types.Option[model.DeploymentName] + ReplacedDeployment optional.Option[model.DeploymentName] } func (e *DeploymentCreatedEvent) GetID() int64 { return e.ID } @@ -91,9 +91,9 @@ func (e *DeploymentUpdatedEvent) GetID() int64 { return e.ID } func (e *DeploymentUpdatedEvent) event() {} type eventFilterCall struct { - sourceModule types.Option[string] + sourceModule optional.Option[string] destModule string - destVerb types.Option[string] + destVerb optional.Option[string] } type eventFilter struct { @@ -120,7 +120,7 @@ func FilterLogLevel(level log.Level) EventFilter { // FilterCall filters call events between the given modules. // // May be called multiple times. -func FilterCall(sourceModule types.Option[string], destModule string, destVerb types.Option[string]) EventFilter { +func FilterCall(sourceModule optional.Option[string], destModule string, destVerb optional.Option[string]) EventFilter { return func(query *eventFilter) { query.calls = append(query.calls, &eventFilterCall{sourceModule: sourceModule, destModule: destModule, destVerb: destVerb}) } @@ -173,23 +173,23 @@ func FilterDescending() EventFilter { // The internal JSON payload of a call event. type eventCallJSON struct { - DurationMS int64 `json:"duration_ms"` - Request json.RawMessage `json:"request"` - Response json.RawMessage `json:"response"` - Error types.Option[string] `json:"error,omitempty"` - Stack types.Option[string] `json:"stack,omitempty"` + DurationMS int64 `json:"duration_ms"` + Request json.RawMessage `json:"request"` + Response json.RawMessage `json:"response"` + Error optional.Option[string] `json:"error,omitempty"` + Stack optional.Option[string] `json:"stack,omitempty"` } type eventLogJSON struct { - Message string `json:"message"` - Attributes map[string]string `json:"attributes"` - Error types.Option[string] `json:"error,omitempty"` - Stack types.Option[string] `json:"stack,omitempty"` + Message string `json:"message"` + Attributes map[string]string `json:"attributes"` + Error optional.Option[string] `json:"error,omitempty"` + Stack optional.Option[string] `json:"stack,omitempty"` } type eventDeploymentCreatedJSON struct { - MinReplicas int `json:"min_replicas"` - ReplacedDeployment types.Option[model.DeploymentName] `json:"replaced,omitempty"` + MinReplicas int `json:"min_replicas"` + ReplacedDeployment optional.Option[model.DeploymentName] `json:"replaced,omitempty"` } type eventDeploymentUpdatedJSON struct { @@ -200,7 +200,7 @@ type eventDeploymentUpdatedJSON struct { type eventRow struct { sql.Event DeploymentName model.DeploymentName - RequestName types.Option[model.RequestName] + RequestName optional.Option[model.RequestName] } func (d *DAL) QueryEvents(ctx context.Context, limit int, filters ...EventFilter) ([]Event, error) { @@ -341,9 +341,9 @@ func transformRowsToEvents(deploymentNames map[int64]model.DeploymentName, rows row.DeploymentName = deploymentNames[deploymentID] - var requestName types.Option[model.RequestName] + var requestName optional.Option[model.RequestName] if key, ok := row.RequestName.Get(); ok { - requestName = types.Some(key) + requestName = optional.Some(key) } switch row.Type { case sql.EventTypeLog: @@ -372,11 +372,11 @@ func transformRowsToEvents(deploymentNames map[int64]model.DeploymentName, rows if err := json.Unmarshal(row.Payload, &jsonPayload); err != nil { return nil, err } - var sourceVerb types.Option[schema.VerbRef] + var sourceVerb optional.Option[schema.VerbRef] sourceModule, smok := row.CustomKey1.Get() sourceName, snok := row.CustomKey2.Get() if smok && snok { - sourceVerb = types.Some(schema.VerbRef{Module: sourceModule, Name: sourceName}) + sourceVerb = optional.Some(schema.VerbRef{Module: sourceModule, Name: sourceName}) } out = append(out, &CallEvent{ ID: row.ID, diff --git a/backend/controller/dal/notify.go b/backend/controller/dal/notify.go index 2ea070f00..057c40e4a 100644 --- a/backend/controller/dal/notify.go +++ b/backend/controller/dal/notify.go @@ -8,7 +8,7 @@ import ( "strings" "time" - "github.com/alecthomas/types" + "github.com/alecthomas/types/optional" "github.com/jackc/pgx/v5" "github.com/jpillora/backoff" @@ -27,8 +27,8 @@ type Notification[T NotificationPayload, Key any, KeyP interface { *Key encoding.TextUnmarshaler }] struct { - Deleted types.Option[Key] // If present the object was deleted. - Message types.Option[T] + Deleted optional.Option[Key] // If present the object was deleted. + Message optional.Option[T] } func (n Notification[T, Key, KeyP]) String() string { @@ -95,14 +95,14 @@ func (d *DAL) runListener(ctx context.Context, conn *pgx.Conn) { func (d *DAL) publishNotification(ctx context.Context, notification event, logger *log.Logger) error { switch notification.Table { case "deployments": - deployment, err := decodeNotification(notification, func(key model.DeploymentName) (Deployment, types.Option[model.DeploymentName], error) { + deployment, err := decodeNotification(notification, func(key model.DeploymentName) (Deployment, optional.Option[model.DeploymentName], error) { row, err := d.db.GetDeployment(ctx, key) if err != nil { - return Deployment{}, types.None[model.DeploymentName](), translatePGError(err) + return Deployment{}, optional.None[model.DeploymentName](), translatePGError(err) } moduleSchema, err := schema.ModuleFromBytes(row.Deployment.Schema) if err != nil { - return Deployment{}, types.None[model.DeploymentName](), err + return Deployment{}, optional.None[model.DeploymentName](), err } return Deployment{ CreatedAt: row.Deployment.CreatedAt, @@ -111,7 +111,7 @@ func (d *DAL) publishNotification(ctx context.Context, notification event, logge Schema: moduleSchema, MinReplicas: int(row.Deployment.MinReplicas), Language: row.Language, - }, types.None[model.DeploymentName](), nil + }, optional.None[model.DeploymentName](), nil }) if err != nil { return err @@ -133,10 +133,10 @@ func (d *DAL) publishNotification(ctx context.Context, notification event, logge func decodeNotification[K any, T NotificationPayload, KP interface { *K encoding.TextUnmarshaler -}](notification event, translate func(key K) (T, types.Option[K], error)) (Notification[T, K, KP], error) { +}](notification event, translate func(key K) (T, optional.Option[K], error)) (Notification[T, K, KP], error) { var ( - deleted types.Option[K] - message types.Option[T] + deleted optional.Option[K] + message optional.Option[T] ) if notification.Action == "DELETE" { var deletedKey K @@ -144,7 +144,7 @@ func decodeNotification[K any, T NotificationPayload, KP interface { if err := deletedKeyP.UnmarshalText([]byte(notification.Old)); err != nil { return Notification[T, K, KP]{}, fmt.Errorf("%s: %w", "failed to unmarshal notification key", err) } - deleted = types.Some(deletedKey) + deleted = optional.Some(deletedKey) } else { var newKey K var newKeyP KP = &newKey @@ -159,7 +159,7 @@ func decodeNotification[K any, T NotificationPayload, KP interface { } if !deleted.Ok() { - message = types.Some(msg) + message = optional.Some(msg) } } diff --git a/backend/controller/deployment_logs.go b/backend/controller/deployment_logs.go index d02f8e553..cb4211924 100644 --- a/backend/controller/deployment_logs.go +++ b/backend/controller/deployment_logs.go @@ -5,7 +5,7 @@ import ( "fmt" "time" - "github.com/alecthomas/types" + "github.com/alecthomas/types/optional" "github.com/TBD54566975/ftl/backend/common/log" "github.com/TBD54566975/ftl/backend/common/model" @@ -58,16 +58,16 @@ func (d *deploymentLogsSink) processLogs(ctx context.Context) { } deployment = dep - var errorStr types.Option[string] + var errorStr optional.Option[string] if entry.Error != nil { - errorStr = types.Some(entry.Error.Error()) + errorStr = optional.Some(entry.Error.Error()) } - var request types.Option[model.RequestName] + var request optional.Option[model.RequestName] if reqStr, ok := entry.Attributes["request"]; ok { _, req, err := model.ParseRequestName(reqStr) if err == nil { - request = types.Some(req) + request = optional.Some(req) } } diff --git a/backend/controller/observability.go b/backend/controller/observability.go index 13d13cbfd..5e0399d16 100644 --- a/backend/controller/observability.go +++ b/backend/controller/observability.go @@ -4,7 +4,7 @@ import ( "context" "time" - "github.com/alecthomas/types" + "github.com/alecthomas/types/optional" "github.com/TBD54566975/ftl/backend/common/log" "github.com/TBD54566975/ftl/backend/common/model" @@ -20,35 +20,35 @@ type Call struct { destVerb *schema.VerbRef callers []*schema.VerbRef request *ftlv1.CallRequest - response types.Option[*ftlv1.CallResponse] - callError types.Option[error] + response optional.Option[*ftlv1.CallResponse] + callError optional.Option[error] } func (s *Service) recordCall(ctx context.Context, call *Call) { logger := log.FromContext(ctx) - var sourceVerb types.Option[schema.VerbRef] + var sourceVerb optional.Option[schema.VerbRef] if len(call.callers) > 0 { - sourceVerb = types.Some(*call.callers[0]) + sourceVerb = optional.Some(*call.callers[0]) } - var errorStr types.Option[string] - var stack types.Option[string] + var errorStr optional.Option[string] + var stack optional.Option[string] var responseBody []byte if callError, ok := call.callError.Get(); ok { - errorStr = types.Some(callError.Error()) + errorStr = optional.Some(callError.Error()) } else if response, ok := call.response.Get(); ok { responseBody = response.GetBody() if callError := response.GetError(); callError != nil { - errorStr = types.Some(callError.Message) - stack = types.Ptr(callError.Stack) + errorStr = optional.Some(callError.Message) + stack = optional.Ptr(callError.Stack) } } err := s.dal.InsertCallEvent(ctx, &dal.CallEvent{ Time: call.startTime, DeploymentName: call.deploymentName, - RequestName: types.Some(call.requestName), + RequestName: optional.Some(call.requestName), Duration: time.Since(call.startTime), SourceVerb: sourceVerb, DestVerb: *call.destVerb, diff --git a/backend/controller/sql/models.go b/backend/controller/sql/models.go index cc99dde08..0363d6082 100644 --- a/backend/controller/sql/models.go +++ b/backend/controller/sql/models.go @@ -11,7 +11,7 @@ import ( "time" "github.com/TBD54566975/ftl/backend/common/model" - "github.com/alecthomas/types" + "github.com/alecthomas/types/optional" ) type ControllerState string @@ -225,12 +225,12 @@ type Event struct { ID int64 TimeStamp time.Time DeploymentID int64 - RequestID types.Option[int64] + RequestID optional.Option[int64] Type EventType - CustomKey1 types.Option[string] - CustomKey2 types.Option[string] - CustomKey3 types.Option[string] - CustomKey4 types.Option[string] + CustomKey1 optional.Option[string] + CustomKey2 optional.Option[string] + CustomKey3 optional.Option[string] + CustomKey4 optional.Option[string] Payload json.RawMessage } @@ -263,7 +263,7 @@ type Runner struct { ReservationTimeout NullTime State RunnerState Endpoint string - ModuleName types.Option[string] - DeploymentID types.Option[int64] + ModuleName optional.Option[string] + DeploymentID optional.Option[int64] Labels []byte } diff --git a/backend/controller/sql/querier.go b/backend/controller/sql/querier.go index 11318b4dd..1c455b554 100644 --- a/backend/controller/sql/querier.go +++ b/backend/controller/sql/querier.go @@ -9,7 +9,7 @@ import ( "time" "github.com/TBD54566975/ftl/backend/common/model" - "github.com/alecthomas/types" + "github.com/alecthomas/types/optional" ) type Querier interface { @@ -68,7 +68,7 @@ type Querier interface { // otherwise we try to retrieve the deployments.id using the key. If // there is no corresponding deployment, then the deployment ID is -1 // and the parent statement will fail due to a foreign key constraint. - UpsertRunner(ctx context.Context, arg UpsertRunnerParams) (types.Option[int64], error) + UpsertRunner(ctx context.Context, arg UpsertRunnerParams) (optional.Option[int64], error) } var _ Querier = (*Queries)(nil) diff --git a/backend/controller/sql/queries.sql.go b/backend/controller/sql/queries.sql.go index b8992b589..860638764 100644 --- a/backend/controller/sql/queries.sql.go +++ b/backend/controller/sql/queries.sql.go @@ -11,7 +11,7 @@ import ( "time" "github.com/TBD54566975/ftl/backend/common/model" - "github.com/alecthomas/types" + "github.com/alecthomas/types/optional" ) const associateArtefactWithDeployment = `-- name: AssociateArtefactWithDeployment :exec @@ -228,8 +228,8 @@ type GetActiveRunnersRow struct { State RunnerState Labels []byte LastSeen time.Time - ModuleName types.Option[string] - DeploymentName types.Option[string] + ModuleName optional.Option[string] + DeploymentName optional.Option[string] } func (q *Queries) GetActiveRunners(ctx context.Context, all bool) ([]GetActiveRunnersRow, error) { @@ -755,7 +755,7 @@ type GetProcessListRow struct { DeploymentName model.DeploymentName DeploymentLabels []byte RunnerKey NullKey - Endpoint types.Option[string] + Endpoint optional.Option[string] RunnerLabels []byte } @@ -796,7 +796,7 @@ WHERE r.key = $1 type GetRouteForRunnerRow struct { Endpoint string RunnerKey Key - ModuleName types.Option[string] + ModuleName optional.Option[string] DeploymentName model.DeploymentName State RunnerState } @@ -827,7 +827,7 @@ WHERE state = 'assigned' type GetRoutingTableRow struct { Endpoint string RunnerKey Key - ModuleName types.Option[string] + ModuleName optional.Option[string] DeploymentName model.DeploymentName } @@ -877,8 +877,8 @@ type GetRunnerRow struct { State RunnerState Labels []byte LastSeen time.Time - ModuleName types.Option[string] - DeploymentName types.Option[string] + ModuleName optional.Option[string] + DeploymentName optional.Option[string] } func (q *Queries) GetRunner(ctx context.Context, key Key) (GetRunnerRow, error) { @@ -925,8 +925,8 @@ type GetRunnersForDeploymentRow struct { ReservationTimeout NullTime State RunnerState Endpoint string - ModuleName types.Option[string] - DeploymentID types.Option[int64] + ModuleName optional.Option[string] + DeploymentID optional.Option[int64] Labels []byte ID_2 int64 CreatedAt time.Time @@ -1000,17 +1000,17 @@ VALUES ((SELECT id FROM deployments WHERE deployments.name = $1::TEXT), type InsertCallEventParams struct { DeploymentName string - RequestName types.Option[string] + RequestName optional.Option[string] TimeStamp time.Time - SourceModule types.Option[string] - SourceVerb types.Option[string] + SourceModule optional.Option[string] + SourceVerb optional.Option[string] DestModule string DestVerb string DurationMs int64 Request []byte Response []byte - Error types.Option[string] - Stack types.Option[string] + Error optional.Option[string] + Stack optional.Option[string] } func (q *Queries) InsertCallEvent(ctx context.Context, arg InsertCallEventParams) error { @@ -1050,7 +1050,7 @@ type InsertDeploymentCreatedEventParams struct { Language string ModuleName string MinReplicas int32 - Replaced types.Option[string] + Replaced optional.Option[string] } func (q *Queries) InsertDeploymentCreatedEvent(ctx context.Context, arg InsertDeploymentCreatedEventParams) error { @@ -1107,12 +1107,12 @@ RETURNING id type InsertEventParams struct { DeploymentID int64 - RequestID types.Option[int64] + RequestID optional.Option[int64] Type EventType - CustomKey1 types.Option[string] - CustomKey2 types.Option[string] - CustomKey3 types.Option[string] - CustomKey4 types.Option[string] + CustomKey1 optional.Option[string] + CustomKey2 optional.Option[string] + CustomKey3 optional.Option[string] + CustomKey4 optional.Option[string] Payload json.RawMessage } @@ -1150,13 +1150,13 @@ VALUES ((SELECT id FROM deployments d WHERE d.name = $1 LIMIT 1), type InsertLogEventParams struct { DeploymentName model.DeploymentName - RequestName types.Option[string] + RequestName optional.Option[string] TimeStamp time.Time Level int32 Message string Attributes []byte - Error types.Option[string] - Stack types.Option[string] + Error optional.Option[string] + Stack optional.Option[string] } func (q *Queries) InsertLogEvent(ctx context.Context, arg InsertLogEventParams) error { @@ -1337,7 +1337,7 @@ type UpsertRunnerParams struct { Endpoint string State RunnerState Labels []byte - DeploymentName types.Option[string] + DeploymentName optional.Option[string] } // Upsert a runner and return the deployment ID that it is assigned to, if any. @@ -1345,7 +1345,7 @@ type UpsertRunnerParams struct { // otherwise we try to retrieve the deployments.id using the key. If // there is no corresponding deployment, then the deployment ID is -1 // and the parent statement will fail due to a foreign key constraint. -func (q *Queries) UpsertRunner(ctx context.Context, arg UpsertRunnerParams) (types.Option[int64], error) { +func (q *Queries) UpsertRunner(ctx context.Context, arg UpsertRunnerParams) (optional.Option[int64], error) { row := q.db.QueryRow(ctx, upsertRunner, arg.Key, arg.Endpoint, @@ -1353,7 +1353,7 @@ func (q *Queries) UpsertRunner(ctx context.Context, arg UpsertRunnerParams) (typ arg.Labels, arg.DeploymentName, ) - var deployment_id types.Option[int64] + var deployment_id optional.Option[int64] err := row.Scan(&deployment_id) return deployment_id, err } diff --git a/backend/controller/sql/types.go b/backend/controller/sql/types.go index c1abf942b..edd362766 100644 --- a/backend/controller/sql/types.go +++ b/backend/controller/sql/types.go @@ -5,22 +5,22 @@ import ( "fmt" "time" - "github.com/alecthomas/types" + "github.com/alecthomas/types/optional" "github.com/google/uuid" "github.com/oklog/ulid/v2" ) -type NullKey = types.Option[Key] +type NullKey = optional.Option[Key] -// FromOption converts a types.Option[~ulid.ULID] to a NullKey. -func FromOption[T ~[16]byte](o types.Option[T]) NullKey { +// FromOption converts a optional.Option[~ulid.ULID] to a NullKey. +func FromOption[T ~[16]byte](o optional.Option[T]) NullKey { if v, ok := o.Get(); ok { return SomeKey(Key(v)) } return NoneKey() } -func SomeKey(key Key) NullKey { return types.Some(key) } -func NoneKey() NullKey { return types.None[Key]() } +func SomeKey(key Key) NullKey { return optional.Some(key) } +func NoneKey() NullKey { return optional.None[Key]() } // Key is a ULID that can be used as a column in a database. type Key ulid.ULID @@ -57,5 +57,5 @@ func (u *Key) UnmarshalText(text []byte) error { return nil } -type NullTime = types.Option[time.Time] -type NullDuration = types.Option[time.Duration] +type NullTime = optional.Option[time.Time] +type NullDuration = optional.Option[time.Duration] diff --git a/backend/runner/runner.go b/backend/runner/runner.go index 5b75e67ee..72d1a3a73 100644 --- a/backend/runner/runner.go +++ b/backend/runner/runner.go @@ -17,7 +17,7 @@ import ( "connectrpc.com/connect" "github.com/alecthomas/atomic" - "github.com/alecthomas/types" + "github.com/alecthomas/types/optional" "github.com/jpillora/backoff" "github.com/otiai10/copy" "google.golang.org/protobuf/types/known/structpb" @@ -121,12 +121,12 @@ type Service struct { lock sync.Mutex state atomic.Value[ftlv1.RunnerState] forceUpdate chan struct{} - deployment atomic.Value[types.Option[*deployment]] + deployment atomic.Value[optional.Option[*deployment]] config Config controllerClient ftlv1connect.ControllerServiceClient // Failed to register with the Controller - registrationFailure atomic.Value[types.Option[error]] + registrationFailure atomic.Value[optional.Option[error]] labels *structpb.Struct deploymentLogQueue chan log.Entry } @@ -179,7 +179,7 @@ func (s *Service) Deploy(ctx context.Context, req *connect.Request[ftlv1.DeployR defer func() { if err != nil { setState(ftlv1.RunnerState_RUNNER_IDLE) - s.deployment.Store(types.None[*deployment]()) + s.deployment.Store(optional.None[*deployment]()) } }() @@ -226,7 +226,7 @@ func (s *Service) Deploy(ctx context.Context, req *connect.Request[ftlv1.DeployR } dep := s.makeDeployment(cmdCtx, key, deployment) - s.deployment.Store(types.Some(dep)) + s.deployment.Store(optional.Some(dep)) setState(ftlv1.RunnerState_RUNNER_ASSIGNED) return connect.NewResponse(&ftlv1.DeployResponse{}), nil @@ -262,7 +262,7 @@ func (s *Service) Terminate(ctx context.Context, c *connect.Request[ftlv1.Termin return nil, fmt.Errorf("%s: %w", "failed to kill plugin", err) } } - s.deployment.Store(types.None[*deployment]()) + s.deployment.Store(optional.None[*deployment]()) s.state.Store(ftlv1.RunnerState_RUNNER_IDLE) return connect.NewResponse(&ftlv1.RegisterRunnerRequest{ Key: s.key.String(), @@ -298,7 +298,7 @@ func (s *Service) registrationLoop(ctx context.Context, send func(request *ftlv1 errStr := err.Error() errPtr = &errStr s.getDeploymentLogger(ctx, depl.key).Errorf(err, "Deployment terminated") - s.deployment.Store(types.None[*deployment]()) + s.deployment.Store(optional.None[*deployment]()) default: state = ftlv1.RunnerState_RUNNER_ASSIGNED @@ -316,10 +316,10 @@ func (s *Service) registrationLoop(ctx context.Context, send func(request *ftlv1 Error: errPtr, }) if err != nil { - s.registrationFailure.Store(types.Some(err)) + s.registrationFailure.Store(optional.Some(err)) return fmt.Errorf("%s: %w", "failed to register with Controller", err) } - s.registrationFailure.Store(types.None[error]()) + s.registrationFailure.Store(optional.None[error]()) // Wait for the next heartbeat. delay := s.config.HeartbeatPeriod + time.Duration(rand.Intn(int(s.config.HeartbeatJitter))) //nolint:gosec @@ -327,7 +327,7 @@ func (s *Service) registrationLoop(ctx context.Context, send func(request *ftlv1 select { case <-ctx.Done(): err = context.Cause(ctx) - s.registrationFailure.Store(types.Some(err)) + s.registrationFailure.Store(optional.Some(err)) return err case <-s.forceUpdate: diff --git a/backend/schema/schema.go b/backend/schema/schema.go index 8cc9b4c11..94d6f1133 100644 --- a/backend/schema/schema.go +++ b/backend/schema/schema.go @@ -6,7 +6,7 @@ import ( "reflect" "strings" - "github.com/alecthomas/types" + "github.com/alecthomas/types/optional" "google.golang.org/protobuf/proto" schemapb "github.com/TBD54566975/ftl/protos/xyz/block/ftl/v1/schema" @@ -71,13 +71,13 @@ func (s *Schema) ResolveVerbRef(ref *VerbRef) *Verb { } // Module returns the named module if it exists. -func (s *Schema) Module(name string) types.Option[*Module] { +func (s *Schema) Module(name string) optional.Option[*Module] { for _, module := range s.Modules { if module.Name == name { - return types.Some(module) + return optional.Some(module) } } - return types.None[*Module]() + return optional.None[*Module]() } func (s *Schema) DataMap() map[Ref]*Data { diff --git a/backend/schema/verb.go b/backend/schema/verb.go index 5ff7978b6..87d1d3bc0 100644 --- a/backend/schema/verb.go +++ b/backend/schema/verb.go @@ -4,7 +4,7 @@ import ( "fmt" "strings" - "github.com/alecthomas/types" + "github.com/alecthomas/types/optional" "google.golang.org/protobuf/proto" schemapb "github.com/TBD54566975/ftl/protos/xyz/block/ftl/v1/schema" @@ -62,13 +62,13 @@ func (v *Verb) AddCall(verb *VerbRef) { v.Metadata = append(v.Metadata, &MetadataCalls{Calls: []*VerbRef{verb}}) } -func (v *Verb) GetMetadataIngress() types.Option[*MetadataIngress] { +func (v *Verb) GetMetadataIngress() optional.Option[*MetadataIngress] { for _, m := range v.Metadata { if m, ok := m.(*MetadataIngress); ok { - return types.Some(m) + return optional.Some(m) } } - return types.None[*MetadataIngress]() + return optional.None[*MetadataIngress]() } func (v *Verb) ToProto() proto.Message { diff --git a/examples/online-boutique/services/checkout/go.mod b/examples/online-boutique/services/checkout/go.mod index 75d69aa3a..95faa91aa 100644 --- a/examples/online-boutique/services/checkout/go.mod +++ b/examples/online-boutique/services/checkout/go.mod @@ -18,7 +18,7 @@ require ( connectrpc.com/otelconnect v0.7.0 // indirect github.com/alecthomas/concurrency v0.0.2 // indirect github.com/alecthomas/participle/v2 v2.1.1 // indirect - github.com/alecthomas/types v0.9.0 // indirect + github.com/alecthomas/types v0.10.0 // indirect github.com/alessio/shellescape v1.4.2 // indirect github.com/danieljoos/wincred v1.2.0 // indirect github.com/go-logr/logr v1.4.1 // indirect diff --git a/examples/online-boutique/services/checkout/go.sum b/examples/online-boutique/services/checkout/go.sum index b26a2ac86..fbee97566 100644 --- a/examples/online-boutique/services/checkout/go.sum +++ b/examples/online-boutique/services/checkout/go.sum @@ -12,8 +12,8 @@ github.com/alecthomas/participle/v2 v2.1.1 h1:hrjKESvSqGHzRb4yW1ciisFJ4p3MGYih6i github.com/alecthomas/participle/v2 v2.1.1/go.mod h1:Y1+hAs8DHPmc3YUFzqllV+eSQ9ljPTk0ZkPMtEdAx2c= github.com/alecthomas/repr v0.3.0 h1:NeYzUPfjjlqHY4KtzgKJiWd6sVq2eNUPTi34PiFGjY8= github.com/alecthomas/repr v0.3.0/go.mod h1:Fr0507jx4eOXV7AlPV6AVZLYrLIuIeSOWtW57eE/O/4= -github.com/alecthomas/types v0.9.0 h1:g/P/fNElr7Ot1tWxSEms/I2gnRemxAqGNeetW6HOlO4= -github.com/alecthomas/types v0.9.0/go.mod h1:t7PnU03TVweFpbPVKaeLtFykjJD8rqiBJ7gfkp6UvLQ= +github.com/alecthomas/types v0.10.0 h1:u9dDe+EFuCHLiBw5QsKAYXGEbkmrOW3se0RPEuvJVT8= +github.com/alecthomas/types v0.10.0/go.mod h1:fIOGnLeeUJXe1AAVofQmMaEMWLxY9bK4QxTLGIo30PA= github.com/alessio/shellescape v1.4.2 h1:MHPfaU+ddJ0/bYWpgIeUnQUqKrlJ1S7BfEYPM4uEoM0= github.com/alessio/shellescape v1.4.2/go.mod h1:PZAiSCk0LJaZkiCSkPv8qIobYglO3FPpyFjDCtHLS30= github.com/bool64/dev v0.2.31 h1:OS57EqYaYe2M/2bw9uhDCIFiZZwywKFS/4qMLN6JUmQ= diff --git a/examples/online-boutique/services/recommendation/go.mod b/examples/online-boutique/services/recommendation/go.mod index 586c51ad6..81b0b244d 100644 --- a/examples/online-boutique/services/recommendation/go.mod +++ b/examples/online-boutique/services/recommendation/go.mod @@ -14,7 +14,7 @@ require ( connectrpc.com/otelconnect v0.7.0 // indirect github.com/alecthomas/concurrency v0.0.2 // indirect github.com/alecthomas/participle/v2 v2.1.1 // indirect - github.com/alecthomas/types v0.9.0 // indirect + github.com/alecthomas/types v0.10.0 // indirect github.com/alessio/shellescape v1.4.2 // indirect github.com/danieljoos/wincred v1.2.0 // indirect github.com/go-logr/logr v1.4.1 // indirect diff --git a/examples/online-boutique/services/recommendation/go.sum b/examples/online-boutique/services/recommendation/go.sum index b26a2ac86..fbee97566 100644 --- a/examples/online-boutique/services/recommendation/go.sum +++ b/examples/online-boutique/services/recommendation/go.sum @@ -12,8 +12,8 @@ github.com/alecthomas/participle/v2 v2.1.1 h1:hrjKESvSqGHzRb4yW1ciisFJ4p3MGYih6i github.com/alecthomas/participle/v2 v2.1.1/go.mod h1:Y1+hAs8DHPmc3YUFzqllV+eSQ9ljPTk0ZkPMtEdAx2c= github.com/alecthomas/repr v0.3.0 h1:NeYzUPfjjlqHY4KtzgKJiWd6sVq2eNUPTi34PiFGjY8= github.com/alecthomas/repr v0.3.0/go.mod h1:Fr0507jx4eOXV7AlPV6AVZLYrLIuIeSOWtW57eE/O/4= -github.com/alecthomas/types v0.9.0 h1:g/P/fNElr7Ot1tWxSEms/I2gnRemxAqGNeetW6HOlO4= -github.com/alecthomas/types v0.9.0/go.mod h1:t7PnU03TVweFpbPVKaeLtFykjJD8rqiBJ7gfkp6UvLQ= +github.com/alecthomas/types v0.10.0 h1:u9dDe+EFuCHLiBw5QsKAYXGEbkmrOW3se0RPEuvJVT8= +github.com/alecthomas/types v0.10.0/go.mod h1:fIOGnLeeUJXe1AAVofQmMaEMWLxY9bK4QxTLGIo30PA= github.com/alessio/shellescape v1.4.2 h1:MHPfaU+ddJ0/bYWpgIeUnQUqKrlJ1S7BfEYPM4uEoM0= github.com/alessio/shellescape v1.4.2/go.mod h1:PZAiSCk0LJaZkiCSkPv8qIobYglO3FPpyFjDCtHLS30= github.com/bool64/dev v0.2.31 h1:OS57EqYaYe2M/2bw9uhDCIFiZZwywKFS/4qMLN6JUmQ= diff --git a/go.mod b/go.mod index 0021abb21..08ca5a939 100644 --- a/go.mod +++ b/go.mod @@ -15,7 +15,7 @@ require ( github.com/alecthomas/kong v0.8.1 github.com/alecthomas/kong-toml v0.1.0 github.com/alecthomas/participle/v2 v2.1.1 - github.com/alecthomas/types v0.9.0 + github.com/alecthomas/types v0.10.0 github.com/amacneil/dbmate/v2 v2.10.0 github.com/beevik/etree v1.3.0 github.com/bmatcuk/doublestar/v4 v4.6.1 diff --git a/go.sum b/go.sum index ed3b74bc4..b3a975e6f 100644 --- a/go.sum +++ b/go.sum @@ -31,8 +31,8 @@ github.com/alecthomas/participle/v2 v2.1.1 h1:hrjKESvSqGHzRb4yW1ciisFJ4p3MGYih6i github.com/alecthomas/participle/v2 v2.1.1/go.mod h1:Y1+hAs8DHPmc3YUFzqllV+eSQ9ljPTk0ZkPMtEdAx2c= github.com/alecthomas/repr v0.3.0 h1:NeYzUPfjjlqHY4KtzgKJiWd6sVq2eNUPTi34PiFGjY8= github.com/alecthomas/repr v0.3.0/go.mod h1:Fr0507jx4eOXV7AlPV6AVZLYrLIuIeSOWtW57eE/O/4= -github.com/alecthomas/types v0.9.0 h1:g/P/fNElr7Ot1tWxSEms/I2gnRemxAqGNeetW6HOlO4= -github.com/alecthomas/types v0.9.0/go.mod h1:t7PnU03TVweFpbPVKaeLtFykjJD8rqiBJ7gfkp6UvLQ= +github.com/alecthomas/types v0.10.0 h1:u9dDe+EFuCHLiBw5QsKAYXGEbkmrOW3se0RPEuvJVT8= +github.com/alecthomas/types v0.10.0/go.mod h1:fIOGnLeeUJXe1AAVofQmMaEMWLxY9bK4QxTLGIo30PA= github.com/alessio/shellescape v1.4.2 h1:MHPfaU+ddJ0/bYWpgIeUnQUqKrlJ1S7BfEYPM4uEoM0= github.com/alessio/shellescape v1.4.2/go.mod h1:PZAiSCk0LJaZkiCSkPv8qIobYglO3FPpyFjDCtHLS30= github.com/amacneil/dbmate/v2 v2.10.0 h1:bGp1sL/tijenf/BhQBw/t0LmiYvBTi+LXn6uBiHwLII= diff --git a/protos/xyz/block/ftl/v1/mixins.go b/protos/xyz/block/ftl/v1/mixins.go index 6ff036259..b09965ccf 100644 --- a/protos/xyz/block/ftl/v1/mixins.go +++ b/protos/xyz/block/ftl/v1/mixins.go @@ -4,7 +4,7 @@ import ( "fmt" "strings" - "github.com/alecthomas/types" + "github.com/alecthomas/types/optional" model "github.com/TBD54566975/ftl/backend/common/model" ) @@ -32,13 +32,13 @@ func (m *Metadata) Add(key, value string) { m.Values = append(m.Values, &Metadata_Pair{Key: key, Value: value}) } -func (m *Metadata) Get(key string) types.Option[string] { +func (m *Metadata) Get(key string) optional.Option[string] { for _, pair := range m.Values { if strings.EqualFold(pair.Key, key) { - return types.Some(pair.Value) + return optional.Some(pair.Value) } } - return types.None[string]() + return optional.None[string]() } func (m *Metadata) GetAll(key string) (out []string) { @@ -60,13 +60,13 @@ func (m *Metadata) Delete(key string) { m.Values = out } -func (r *RegisterRunnerRequest) DeploymentAsOptional() (types.Option[model.DeploymentName], error) { +func (r *RegisterRunnerRequest) DeploymentAsOptional() (optional.Option[model.DeploymentName], error) { if r.Deployment == nil { - return types.None[model.DeploymentName](), nil + return optional.None[model.DeploymentName](), nil } key, err := model.ParseDeploymentName(*r.Deployment) if err != nil { - return types.None[model.DeploymentName](), fmt.Errorf("%s: %w", "invalid deployment key", err) + return optional.None[model.DeploymentName](), fmt.Errorf("%s: %w", "invalid deployment key", err) } - return types.Some(key), nil + return optional.Some(key), nil } diff --git a/sqlc.yaml b/sqlc.yaml index 6d82f843b..9c2ba5f64 100644 --- a/sqlc.yaml +++ b/sqlc.yaml @@ -24,42 +24,42 @@ sql: - db_type: "timestamptz" nullable: true go_type: - type: "NullTime" + type: "NullTime" - db_type: "uuid" go_type: - type: "Key" + type: "Key" - db_type: "uuid" nullable: true go_type: - type: "NullKey" + type: "NullKey" - db_type: "pg_catalog.varchar" nullable: true - go_type: "github.com/alecthomas/types.Option[string]" + go_type: "github.com/alecthomas/types/optional.Option[string]" - db_type: "text" go_type: "string" - db_type: "text" nullable: true - go_type: "github.com/alecthomas/types.Option[string]" + go_type: "github.com/alecthomas/types/optional.Option[string]" - db_type: "pg_catalog.int8" nullable: true - go_type: "github.com/alecthomas/types.Option[int64]" + go_type: "github.com/alecthomas/types/optional.Option[int64]" - db_type: "bigint" nullable: true - go_type: "github.com/alecthomas/types.Option[int64]" + go_type: "github.com/alecthomas/types/optional.Option[int64]" - db_type: "int" nullable: true - go_type: "github.com/alecthomas/types.Option[int32]" + go_type: "github.com/alecthomas/types/optional.Option[int32]" - db_type: "bool" nullable: true - go_type: "github.com/alecthomas/types.Option[bool]" + go_type: "github.com/alecthomas/types/optional.Option[bool]" # Can't use until https://github.com/sqlc-dev/sqlc/issues/2632 is fixed, if it ever is... -# - column: "ingress_requests.key" -# go_type: "github.com/TBD54566975/ftl/backend/common/model.RequestName" -# - column: "ingress_requests.key" -# nullable: true -# go_type: "github.com/TBD54566975/ftl/backend/common/model.NullRequestName" -# - column: "runners.key" -# go_type: "github.com/TBD54566975/ftl/backend/common/model.RunnerKey" + # - column: "ingress_requests.key" + # go_type: "github.com/TBD54566975/ftl/backend/common/model.RequestName" + # - column: "ingress_requests.key" + # nullable: true + # go_type: "github.com/TBD54566975/ftl/backend/common/model.NullRequestName" + # - column: "runners.key" + # go_type: "github.com/TBD54566975/ftl/backend/common/model.RunnerKey" - column: "controller.key" go_type: "github.com/TBD54566975/ftl/backend/common/model.ControllerKey" - column: "deployments.name" @@ -71,9 +71,9 @@ sql: # - postgresql-query-too-costly - postgresql-no-seq-scan rules: -- name: postgresql-query-too-costly - message: "Query cost estimate is too high" - rule: "postgresql.explain.plan.total_cost > 500.0" -- name: postgresql-no-seq-scan - message: "Query plan results in a sequential scan" - rule: "postgresql.explain.plan.node_type == 'Seq Scan'" + - name: postgresql-query-too-costly + message: "Query cost estimate is too high" + rule: "postgresql.explain.plan.total_cost > 500.0" + - name: postgresql-no-seq-scan + message: "Query plan results in a sequential scan" + rule: "postgresql.explain.plan.node_type == 'Seq Scan'"