Skip to content

Commit

Permalink
Make filter specific methods and function types for dynamic keys
Browse files Browse the repository at this point in the history
  • Loading branch information
madhuravi committed Feb 13, 2018
1 parent 34ebb20 commit 1118834
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 25 deletions.
18 changes: 9 additions & 9 deletions common/service/dynamicconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
// options right now. In the interest of keeping it minimal, we can add when requirement arises.
type Client interface {
GetValue(name Key) (interface{}, error)
GetValueWithConstraints(name Key, constraints map[ConstraintKey]interface{}) (interface{}, error)
GetValueWithFilters(name Key, filters map[Filter]interface{}) (interface{}, error)
}

type nopClient struct{}
Expand All @@ -38,8 +38,8 @@ func (mc *nopClient) GetValue(name Key) (interface{}, error) {
return nil, errors.New("unable to find key")
}

func (mc *nopClient) GetValueWithConstraints(
name Key, constraints map[ConstraintKey]interface{},
func (mc *nopClient) GetValueWithFilters(
name Key, filters map[Filter]interface{},
) (interface{}, error) {
return nil, errors.New("unable to find key")
}
Expand All @@ -59,12 +59,12 @@ type Collection struct {
client Client
}

// GetIntPropertyWithConstraints gets property based on constraints and asserts that it's an integer
func (c *Collection) GetIntPropertyWithConstraints(
key Key, defaultVal int,
) func(map[ConstraintKey]interface{}) int {
return func(constraints map[ConstraintKey]interface{}) int {
val, err := c.client.GetValue(key)
// GetIntPropertyWithTaskList gets property with taskList filter and asserts that it's an integer
func (c *Collection) GetIntPropertyWithTaskList(key Key, defaultVal int) func(string) int {
return func(taskList string) int {
filters := make(map[Filter]interface{})
filters[TaskListName] = taskList
val, err := c.client.GetValueWithFilters(key, filters)
if err != nil {
return defaultVal
}
Expand Down
4 changes: 2 additions & 2 deletions common/service/dynamicconfig/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ func (mc *inMemoryClient) GetValue(key Key) (interface{}, error) {
return nil, errors.New("unable to find key")
}

func (mc *inMemoryClient) GetValueWithConstraints(
name Key, constraints map[ConstraintKey]interface{},
func (mc *inMemoryClient) GetValueWithFilters(
name Key, filters map[Filter]interface{},
) (interface{}, error) {
return mc.GetValue(name)
}
Expand Down
14 changes: 7 additions & 7 deletions common/service/dynamicconfig/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,23 +51,23 @@ const (
HistoryLongPollExpirationInterval
)

// ConstraintKey represents a key for a constraint on the dynamic config key
type ConstraintKey int
// Filter represents a filter on the dynamic config key
type Filter int

func (k ConstraintKey) String() string {
func (k Filter) String() string {
keys := []string{
"unknownConstraintKey",
"unknownFilter",
"domainName",
"taskListName",
}
if k <= unknownConstraintKey || k > TaskListName {
return keys[unknownConstraintKey]
if k <= unknownFilter || k > TaskListName {
return keys[unknownFilter]
}
return keys[k]
}

const (
unknownConstraintKey ConstraintKey = iota
unknownFilter Filter = iota
// DomainName is the domain name
DomainName
// TaskListName is the tasklist name
Expand Down
4 changes: 2 additions & 2 deletions service/matching/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type Config struct {
GetTasksBatchSize int
UpdateAckInterval time.Duration
IdleTasklistCheckInterval time.Duration
MinTaskThrottlingBurstSize func(map[dynamicconfig.ConstraintKey]interface{}) int
MinTaskThrottlingBurstSize func(string) int

// taskWriter configuration
OutstandingTaskAppendsThreshold int
Expand All @@ -60,7 +60,7 @@ func NewConfig(dc *dynamicconfig.Collection) *Config {
IdleTasklistCheckInterval: 5 * time.Minute,
OutstandingTaskAppendsThreshold: 250,
MaxTaskBatchSize: 100,
MinTaskThrottlingBurstSize: dc.GetIntPropertyWithConstraints(
MinTaskThrottlingBurstSize: dc.GetIntPropertyWithTaskList(
dynamicconfig.MinTaskThrottlingBurstSize, 1,
),
}
Expand Down
8 changes: 3 additions & 5 deletions service/matching/taskListManager.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ import (
"sync/atomic"
"time"

"github.com/uber/cadence/common/service/dynamicconfig"

h "github.com/uber/cadence/.gen/go/history"
m "github.com/uber/cadence/.gen/go/matching"
s "github.com/uber/cadence/.gen/go/shared"
Expand Down Expand Up @@ -140,9 +138,9 @@ func newTaskListManager(
e *matchingEngineImpl, taskList *taskListID, taskListKind *s.TaskListKind, config *Config,
) taskListManager {
dPtr := _defaultTaskDispatchRPS
cnst := make(map[dynamicconfig.ConstraintKey]interface{})
cnst[dynamicconfig.TaskListName] = taskList.taskListName
rl := newRateLimiter(&dPtr, _defaultTaskDispatchRPSTTL, config.MinTaskThrottlingBurstSize(cnst))
rl := newRateLimiter(
&dPtr, _defaultTaskDispatchRPSTTL, config.MinTaskThrottlingBurstSize(taskList.taskListName),
)
return newTaskListManagerWithRateLimiter(e, taskList, taskListKind, config, rl)
}

Expand Down

0 comments on commit 1118834

Please sign in to comment.