Skip to content

Commit

Permalink
Fix missing root dir prefix when loading dynamic config (cadence-work…
Browse files Browse the repository at this point in the history
…flow#4056)

* Fix missing root dir prefix when loading dynamic config

The cadence server would fail to load the dynamic config file
when the working dir wasn't the parent dir of dynamic config
file path.

* Fix don't append the root dir when the dynamic file path was absolute

* run buildkite test

sorry I have to edit something to hack around buildkite

Co-authored-by: Quanzheng Long <longquanzheng@users.noreply.github.com>
  • Loading branch information
git-hulk and longquanzheng authored Mar 19, 2021
1 parent ed82bb7 commit a3708fb
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
16 changes: 12 additions & 4 deletions cmd/server/cadence/cadence.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"log"
"os"
"os/signal"
"path/filepath"
"strings"
"syscall"

Expand All @@ -43,6 +44,7 @@ func startHandler(c *cli.Context) {
env := getEnvironment(c)
zone := getZone(c)
configDir := getConfigDir(c)
rootDir := getRootDir(c)

log.Printf("Loading config; env=%v,zone=%v,configDir=%v\n", env, zone, configDir)

Expand All @@ -54,6 +56,7 @@ func startHandler(c *cli.Context) {
if cfg.Log.Level == "debug" {
log.Printf("config=\n%v\n", cfg.String())
}
cfg.DynamicConfigClient.Filepath = constructPathIfNeed(rootDir, cfg.DynamicConfigClient.Filepath)

if err := cfg.ValidateAndFillDefaults(); err != nil {
log.Fatalf("config validation failed: %v", err)
Expand Down Expand Up @@ -130,7 +133,7 @@ func isValidService(in string) bool {
}

func getConfigDir(c *cli.Context) string {
return constructPath(getRootDir(c), c.GlobalString("config"))
return constructPathIfNeed(getRootDir(c), c.GlobalString("config"))
}

func getRootDir(c *cli.Context) string {
Expand All @@ -145,8 +148,13 @@ func getRootDir(c *cli.Context) string {
return dirpath
}

func constructPath(dir string, file string) string {
return dir + "/" + file
// constructPathIfNeed would append the dir as the root dir
// when the file wasn't absolute path.
func constructPathIfNeed(dir string, file string) string {
if !filepath.IsAbs(file) {
return dir + "/" + file
}
return file
}

// BuildCLI is the main entry point for the cadence server
Expand All @@ -167,7 +175,7 @@ func BuildCLI() *cli.App {
cli.StringFlag{
Name: "config, c",
Value: "config",
Usage: "config dir path relative to root",
Usage: "config dir is a path relative to root, or an absolute path",
EnvVar: config.EnvKeyConfigDir,
},
cli.StringFlag{
Expand Down
3 changes: 2 additions & 1 deletion cmd/server/cadence/cadence_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,6 @@ func (s *CadenceSuite) TestIsValidService() {
}

func (s *CadenceSuite) TestPath() {
s.Equal("foo/bar", constructPath("foo", "bar"))
s.Equal("foo/bar", constructPathIfNeed("foo", "bar"))
s.Equal("/bar", constructPathIfNeed("foo", "/bar"))
}
2 changes: 1 addition & 1 deletion common/service/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ type (
// PublicClient is config for connecting to cadence frontend
PublicClient PublicClient `yaml:"publicClient"`
// DynamicConfigClient is the config for setting up the file based dynamic config client
// Filepath should be relative to the root directory
// Filepath would be relative to the root directory when the path wasn't absolute.
DynamicConfigClient dynamicconfig.FileBasedClientConfig `yaml:"dynamicConfigClient"`
// DomainDefaults is the default config for every domain
DomainDefaults DomainDefaults `yaml:"domainDefaults"`
Expand Down

0 comments on commit a3708fb

Please sign in to comment.