Skip to content
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

Conversation

rodrigozhou
Copy link
Collaborator

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.

@rodrigozhou rodrigozhou requested a review from a team as a code owner January 30, 2023 17:56
@@ -89,6 +100,10 @@ func FromPersistentState(record *persistence.GetNamespaceResponse) *Namespace {
isGlobalNamespace: record.IsGlobalNamespace,
failoverNotificationVersion: record.Namespace.FailoverNotificationVersion,
notificationVersion: record.NotificationVersion,
customSearchAttributesMapper: CustomSearchAttributesMapper{
Copy link
Member

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.

Copy link
Collaborator Author

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.

Comment on lines 313 to 331
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
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. 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
  2. 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.

Copy link
Collaborator Author

@rodrigozhou rodrigozhou Jan 30, 2023

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.

Copy link
Contributor

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) {
Copy link
Contributor

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

@rodrigozhou rodrigozhou force-pushed the add-search-attributes-alias-namespace-config branch from 364aaf4 to cbdb8d7 Compare January 30, 2023 21:33
@rodrigozhou rodrigozhou changed the title Add custom search attributes alias map to namespace config Add custom search attribute aliases map to namespace config Jan 30, 2023
@rodrigozhou rodrigozhou force-pushed the add-search-attributes-alias-namespace-config branch from cbdb8d7 to 91e53d5 Compare January 30, 2023 22:08
@rodrigozhou rodrigozhou merged commit 7e83ca2 into temporalio:master Jan 31, 2023
@rodrigozhou rodrigozhou deleted the add-search-attributes-alias-namespace-config branch January 31, 2023 01:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants