-
Notifications
You must be signed in to change notification settings - Fork 917
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add custom search attribute aliases map to namespace config #3866
Add custom search attribute aliases map to namespace config #3866
Conversation
proto/internal/temporal/server/api/persistence/v1/namespaces.proto
Outdated
Show resolved
Hide resolved
@@ -89,6 +100,10 @@ func FromPersistentState(record *persistence.GetNamespaceResponse) *Namespace { | |||
isGlobalNamespace: record.IsGlobalNamespace, | |||
failoverNotificationVersion: record.Namespace.FailoverNotificationVersion, | |||
notificationVersion: record.NotificationVersion, | |||
customSearchAttributesMapper: CustomSearchAttributesMapper{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is every 10s for every namespace. Just FYI.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm. Maybe follow up optimization to avoid calling this if there are no changes.
common/namespace/namespace.go
Outdated
func (m *CustomSearchAttributesMapper) GetAlias(fieldName string, namespace string) (string, error) { | ||
alias, ok := m.fieldToAlias[fieldName] | ||
if !ok { | ||
return "", serviceerror.NewInvalidArgument( | ||
fmt.Sprintf("Namespace %s has no mapping defined for field name %s", namespace, fieldName), | ||
) | ||
} | ||
return alias, nil | ||
} | ||
|
||
func (m *CustomSearchAttributesMapper) GetFieldName(alias string, namespace string) (string, error) { | ||
fieldName, ok := m.aliasToField[alias] | ||
if !ok { | ||
return "", serviceerror.NewInvalidArgument( | ||
fmt.Sprintf("Namespace %s has no mapping defined for search attribute %s", namespace, fieldName), | ||
) | ||
} | ||
return fieldName, nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- We should change the return type to (string, bool) because these are utility functions and the service-level functions exist higher up in the call stack
- We should remove the namespace parameter because it is not used for functionality here. Callers can dictate what the error should be and if a namespace is attached to it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For both asks, we need this way because it's part of the searchattribute.Mapper
interface.
Maybe in another follow up PR to improve it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I see
@@ -290,3 +309,27 @@ func (n Name) String() string { | |||
func (n Name) IsEmpty() bool { | |||
return n == EmptyName | |||
} | |||
|
|||
func (m *CustomSearchAttributesMapper) GetAlias(fieldName string, namespace string) (string, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider using a type alias here so that callers don't suffer from type blindness since "fieldName" and "alias" are both strings but have very different meanings
364aaf4
to
cbdb8d7
Compare
cbdb8d7
to
91e53d5
Compare
What changed?
Added custom search attributes alias mapper to namespace object.
Why?
Custom search attributes alias map is per namespace and stored in the namespace config.
This adds a mapper struct that implements
searchattribute.Mapper
interface to namespace object for easy usage.How did you test it?
Unit tests.
Potential risks
None, currently not in use.
Is hotfix candidate?
No.