From 902abe4593b2a16e4d96b04bea782c863224e2c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Minaudier?= Date: Fri, 2 Dec 2022 00:55:05 +0100 Subject: [PATCH] Expose a new --codec-endpoint flag to start command (#174) --- cmd/temporalite/main.go | 39 ++++++++++++++++++++++++++++------ cmd/temporalite/ui.go | 26 +++++++++++++++-------- cmd/temporalite/ui_disabled.go | 2 +- cmd/temporalite/ui_test.go | 24 ++++++++++++++++++--- 4 files changed, 72 insertions(+), 19 deletions(-) diff --git a/cmd/temporalite/main.go b/cmd/temporalite/main.go index 40b517bc..68ee25f1 100644 --- a/cmd/temporalite/main.go +++ b/cmd/temporalite/main.go @@ -42,6 +42,7 @@ const ( headlessFlag = "headless" ipFlag = "ip" uiIPFlag = "ui-ip" + uiCodecEndpointFlag = "ui-codec-endpoint" logFormatFlag = "log-format" logLevelFlag = "log-level" namespaceFlag = "namespace" @@ -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) @@ -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"])`, @@ -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) { @@ -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 @@ -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 } diff --git a/cmd/temporalite/ui.go b/cmd/temporalite/ui.go index 1b41df9f..66eec50a 100644 --- a/cmd/temporalite/ui.go +++ b/cmd/temporalite/ui.go @@ -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 { @@ -32,11 +30,17 @@ 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") { @@ -44,7 +48,11 @@ func newUIConfig(frontendAddr string, uiIP string, uiPort int, configDir string) } } } - 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 } diff --git a/cmd/temporalite/ui_disabled.go b/cmd/temporalite/ui_disabled.go index d23f5867..5dfb8ff8 100644 --- a/cmd/temporalite/ui_disabled.go +++ b/cmd/temporalite/ui_disabled.go @@ -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 } diff --git a/cmd/temporalite/ui_test.go b/cmd/temporalite/ui_test.go index a8e5a8d6..4df66418 100644 --- a/cmd/temporalite/ui_test.go +++ b/cmd/temporalite/ui_test.go @@ -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 @@ -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 @@ -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