From 4f0c5a7a7984bd27bf15f958ad7e860e4a358ee0 Mon Sep 17 00:00:00 2001 From: Jacob LeGrone Date: Fri, 10 Mar 2023 16:40:50 -0500 Subject: [PATCH] Always use dynamic ports --- temporal/temporalite/config.go | 32 +++++++++----------------------- temporal/temporalite/options.go | 8 -------- temporal/temporaltest/server.go | 1 - 3 files changed, 9 insertions(+), 32 deletions(-) diff --git a/temporal/temporalite/config.go b/temporal/temporalite/config.go index b3269bdb5b68..62ce5b34bbaa 100644 --- a/temporal/temporalite/config.go +++ b/temporal/temporalite/config.go @@ -50,7 +50,6 @@ func newDefaultConfig() (*temporaliteConfig, error) { DatabaseFilePath: filepath.Join(userConfigDir, "temporalite", "db", "default.db"), FrontendPort: 0, MetricsPort: 0, - DynamicPorts: false, Namespaces: nil, SQLitePragmas: nil, Logger: log.NewZapLogger(log.BuildZapLogger(log.Config{ @@ -88,24 +87,13 @@ func convertLiteConfig(cfg *temporaliteConfig) *config.Config { sqliteConfig.ConnectAttributes["_"+k] = v } - var pprofPort int - if cfg.DynamicPorts { - if cfg.FrontendPort == 0 { - cfg.FrontendPort = cfg.portProvider.MustGetFreePort() - } - if cfg.MetricsPort == 0 { - cfg.MetricsPort = cfg.portProvider.MustGetFreePort() - } - pprofPort = cfg.portProvider.MustGetFreePort() - } else { - if cfg.FrontendPort == 0 { - cfg.FrontendPort = defaultFrontendPort - } - if cfg.MetricsPort == 0 { - cfg.MetricsPort = cfg.FrontendPort + 200 - } - pprofPort = cfg.FrontendPort + 201 + if cfg.FrontendPort == 0 { + cfg.FrontendPort = cfg.portProvider.MustGetFreePort() + } + if cfg.MetricsPort == 0 { + cfg.MetricsPort = cfg.portProvider.MustGetFreePort() } + pprofPort := cfg.portProvider.MustGetFreePort() baseConfig := cfg.BaseConfig baseConfig.Global.Membership = config.Membership{ @@ -189,12 +177,10 @@ func (cfg *temporaliteConfig) mustGetService(frontendPortOffset int) config.Serv } // Assign any open port when configured to use dynamic ports - if cfg.DynamicPorts { - if frontendPortOffset != 0 { - svc.RPC.GRPCPort = cfg.portProvider.MustGetFreePort() - } - svc.RPC.MembershipPort = cfg.portProvider.MustGetFreePort() + if frontendPortOffset != 0 { + svc.RPC.GRPCPort = cfg.portProvider.MustGetFreePort() } + svc.RPC.MembershipPort = cfg.portProvider.MustGetFreePort() // Optionally bind frontend to IPv4 address if frontendPortOffset == 0 && cfg.FrontendIP != "" { diff --git a/temporal/temporalite/options.go b/temporal/temporalite/options.go index 6ec92dd142a7..b941f0a4b4b2 100644 --- a/temporal/temporalite/options.go +++ b/temporal/temporalite/options.go @@ -24,7 +24,6 @@ type temporaliteConfig struct { // // When unspecified, the port will be system-chosen. MetricsPort int - DynamicPorts bool Namespaces []string SQLitePragmas map[string]string // Logger overrides the default logger. @@ -91,13 +90,6 @@ func WithFrontendIP(address string) ServerOption { }) } -// WithDynamicPorts starts Temporal on system-chosen ports. -func WithDynamicPorts() Option { - return newApplyFuncContainer(func(cfg *temporaliteConfig) { - cfg.DynamicPorts = true - }) -} - // WithNamespaces registers each namespace on Temporal start. func WithNamespaces(namespaces ...string) ServerOption { return newApplyFuncContainer(func(cfg *temporaliteConfig) { diff --git a/temporal/temporaltest/server.go b/temporal/temporaltest/server.go index 4920bd8ccb21..836567535cb2 100644 --- a/temporal/temporaltest/server.go +++ b/temporal/temporaltest/server.go @@ -152,7 +152,6 @@ func NewServer(opts ...TestServerOption) *TestServer { ts.serverOptions = append(ts.serverOptions, temporalite.WithNamespaces(ts.defaultTestNamespace), temporalite.WithPersistenceDisabled(), - temporalite.WithDynamicPorts(), temporalite.WithLogger(log.NewNoopLogger()), temporalite.WithSearchAttributeCacheDisabled(), // Disable "accept incoming network connections?" prompt on macOS