diff --git a/common/dynamicconfig/collection.go b/common/dynamicconfig/collection.go index 5c7978ea15a..e3980b807e3 100644 --- a/common/dynamicconfig/collection.go +++ b/common/dynamicconfig/collection.go @@ -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 ( @@ -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{} { diff --git a/common/dynamicconfig/collection_test.go b/common/dynamicconfig/collection_test.go index 05e5ae680f7..cccd9ec3dfc 100644 --- a/common/dynamicconfig/collection_test.go +++ b/common/dynamicconfig/collection_test.go @@ -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 @@ -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"