Skip to content

Commit

Permalink
chore: remove left over DB stuff (#3790)
Browse files Browse the repository at this point in the history
  • Loading branch information
stuartwdouglas authored Dec 17, 2024
1 parent c6b2b27 commit e9e1372
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 40 deletions.
15 changes: 5 additions & 10 deletions backend/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,12 @@ type CommonConfig struct {
type Config struct {
Bind *url.URL `help:"Socket to bind to." default:"http://127.0.0.1:8892" env:"FTL_BIND"`
Key model.ControllerKey `help:"Controller key (auto)." placeholder:"KEY"`
DSN string `help:"DAL DSN." default:"${dsn}" env:"FTL_DSN"`
Advertise *url.URL `help:"Endpoint the Controller should advertise (must be unique across the cluster, defaults to --bind if omitted)." env:"FTL_ADVERTISE"`
RunnerTimeout time.Duration `help:"Runner heartbeat timeout." default:"10s"`
ControllerTimeout time.Duration `help:"Controller heartbeat timeout." default:"10s"`
DeploymentReservationTimeout time.Duration `help:"Deployment reservation timeout." default:"120s"`
ModuleUpdateFrequency time.Duration `help:"Frequency to send module updates." default:"30s"`
ArtefactChunkSize int `help:"Size of each chunk streamed to the client." default:"1048576"`
MaxOpenDBConnections int `help:"Maximum number of database connections." default:"20" env:"FTL_MAX_OPEN_DB_CONNECTIONS"`
MaxIdleDBConnections int `help:"Maximum number of idle database connections." default:"20" env:"FTL_MAX_IDLE_DB_CONNECTIONS"`
CommonConfig
}

Expand All @@ -86,13 +83,13 @@ func (c *Config) SetDefaults() {
}
}

func (c *Config) OpenDBAndInstrument() (*sql.DB, error) {
conn, err := internalobservability.OpenDBAndInstrument(c.DSN)
func (c *Config) OpenDBAndInstrument(dsn string) (*sql.DB, error) {
conn, err := internalobservability.OpenDBAndInstrument(dsn)
if err != nil {
return nil, fmt.Errorf("failed to open DB connection: %w", err)
}
conn.SetMaxIdleConns(c.MaxIdleDBConnections)
conn.SetMaxOpenConns(c.MaxOpenDBConnections)
conn.SetMaxIdleConns(10)
conn.SetMaxOpenConns(10)
return conn, nil
}

Expand All @@ -103,15 +100,14 @@ func Start(
storage *artefacts.OCIArtefactService,
adminClient ftlv1connect.AdminServiceClient,
timelineClient *timeline.Client,
conn *sql.DB,
devel bool,
) error {
config.SetDefaults()

logger := log.FromContext(ctx)
logger.Debugf("Starting FTL controller")

svc, err := New(ctx, conn, adminClient, timelineClient, storage, config, devel)
svc, err := New(ctx, adminClient, timelineClient, storage, config, devel)
if err != nil {
return err
}
Expand Down Expand Up @@ -163,7 +159,6 @@ type Service struct {

func New(
ctx context.Context,
conn *sql.DB,
adminClient ftlv1connect.AdminServiceClient,
timelineClient *timeline.Client,
storage *artefacts.OCIArtefactService,
Expand Down
5 changes: 5 additions & 0 deletions backend/provisioner/dev_provisioner.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/IBM/sarama"
"github.com/XSAM/otelsql"
"github.com/alecthomas/types/optional"
_ "github.com/go-sql-driver/mysql"

"github.com/block/ftl/common/schema"
Expand Down Expand Up @@ -129,6 +130,10 @@ func provisionPostgres(postgresPort int, recreate bool) InMemResourceProvisioner

// We assume that the DB has already been started when running in dev mode
postgresDSN := dsn.PostgresDSN("ftl", dsn.Port(postgresPort))
err := dev.SetupPostgres(ctx, optional.None[string](), postgresPort, recreate)
if err != nil {
return nil, fmt.Errorf("failed to wait for postgres to be ready: %w", err)
}

conn, err := otelsql.Open("pgx", postgresDSN)
if err != nil {
Expand Down
6 changes: 1 addition & 5 deletions cmd/ftl-controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,6 @@ func main() {
storage, err := artefacts.NewOCIRegistryStorage(cli.RegistryConfig)
kctx.FatalIfErrorf(err, "failed to create OCI registry storage")

// The FTL controller currently only supports DB as a cf provider/resolver.
conn, err := cli.ControllerConfig.OpenDBAndInstrument()
kctx.FatalIfErrorf(err)

leaseClient := rpc.Dial(leasepbconnect.NewLeaseServiceClient, cli.LeaseEndpoint.String(), log.Error)

ctx = rpc.ContextWithClient(ctx, leaseClient)
Expand All @@ -67,6 +63,6 @@ func main() {
kctx.FatalIfErrorf(err)

timelineClient := timeline.NewClient(ctx, cli.TimelineEndpoint)
err = controller.Start(ctx, cli.ControllerConfig, storage, adminClient, timelineClient, conn, false)
err = controller.Start(ctx, cli.ControllerConfig, storage, adminClient, timelineClient, false)
kctx.FatalIfErrorf(err)
}
11 changes: 0 additions & 11 deletions frontend/cli/cmd_release.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,9 @@ import (
"github.com/block/ftl/backend/controller/artefacts"
sh "github.com/block/ftl/common/sha256"
"github.com/block/ftl/common/slices"
internalobservability "github.com/block/ftl/internal/observability"
)

type releaseCmd struct {
DSN string `help:"DAL DSN." default:"postgres://127.0.0.1:15432/ftl?sslmode=disable&user=postgres&password=secret" env:"FTL_DSN"`
MaxOpenDBConnections int `help:"Maximum number of database connections." default:"20" env:"FTL_MAX_OPEN_DB_CONNECTIONS"`
MaxIdleDBConnections int `help:"Maximum number of idle database connections." default:"20" env:"FTL_MAX_IDLE_DB_CONNECTIONS"`

Publish releasePublishCmd `cmd:"" help:"Packages the project into a release and publishes it."`
Exists releaseExistsCmd `cmd:"" help:"Indicates whether modules, with the specified digests, have been published."`
Registry artefacts.RegistryConfig `embed:"" prefix:"oci-"`
Expand Down Expand Up @@ -75,12 +70,6 @@ func (d *releaseExistsCmd) Run(release *releaseCmd) error {
}

func createContainerService(release *releaseCmd) (*artefacts.OCIArtefactService, error) {
conn, err := internalobservability.OpenDBAndInstrument(release.DSN)
if err != nil {
return nil, fmt.Errorf("failed to open DB connection: %w", err)
}
conn.SetMaxIdleConns(release.MaxIdleDBConnections)
conn.SetMaxOpenConns(release.MaxOpenDBConnections)
storage, err := artefacts.NewOCIRegistryStorage(release.Registry)
if err != nil {
return nil, fmt.Errorf("failed to create OCI registry storage: %w", err)
Expand Down
15 changes: 1 addition & 14 deletions frontend/cli/cmd_serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,12 +187,6 @@ func (s *serveCommonConfig) run(
if err != nil {
return fmt.Errorf("failed to create OCI registry storage: %w", err)
}
// Bring up the DB and DAL.
dsn := dev.PostgresDSN(ctx, s.DBPort)
err = dev.SetupPostgres(ctx, optional.Some(s.DatabaseImage), s.DBPort, recreate)
if err != nil {
return err
}

wg, ctx := errgroup.WithContext(ctx)

Expand Down Expand Up @@ -255,22 +249,15 @@ func (s *serveCommonConfig) run(
CommonConfig: s.CommonConfig,
Bind: controllerAddresses[i],
Key: model.NewLocalControllerKey(i),
DSN: dsn,
}
config.SetDefaults()
config.ModuleUpdateFrequency = time.Second * 1

scope := fmt.Sprintf("controller%d", i)
controllerCtx := log.ContextWithLogger(ctx, logger.Scope(scope))

// Bring up the DB connection and DAL.
conn, err := config.OpenDBAndInstrument()
if err != nil {
return fmt.Errorf("failed to bring up DB connection: %w", err)
}

wg.Go(func() error {
if err := controller.Start(controllerCtx, config, storage, adminClient, timelineClient, conn, true); err != nil {
if err := controller.Start(controllerCtx, config, storage, adminClient, timelineClient, true); err != nil {
logger.Errorf(err, "controller%d failed: %v", i, err)
return fmt.Errorf("controller%d failed: %w", i, err)
}
Expand Down

0 comments on commit e9e1372

Please sign in to comment.