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

Expose a new --codec-endpoint flag to start command #174

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 28 additions & 6 deletions cmd/temporalite/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"path/filepath"
"strings"

uiconfig "github.com/temporalio/ui-server/v2/server/config"
"github.com/urfave/cli/v2"
"go.temporal.io/server/common/config"
"go.temporal.io/server/common/dynamicconfig"
Expand Down Expand Up @@ -42,6 +43,7 @@ const (
headlessFlag = "headless"
ipFlag = "ip"
uiIPFlag = "ui-ip"
uiCodecEndpointFlag = "ui-codec-endpoint"
logFormatFlag = "log-format"
logLevelFlag = "log-level"
namespaceFlag = "namespace"
Expand Down Expand Up @@ -124,6 +126,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 +205,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 +221,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 +269,17 @@ 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.Config{
Host: uiIP,
Port: uiPort,
TemporalGRPCAddress: frontendAddr,
EnableUI: true,
Codec: uiconfig.Codec{
Endpoint: uiCodecEndpoint,
},
}

opt, err := newUIOption(cfg, c.String(configFlag))
if err != nil {
return err
}
Expand Down
21 changes: 11 additions & 10 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.Config, configDir string) (temporalite.ServerOption, error) {
cfg, err := newUIConfig(
frontendAddr,
uiIP,
uiPort,
c,
configDir,
)
if err != nil {
Expand All @@ -32,19 +30,22 @@ 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) {
cfg := &uiconfig.Config{
Host: uiIP,
Port: uiPort,
}
func newUIConfig(cfg *uiconfig.Config, configDir string) (*uiconfig.Config, error) {
frontendAddr := cfg.TemporalGRPCAddress
enabledUi := cfg.EnableUI

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

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

return cfg, nil
}
26 changes: 23 additions & 3 deletions cmd/temporalite/ui_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ package main
import (
"runtime/debug"
"testing"

uiconfig "github.com/temporalio/ui-server/v2/server/config"
)

// This test ensures that ui-server is a dependency of Temporalite built in non-headless mode.
Expand All @@ -27,7 +29,13 @@ func TestHasUIServerDependency(t *testing.T) {
}

func TestNewUIConfig(t *testing.T) {
cfg, err := newUIConfig("localhost:7233", "localhost", 8233, "")
c := &uiconfig.Config{
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 +46,13 @@ func TestNewUIConfig(t *testing.T) {
}

func TestNewUIConfigWithMissingConfigFile(t *testing.T) {
cfg, err := newUIConfig("localhost:7233", "localhost", 8233, "wibble")
c := &uiconfig.Config{
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 +63,13 @@ func TestNewUIConfigWithMissingConfigFile(t *testing.T) {
}

func TestNewUIConfigWithPresentConfigFile(t *testing.T) {
cfg, err := newUIConfig("localhost:7233", "localhost", 8233, "testdata")
c := &uiconfig.Config{
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