Skip to content

Commit

Permalink
Allow dynamic config filter by namespace or task queue name only (#2858)
Browse files Browse the repository at this point in the history
  • Loading branch information
dnr committed May 20, 2022
1 parent 150516a commit 2758e29
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 16 deletions.
29 changes: 13 additions & 16 deletions common/dynamicconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,15 @@ func getFilterMap(opts ...FilterOption) map[Filter]interface{} {
return m
}

func getFilterMapsForTaskQueue(namespace string, taskQueue string, taskType enumspb.TaskQueueType) []map[Filter]interface{} {
return []map[Filter]interface{}{
getFilterMap(NamespaceFilter(namespace), TaskQueueFilter(taskQueue), TaskTypeFilter(taskType)),
getFilterMap(NamespaceFilter(namespace), TaskQueueFilter(taskQueue)),
getFilterMap(NamespaceFilter(namespace)),
getFilterMap(TaskQueueFilter(taskQueue)),
}
}

// GetIntProperty gets property and asserts that it's an integer
func (c *Collection) GetIntProperty(key Key, defaultValue int) IntPropertyFn {
return func(opts ...FilterOption) int {
Expand Down Expand Up @@ -180,10 +189,7 @@ func (c *Collection) GetIntPropertyFilteredByTaskQueueInfo(key Key, defaultValue
val := defaultValue
var err error

filterMaps := []map[Filter]interface{}{
getFilterMap(NamespaceFilter(namespace), TaskQueueFilter(taskQueue), TaskTypeFilter(taskType)),
getFilterMap(NamespaceFilter(namespace), TaskQueueFilter(taskQueue)),
}
filterMaps := getFilterMapsForTaskQueue(namespace, taskQueue, taskType)

for _, filterMap := range filterMaps {
val, err = c.client.GetIntValue(
Expand Down Expand Up @@ -266,10 +272,7 @@ func (c *Collection) GetFloatPropertyFilteredByTaskQueueInfo(key Key, defaultVal
val := defaultValue
var err error

filterMaps := []map[Filter]interface{}{
getFilterMap(NamespaceFilter(namespace), TaskQueueFilter(taskQueue), TaskTypeFilter(taskType)),
getFilterMap(NamespaceFilter(namespace), TaskQueueFilter(taskQueue)),
}
filterMaps := getFilterMapsForTaskQueue(namespace, taskQueue, taskType)

for _, filterMap := range filterMaps {
val, err = c.client.GetFloatValue(
Expand Down Expand Up @@ -332,10 +335,7 @@ func (c *Collection) GetDurationPropertyFilteredByTaskQueueInfo(key Key, default
val := defaultValue
var err error

filterMaps := []map[Filter]interface{}{
getFilterMap(NamespaceFilter(namespace), TaskQueueFilter(taskQueue), TaskTypeFilter(taskType)),
getFilterMap(NamespaceFilter(namespace), TaskQueueFilter(taskQueue)),
}
filterMaps := getFilterMapsForTaskQueue(namespace, taskQueue, taskType)

for _, filterMap := range filterMaps {
val, err = c.client.GetDurationValue(
Expand Down Expand Up @@ -462,10 +462,7 @@ func (c *Collection) GetBoolPropertyFilteredByTaskQueueInfo(key Key, defaultValu
val := defaultValue
var err error

filterMaps := []map[Filter]interface{}{
getFilterMap(NamespaceFilter(namespace), TaskQueueFilter(taskQueue), TaskTypeFilter(taskType)),
getFilterMap(NamespaceFilter(namespace), TaskQueueFilter(taskQueue)),
}
filterMaps := getFilterMapsForTaskQueue(namespace, taskQueue, taskType)

for _, filterMap := range filterMaps {
val, err = c.client.GetBoolValue(
Expand Down
3 changes: 3 additions & 0 deletions common/dynamicconfig/config/testConfig.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ testGetIntPropertyKey:
constraints:
namespace: global-samples-namespace
taskQueueName: test-tq
- value: 1005
constraints:
taskQueueName: other-test-tq
testGetMapPropertyKey:
- value:
key1: "1"
Expand Down
10 changes: 10 additions & 0 deletions common/dynamicconfig/file_based_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,16 @@ func (s *fileBasedClientSuite) TestGetIntValue_FilteredByActivityTaskQueueInfo()
s.Equal(expectedValue, v)
}

func (s *fileBasedClientSuite) TestGetIntValue_FilteredByTaskQueueNameOnly() {
expectedValue := 1005
filters := map[Filter]interface{}{
TaskQueueName: "other-test-tq",
}
v, err := s.client.GetIntValue(testGetIntPropertyKey, filters, 0)
s.NoError(err)
s.Equal(expectedValue, v)
}

func (s *fileBasedClientSuite) TestGetFloatValue() {
v, err := s.client.GetFloatValue(testGetFloat64PropertyKey, nil, 1)
s.NoError(err)
Expand Down

0 comments on commit 2758e29

Please sign in to comment.