Skip to content

Commit

Permalink
Always use dynamic ports
Browse files Browse the repository at this point in the history
  • Loading branch information
jlegrone committed Mar 10, 2023
1 parent 5b0d733 commit 4f0c5a7
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 32 deletions.
32 changes: 9 additions & 23 deletions temporal/temporalite/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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 != "" {
Expand Down
8 changes: 0 additions & 8 deletions temporal/temporalite/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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) {
Expand Down
1 change: 0 additions & 1 deletion temporal/temporaltest/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4f0c5a7

Please sign in to comment.