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

Commit 902abe4

Browse files
authored
Expose a new --codec-endpoint flag to start command (#174)
1 parent fdc0165 commit 902abe4

File tree

4 files changed

+72
-19
lines changed

4 files changed

+72
-19
lines changed

cmd/temporalite/main.go

+33-6
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ const (
4242
headlessFlag = "headless"
4343
ipFlag = "ip"
4444
uiIPFlag = "ui-ip"
45+
uiCodecEndpointFlag = "ui-codec-endpoint"
4546
logFormatFlag = "log-format"
4647
logLevelFlag = "log-level"
4748
namespaceFlag = "namespace"
@@ -50,6 +51,14 @@ const (
5051
dynamicConfigValueFlag = "dynamic-config-value"
5152
)
5253

54+
type uiConfig struct {
55+
Host string
56+
Port int
57+
TemporalGRPCAddress string
58+
EnableUI bool
59+
CodecEndpoint string
60+
}
61+
5362
func main() {
5463
if err := buildCLI().Run(os.Args); err != nil {
5564
goLog.Fatal(err)
@@ -124,6 +133,11 @@ func buildCLI() *cli.App {
124133
Usage: `IPv4 address to bind the web UI to instead of localhost`,
125134
DefaultText: "same as --ip (eg. 127.0.0.1)",
126135
},
136+
&cli.StringFlag{
137+
Name: uiCodecEndpointFlag,
138+
Usage: `UI Remote data converter HTTP endpoint`,
139+
EnvVars: nil,
140+
},
127141
&cli.StringFlag{
128142
Name: logFormatFlag,
129143
Usage: `customize the log formatting (allowed: ["json" "pretty"])`,
@@ -198,11 +212,12 @@ func buildCLI() *cli.App {
198212
},
199213
Action: func(c *cli.Context) error {
200214
var (
201-
ip = c.String(ipFlag)
202-
serverPort = c.Int(portFlag)
203-
metricsPort = c.Int(metricsPortFlag)
204-
uiPort = serverPort + 1000
205-
uiIP = ip
215+
ip = c.String(ipFlag)
216+
serverPort = c.Int(portFlag)
217+
metricsPort = c.Int(metricsPortFlag)
218+
uiPort = serverPort + 1000
219+
uiIP = ip
220+
uiCodecEndpoint = ""
206221
)
207222

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

231+
if c.IsSet(uiCodecEndpointFlag) {
232+
uiCodecEndpoint = c.String(uiCodecEndpointFlag)
233+
}
234+
216235
pragmas, err := getPragmaMap(c.StringSlice(pragmaFlag))
217236
if err != nil {
218237
return err
@@ -257,7 +276,15 @@ func buildCLI() *cli.App {
257276
}
258277
if !c.Bool(headlessFlag) {
259278
frontendAddr := fmt.Sprintf("%s:%d", ip, serverPort)
260-
opt, err := newUIOption(frontendAddr, uiIP, uiPort, c.String(configFlag))
279+
cfg := &uiConfig{
280+
Host: uiIP,
281+
Port: uiPort,
282+
TemporalGRPCAddress: frontendAddr,
283+
EnableUI: true,
284+
CodecEndpoint: uiCodecEndpoint,
285+
}
286+
287+
opt, err := newUIOption(cfg, c.String(configFlag))
261288
if err != nil {
262289
return err
263290
}

cmd/temporalite/ui.go

+17-9
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,9 @@ import (
1919
"github.com/temporalio/temporalite"
2020
)
2121

22-
func newUIOption(frontendAddr string, uiIP string, uiPort int, configDir string) (temporalite.ServerOption, error) {
22+
func newUIOption(c *uiConfig, configDir string) (temporalite.ServerOption, error) {
2323
cfg, err := newUIConfig(
24-
frontendAddr,
25-
uiIP,
26-
uiPort,
24+
c,
2725
configDir,
2826
)
2927
if err != nil {
@@ -32,19 +30,29 @@ func newUIOption(frontendAddr string, uiIP string, uiPort int, configDir string)
3230
return temporalite.WithUI(uiserver.NewServer(uiserveroptions.WithConfigProvider(cfg))), nil
3331
}
3432

35-
func newUIConfig(frontendAddr string, uiIP string, uiPort int, configDir string) (*uiconfig.Config, error) {
33+
func newUIConfig(c *uiConfig, configDir string) (*uiconfig.Config, error) {
3634
cfg := &uiconfig.Config{
37-
Host: uiIP,
38-
Port: uiPort,
35+
Host: c.Host,
36+
Port: c.Port,
37+
TemporalGRPCAddress: c.TemporalGRPCAddress,
38+
EnableUI: c.EnableUI,
39+
Codec: uiconfig.Codec{
40+
Endpoint: c.CodecEndpoint,
41+
},
3942
}
43+
4044
if configDir != "" {
4145
if err := provider.Load(configDir, cfg, "temporalite-ui"); err != nil {
4246
if !strings.HasPrefix(err.Error(), "no config files found") {
4347
return nil, err
4448
}
4549
}
4650
}
47-
cfg.TemporalGRPCAddress = frontendAddr
48-
cfg.EnableUI = true
51+
52+
// See https://github.com/temporalio/temporalite/pull/174/files#r1035958308
53+
// for context about those overrides.
54+
cfg.TemporalGRPCAddress = c.TemporalGRPCAddress
55+
cfg.EnableUI = c.EnableUI
56+
4957
return cfg, nil
5058
}

cmd/temporalite/ui_disabled.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ package main
88

99
import "github.com/temporalio/temporalite"
1010

11-
func newUIOption(frontendAddr string, uiIP string, uiPort int, configDir string) (temporalite.ServerOption, error) {
11+
func newUIOption(c *uiConfig, configDir string) (temporalite.ServerOption, error) {
1212
return nil, nil
1313
}

cmd/temporalite/ui_test.go

+21-3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,13 @@ func TestHasUIServerDependency(t *testing.T) {
2727
}
2828

2929
func TestNewUIConfig(t *testing.T) {
30-
cfg, err := newUIConfig("localhost:7233", "localhost", 8233, "")
30+
c := &uiConfig{
31+
Host: "localhost",
32+
Port: 8233,
33+
TemporalGRPCAddress: "localhost:7233",
34+
EnableUI: true,
35+
}
36+
cfg, err := newUIConfig(c, "")
3137
if err != nil {
3238
t.Errorf("cannot create config: %s", err)
3339
return
@@ -38,7 +44,13 @@ func TestNewUIConfig(t *testing.T) {
3844
}
3945

4046
func TestNewUIConfigWithMissingConfigFile(t *testing.T) {
41-
cfg, err := newUIConfig("localhost:7233", "localhost", 8233, "wibble")
47+
c := &uiConfig{
48+
Host: "localhost",
49+
Port: 8233,
50+
TemporalGRPCAddress: "localhost:7233",
51+
EnableUI: true,
52+
}
53+
cfg, err := newUIConfig(c, "wibble")
4254
if err != nil {
4355
t.Errorf("cannot create config: %s", err)
4456
return
@@ -49,7 +61,13 @@ func TestNewUIConfigWithMissingConfigFile(t *testing.T) {
4961
}
5062

5163
func TestNewUIConfigWithPresentConfigFile(t *testing.T) {
52-
cfg, err := newUIConfig("localhost:7233", "localhost", 8233, "testdata")
64+
c := &uiConfig{
65+
Host: "localhost",
66+
Port: 8233,
67+
TemporalGRPCAddress: "localhost:7233",
68+
EnableUI: true,
69+
}
70+
cfg, err := newUIConfig(c, "testdata")
5371
if err != nil {
5472
t.Errorf("cannot create config: %s", err)
5573
return

0 commit comments

Comments
 (0)