Skip to content

Commit

Permalink
Add string dynamic config filter by namespace id (#4523)
Browse files Browse the repository at this point in the history
  • Loading branch information
codemonkeycxy authored Jun 21, 2023
1 parent 198f0e4 commit f2fb098
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
14 changes: 14 additions & 0 deletions common/dynamicconfig/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ type (
MapPropertyFnWithNamespaceFilter func(namespace string) map[string]any
StringPropertyFn func() string
StringPropertyFnWithNamespaceFilter func(namespace string) string
StringPropertyFnWithNamespaceIDFilter func(namespaceID string) string
)

const (
Expand Down Expand Up @@ -347,6 +348,19 @@ func (c *Collection) GetStringPropertyFnWithNamespaceFilter(key Key, defaultValu
}
}

// GetStringPropertyFnWithNamespaceIDFilter gets property with namespace ID filter and asserts that it's a string
func (c *Collection) GetStringPropertyFnWithNamespaceIDFilter(key Key, defaultValue any) StringPropertyFnWithNamespaceIDFilter {
return func(namespaceID string) string {
return matchAndConvert(
c,
key,
defaultValue,
namespaceIDPrecedence(namespaceID),
convertString,
)
}
}

// GetMapPropertyFnWithNamespaceFilter gets property and asserts that it's a map
func (c *Collection) GetMapPropertyFnWithNamespaceFilter(key Key, defaultValue any) MapPropertyFnWithNamespaceFilter {
return func(namespace string) map[string]interface{} {
Expand Down
9 changes: 9 additions & 0 deletions common/dynamicconfig/collection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const (
testGetDurationPropertyStructuredDefaults = "testGetDurationPropertyStructuredDefaults"
testGetBoolPropertyFilteredByNamespaceIDKey = "testGetBoolPropertyFilteredByNamespaceIDKey"
testGetBoolPropertyFilteredByTaskQueueInfoKey = "testGetBoolPropertyFilteredByTaskQueueInfoKey"
testGetStringPropertyFilteredByNamespaceIDKey = "testGetStringPropertyFilteredByNamespaceIDKey"
)

// Note: fileBasedClientSuite also heavily tests Collection, since some tests are easier with data
Expand Down Expand Up @@ -97,6 +98,14 @@ func (s *collectionSuite) TestGetStringPropertyFnWithNamespaceFilter() {
s.Equal("efg", value(namespace))
}

func (s *collectionSuite) TestGetStringPropertyFnWithNamespaceIDFilter() {
namespaceID := "testNamespaceID"
value := s.cln.GetStringPropertyFnWithNamespaceIDFilter(testGetStringPropertyFilteredByNamespaceIDKey, "abc")
s.Equal("abc", value(namespaceID))
s.client[testGetStringPropertyFilteredByNamespaceIDKey] = "efg"
s.Equal("efg", value(namespaceID))
}

func (s *collectionSuite) TestGetIntPropertyFilteredByTaskQueueInfo() {
namespace := "testNamespace"
taskQueue := "testTaskQueue"
Expand Down

0 comments on commit f2fb098

Please sign in to comment.