Skip to content
This repository has been archived by the owner on Apr 3, 2024. It is now read-only.

Commit

Permalink
Expose a new --codec-endpoint flag to start command (#174)
Browse files Browse the repository at this point in the history
  • Loading branch information
lminaudier authored Dec 1, 2022
1 parent fdc0165 commit 902abe4
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 19 deletions.
39 changes: 33 additions & 6 deletions cmd/temporalite/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const (
headlessFlag = "headless"
ipFlag = "ip"
uiIPFlag = "ui-ip"
uiCodecEndpointFlag = "ui-codec-endpoint"
logFormatFlag = "log-format"
logLevelFlag = "log-level"
namespaceFlag = "namespace"
Expand All @@ -50,6 +51,14 @@ const (
dynamicConfigValueFlag = "dynamic-config-value"
)

type uiConfig struct {
Host string
Port int
TemporalGRPCAddress string
EnableUI bool
CodecEndpoint string
}

func main() {
if err := buildCLI().Run(os.Args); err != nil {
goLog.Fatal(err)
Expand Down Expand Up @@ -124,6 +133,11 @@ func buildCLI() *cli.App {
Usage: `IPv4 address to bind the web UI to instead of localhost`,
DefaultText: "same as --ip (eg. 127.0.0.1)",
},
&cli.StringFlag{
Name: uiCodecEndpointFlag,
Usage: `UI Remote data converter HTTP endpoint`,
EnvVars: nil,
},
&cli.StringFlag{
Name: logFormatFlag,
Usage: `customize the log formatting (allowed: ["json" "pretty"])`,
Expand Down Expand Up @@ -198,11 +212,12 @@ func buildCLI() *cli.App {
},
Action: func(c *cli.Context) error {
var (
ip = c.String(ipFlag)
serverPort = c.Int(portFlag)
metricsPort = c.Int(metricsPortFlag)
uiPort = serverPort + 1000
uiIP = ip
ip = c.String(ipFlag)
serverPort = c.Int(portFlag)
metricsPort = c.Int(metricsPortFlag)
uiPort = serverPort + 1000
uiIP = ip
uiCodecEndpoint = ""
)

if c.IsSet(uiPortFlag) {
Expand All @@ -213,6 +228,10 @@ func buildCLI() *cli.App {
uiIP = c.String(uiIPFlag)
}

if c.IsSet(uiCodecEndpointFlag) {
uiCodecEndpoint = c.String(uiCodecEndpointFlag)
}

pragmas, err := getPragmaMap(c.StringSlice(pragmaFlag))
if err != nil {
return err
Expand Down Expand Up @@ -257,7 +276,15 @@ func buildCLI() *cli.App {
}
if !c.Bool(headlessFlag) {
frontendAddr := fmt.Sprintf("%s:%d", ip, serverPort)
opt, err := newUIOption(frontendAddr, uiIP, uiPort, c.String(configFlag))
cfg := &uiConfig{
Host: uiIP,
Port: uiPort,
TemporalGRPCAddress: frontendAddr,
EnableUI: true,
CodecEndpoint: uiCodecEndpoint,
}

opt, err := newUIOption(cfg, c.String(configFlag))
if err != nil {
return err
}
Expand Down
26 changes: 17 additions & 9 deletions cmd/temporalite/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,9 @@ import (
"github.com/temporalio/temporalite"
)

func newUIOption(frontendAddr string, uiIP string, uiPort int, configDir string) (temporalite.ServerOption, error) {
func newUIOption(c *uiConfig, configDir string) (temporalite.ServerOption, error) {
cfg, err := newUIConfig(
frontendAddr,
uiIP,
uiPort,
c,
configDir,
)
if err != nil {
Expand All @@ -32,19 +30,29 @@ func newUIOption(frontendAddr string, uiIP string, uiPort int, configDir string)
return temporalite.WithUI(uiserver.NewServer(uiserveroptions.WithConfigProvider(cfg))), nil
}

func newUIConfig(frontendAddr string, uiIP string, uiPort int, configDir string) (*uiconfig.Config, error) {
func newUIConfig(c *uiConfig, configDir string) (*uiconfig.Config, error) {
cfg := &uiconfig.Config{
Host: uiIP,
Port: uiPort,
Host: c.Host,
Port: c.Port,
TemporalGRPCAddress: c.TemporalGRPCAddress,
EnableUI: c.EnableUI,
Codec: uiconfig.Codec{
Endpoint: c.CodecEndpoint,
},
}

if configDir != "" {
if err := provider.Load(configDir, cfg, "temporalite-ui"); err != nil {
if !strings.HasPrefix(err.Error(), "no config files found") {
return nil, err
}
}
}
cfg.TemporalGRPCAddress = frontendAddr
cfg.EnableUI = true

// See https://github.com/temporalio/temporalite/pull/174/files#r1035958308
// for context about those overrides.
cfg.TemporalGRPCAddress = c.TemporalGRPCAddress
cfg.EnableUI = c.EnableUI

return cfg, nil
}
2 changes: 1 addition & 1 deletion cmd/temporalite/ui_disabled.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ package main

import "github.com/temporalio/temporalite"

func newUIOption(frontendAddr string, uiIP string, uiPort int, configDir string) (temporalite.ServerOption, error) {
func newUIOption(c *uiConfig, configDir string) (temporalite.ServerOption, error) {
return nil, nil
}
24 changes: 21 additions & 3 deletions cmd/temporalite/ui_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,13 @@ func TestHasUIServerDependency(t *testing.T) {
}

func TestNewUIConfig(t *testing.T) {
cfg, err := newUIConfig("localhost:7233", "localhost", 8233, "")
c := &uiConfig{
Host: "localhost",
Port: 8233,
TemporalGRPCAddress: "localhost:7233",
EnableUI: true,
}
cfg, err := newUIConfig(c, "")
if err != nil {
t.Errorf("cannot create config: %s", err)
return
Expand All @@ -38,7 +44,13 @@ func TestNewUIConfig(t *testing.T) {
}

func TestNewUIConfigWithMissingConfigFile(t *testing.T) {
cfg, err := newUIConfig("localhost:7233", "localhost", 8233, "wibble")
c := &uiConfig{
Host: "localhost",
Port: 8233,
TemporalGRPCAddress: "localhost:7233",
EnableUI: true,
}
cfg, err := newUIConfig(c, "wibble")
if err != nil {
t.Errorf("cannot create config: %s", err)
return
Expand All @@ -49,7 +61,13 @@ func TestNewUIConfigWithMissingConfigFile(t *testing.T) {
}

func TestNewUIConfigWithPresentConfigFile(t *testing.T) {
cfg, err := newUIConfig("localhost:7233", "localhost", 8233, "testdata")
c := &uiConfig{
Host: "localhost",
Port: 8233,
TemporalGRPCAddress: "localhost:7233",
EnableUI: true,
}
cfg, err := newUIConfig(c, "testdata")
if err != nil {
t.Errorf("cannot create config: %s", err)
return
Expand Down

0 comments on commit 902abe4

Please sign in to comment.