Skip to content

Commit

Permalink
Refactor dynamic config (uber#4863)
Browse files Browse the repository at this point in the history
* Refactor dynamic config

* Change dynamic client interface
  • Loading branch information
Shaddoll authored Jun 29, 2022
1 parent aff5ecf commit 650cf8a
Show file tree
Hide file tree
Showing 48 changed files with 4,186 additions and 2,587 deletions.
10 changes: 5 additions & 5 deletions client/clientfactory.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func (cf *rpcClientFactory) NewHistoryClientWithTimeout(timeout time.Duration) (
peerResolver := history.NewPeerResolver(cf.numberOfHistoryShards, cf.resolver, namedPort)

supportedMessageSize := cf.rpcFactory.GetMaxMessageSize()
maxSizeConfig := cf.dynConfig.GetIntProperty(dynamicconfig.GRPCMaxSizeInByte, 4*1024*1024)
maxSizeConfig := cf.dynConfig.GetIntProperty(dynamicconfig.GRPCMaxSizeInByte)
if maxSizeConfig() > supportedMessageSize {
return nil, fmt.Errorf(
"GRPCMaxSizeInByte dynamic config value %v is larger than supported value %v",
Expand All @@ -133,7 +133,7 @@ func (cf *rpcClientFactory) NewHistoryClientWithTimeout(timeout time.Duration) (
peerResolver,
cf.logger,
)
if errorRate := cf.dynConfig.GetFloat64Property(dynamicconfig.HistoryErrorInjectionRate, 0)(); errorRate != 0 {
if errorRate := cf.dynConfig.GetFloat64Property(dynamicconfig.HistoryErrorInjectionRate)(); errorRate != 0 {
client = history.NewErrorInjectionClient(client, errorRate, cf.logger)
}
if cf.metricsClient != nil {
Expand Down Expand Up @@ -166,7 +166,7 @@ func (cf *rpcClientFactory) NewMatchingClientWithTimeout(
peerResolver,
matching.NewLoadBalancer(domainIDToName, cf.dynConfig),
)
if errorRate := cf.dynConfig.GetFloat64Property(dynamicconfig.MatchingErrorInjectionRate, 0)(); errorRate != 0 {
if errorRate := cf.dynConfig.GetFloat64Property(dynamicconfig.MatchingErrorInjectionRate)(); errorRate != 0 {
client = matching.NewErrorInjectionClient(client, errorRate, cf.logger)
}
if cf.metricsClient != nil {
Expand All @@ -189,7 +189,7 @@ func (cf *rpcClientFactory) NewAdminClientWithTimeoutAndConfig(
}

client = admin.NewClient(timeout, largeTimeout, client)
if errorRate := cf.dynConfig.GetFloat64Property(dynamicconfig.AdminErrorInjectionRate, 0)(); errorRate != 0 {
if errorRate := cf.dynConfig.GetFloat64Property(dynamicconfig.AdminErrorInjectionRate)(); errorRate != 0 {
client = admin.NewErrorInjectionClient(client, errorRate, cf.logger)
}
if cf.metricsClient != nil {
Expand All @@ -216,7 +216,7 @@ func (cf *rpcClientFactory) NewFrontendClientWithTimeoutAndConfig(
}

client = frontend.NewClient(timeout, longPollTimeout, client)
if errorRate := cf.dynConfig.GetFloat64Property(dynamicconfig.FrontendErrorInjectionRate, 0)(); errorRate != 0 {
if errorRate := cf.dynConfig.GetFloat64Property(dynamicconfig.FrontendErrorInjectionRate)(); errorRate != 0 {
client = frontend.NewErrorInjectionClient(client, errorRate, cf.logger)
}
if cf.metricsClient != nil {
Expand Down
4 changes: 2 additions & 2 deletions client/matching/loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ func NewLoadBalancer(
) LoadBalancer {
return &defaultLoadBalancer{
domainIDToName: domainIDToName,
nReadPartitions: dc.GetIntPropertyFilteredByTaskListInfo(dynamicconfig.MatchingNumTasklistReadPartitions, 1),
nWritePartitions: dc.GetIntPropertyFilteredByTaskListInfo(dynamicconfig.MatchingNumTasklistWritePartitions, 1),
nReadPartitions: dc.GetIntPropertyFilteredByTaskListInfo(dynamicconfig.MatchingNumTasklistReadPartitions),
nWritePartitions: dc.GetIntPropertyFilteredByTaskListInfo(dynamicconfig.MatchingNumTasklistWritePartitions),
}
}

Expand Down
5 changes: 2 additions & 3 deletions cmd/server/cadence/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ func (s *server) startService() common.Daemon {

advancedVisMode := dc.GetStringProperty(
dynamicconfig.AdvancedVisibilityWritingMode,
common.AdvancedVisibilityWritingModeOn,
)()
isAdvancedVisEnabled := common.IsAdvancedVisibilityWritingEnabled(advancedVisMode, params.PersistenceConfig.IsAdvancedVisibilityConfigExist())
if isAdvancedVisEnabled {
Expand Down Expand Up @@ -252,8 +251,8 @@ func (s *server) startService() common.Daemon {
)

params.ArchiverProvider = provider.NewArchiverProvider(s.cfg.Archival.History.Provider, s.cfg.Archival.Visibility.Provider)
params.PersistenceConfig.TransactionSizeLimit = dc.GetIntProperty(dynamicconfig.TransactionSizeLimit, common.DefaultTransactionSizeLimit)
params.PersistenceConfig.ErrorInjectionRate = dc.GetFloat64Property(dynamicconfig.PersistenceErrorInjectionRate, 0)
params.PersistenceConfig.TransactionSizeLimit = dc.GetIntProperty(dynamicconfig.TransactionSizeLimit)
params.PersistenceConfig.ErrorInjectionRate = dc.GetFloat64Property(dynamicconfig.PersistenceErrorInjectionRate)
params.AuthorizationConfig = s.cfg.Authorization
params.BlobstoreClient, err = filestore.NewFilestoreClient(s.cfg.Blobstore.Filestore)
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions common/archiver/archivalMetadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,18 +86,18 @@ func NewArchivalMetadata(
) ArchivalMetadata {
historyConfig := NewArchivalConfig(
historyStatus,
dc.GetStringProperty(dynamicconfig.HistoryArchivalStatus, common.ArchivalEnabled),
dc.GetStringProperty(dynamicconfig.HistoryArchivalStatus),
historyReadEnabled,
dc.GetBoolProperty(dynamicconfig.EnableReadFromHistoryArchival, true),
dc.GetBoolProperty(dynamicconfig.EnableReadFromHistoryArchival),
domainDefaults.History.Status,
domainDefaults.History.URI,
)

visibilityConfig := NewArchivalConfig(
visibilityStatus,
dc.GetStringProperty(dynamicconfig.VisibilityArchivalStatus, common.ArchivalEnabled),
dc.GetStringProperty(dynamicconfig.VisibilityArchivalStatus),
visibilityReadEnabled,
dc.GetBoolProperty(dynamicconfig.EnableReadFromVisibilityArchival, true),
dc.GetBoolProperty(dynamicconfig.EnableReadFromVisibilityArchival),
domainDefaults.Visibility.Status,
domainDefaults.Visibility.URI,
)
Expand Down
32 changes: 30 additions & 2 deletions common/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,6 @@ const (
SystemLocalDomainName = "cadence-system"
// SystemDomainRetentionDays is retention config for all cadence system workflows
SystemDomainRetentionDays = 7
// DefaultAdminOperationToken is the default dynamic config value for AdminOperationToken
DefaultAdminOperationToken = "CadenceTeamONLY"
// BatcherDomainID is domain id for batcher local domain
BatcherDomainID = "3116607e-419b-4783-85fc-47726a4c3fe9"
// BatcherLocalDomainName is domain name for batcher workflows running in local cluster
Expand Down Expand Up @@ -231,3 +229,33 @@ const (
RecordClosed VisibilityOperation = "RecordClosed"
UpsertSearchAttributes VisibilityOperation = "UpsertSearchAttributes"
)

const (
numBitsPerLevel = 3

// NoPriority is the value returned if no priority is ever assigned to the task
NoPriority = -1
)

const (
// HighPriorityClass is the priority class for high priority tasks
HighPriorityClass = iota << numBitsPerLevel
// DefaultPriorityClass is the priority class for default priority tasks
DefaultPriorityClass
// LowPriorityClass is the priority class for low priority tasks
LowPriorityClass
)

const (
// HighPrioritySubclass is the priority subclass for high priority tasks
HighPrioritySubclass = iota
// DefaultPrioritySubclass is the priority subclass for high priority tasks
DefaultPrioritySubclass
// LowPrioritySubclass is the priority subclass for high priority tasks
LowPrioritySubclass
)

const (
// DefaultHistoryMaxAutoResetPoints is the default maximum number for auto reset points
DefaultHistoryMaxAutoResetPoints = 20
)
37 changes: 0 additions & 37 deletions common/domain/const.go

This file was deleted.

22 changes: 9 additions & 13 deletions common/dynamicconfig/clientInterface.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,15 @@ const (
// Client allows fetching values from a dynamic configuration system NOTE: This does not have async
// options right now. In the interest of keeping it minimal, we can add when requirement arises.
type Client interface {
GetValue(name Key, defaultValue interface{}) (interface{}, error)
GetValueWithFilters(name Key, filters map[Filter]interface{}, defaultValue interface{}) (interface{}, error)

GetIntValue(name Key, filters map[Filter]interface{}, defaultValue int) (int, error)
GetFloatValue(name Key, filters map[Filter]interface{}, defaultValue float64) (float64, error)
GetBoolValue(name Key, filters map[Filter]interface{}, defaultValue bool) (bool, error)
GetStringValue(name Key, filters map[Filter]interface{}, defaultValue string) (string, error)
GetMapValue(
name Key, filters map[Filter]interface{}, defaultValue map[string]interface{},
) (map[string]interface{}, error)
GetDurationValue(
name Key, filters map[Filter]interface{}, defaultValue time.Duration,
) (time.Duration, error)
GetValue(name Key) (interface{}, error)
GetValueWithFilters(name Key, filters map[Filter]interface{}) (interface{}, error)

GetIntValue(name IntKey, filters map[Filter]interface{}) (int, error)
GetFloatValue(name FloatKey, filters map[Filter]interface{}) (float64, error)
GetBoolValue(name BoolKey, filters map[Filter]interface{}) (bool, error)
GetStringValue(name StringKey, filters map[Filter]interface{}) (string, error)
GetMapValue(name MapKey, filters map[Filter]interface{}) (map[string]interface{}, error)
GetDurationValue(name DurationKey, filters map[Filter]interface{}) (time.Duration, error)
// UpdateValue takes value as map and updates by overriding. It doesn't support update with filters.
UpdateValue(name Key, value interface{}) error
RestoreValue(name Key, filters map[Filter]interface{}) error
Expand Down
64 changes: 32 additions & 32 deletions common/dynamicconfig/clientInterface_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 650cf8a

Please sign in to comment.