Skip to content

Commit

Permalink
Switch to File Based Dynamic Config Client (cadence-workflow#1795)
Browse files Browse the repository at this point in the history
  • Loading branch information
yycptt authored May 6, 2019
1 parent 581dd02 commit fa5d9cc
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 8 deletions.
9 changes: 7 additions & 2 deletions cmd/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"github.com/uber/cadence/common/cluster"
"github.com/uber/cadence/common/elasticsearch"
"github.com/uber/cadence/common/log/loggerimpl"
"github.com/uber/cadence/common/log/tag"
"github.com/uber/cadence/common/messaging"
"github.com/uber/cadence/common/metrics"
"github.com/uber/cadence/common/service"
Expand Down Expand Up @@ -111,7 +112,11 @@ func (s *server) startService() common.Daemon {
log.Fatalf("error creating ringpop factory: %v", err)
}

params.DynamicConfig = dynamicconfig.NewNopClient()
params.DynamicConfig, err = dynamicconfig.NewFileBasedClient(&s.cfg.DynamicConfigClient, params.Logger.WithTags(tag.Service(params.Name)), s.doneC)
if err != nil {
log.Printf("error creating file based dynamic config client, use no-op config client instead. error: %v", err)
params.DynamicConfig = dynamicconfig.NewNopClient()
}
dc := dynamicconfig.NewCollection(params.DynamicConfig, params.Logger)

svcCfg := s.cfg.Services[s.name]
Expand Down Expand Up @@ -199,5 +204,5 @@ func (s *server) startService() common.Daemon {
// execute runs the daemon in a separate go routine
func execute(d common.Daemon, doneC chan struct{}) {
d.Start()
doneC <- struct{}{}
close(doneC)
}
3 changes: 3 additions & 0 deletions common/service/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ type (
ElasticSearch elasticsearch.Config `yaml:"elasticsearch"`
// 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
DynamicConfigClient dynamicconfig.FileBasedClientConfig `yaml:"dynamicConfigClient"`
}

// Service contains the service specific config items
Expand Down
10 changes: 4 additions & 6 deletions common/service/dynamicconfig/fileBasedClient.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ type constrainedValue struct {
// It specifies where the config file is stored and how often the config should be
// updated by checking the config file again.
type FileBasedClientConfig struct {
Filepath string
PollInterval time.Duration
Filepath string `yaml:"filepath"`
PollInterval time.Duration `yaml:"pollInterval"`
}

type fileBasedClient struct {
Expand Down Expand Up @@ -79,9 +79,7 @@ func NewFileBasedClient(config *FileBasedClientConfig, logger log.Logger, doneCh
case <-ticker.C:
err := client.update()
if err != nil {
client.logger.Error("Failed to update dynamic config", tag.Timestamp(time.Now()))
} else {
client.logger.Info("Updated dynamic config", tag.Timestamp(time.Now()))
client.logger.Error("Failed to update dynamic config", tag.Error(err))
}
case <-client.doneCh:
ticker.Stop()
Expand Down Expand Up @@ -220,7 +218,7 @@ func (fc *fileBasedClient) update() error {
}

fc.values.Store(newValues)

fc.logger.Info("Updated dynamic config")
return nil
}

Expand Down
4 changes: 4 additions & 0 deletions config/development.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,7 @@ elasticsearch:
publicClient:
hostPort: "127.0.0.1:7933"

dynamicConfigClient:
filepath: "config/dynamicconfig/development.yaml"
pollInterval: "10s"

37 changes: 37 additions & 0 deletions config/dynamicconfig/development.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Use this file to override the default dynamic config value (they are specified
# when creating the service config).

# Each key can have zero or more values and each value can have zero or more
# constraints. There are only three types of constraint:
# 1. domainName: string
# 2. taskListName: string
# 3. taskType: int (0:Decision, 1:Activity)
# A value will be selected and returned if all its has exactly the same constraints
# as the ones specified in query filters (including the number of constraints).

# Please use the following format:
# testGetBoolPropertyKey:
# - value: false
# - value: true
# constraints:
# domainName: "global-samples-domain"
# - value: false
# constraints:
# domainName: "samples-domain"
# testGetDurationPropertyKey:
# - value: "1m"
# constraints:
# domainName: "samples-domain"
# taskListName: "longIdleTimeTasklist"
# testGetFloat64PropertyKey:
# - value: 12.0
# constraints:
# domainName: "samples-domain"
# testGetMapPropertyKey:
# - value:
# key1: 1
# key2: "value 2"
# key3:
# - false
# - key4: true
# key5: 2.0

0 comments on commit fa5d9cc

Please sign in to comment.