-
Notifications
You must be signed in to change notification settings - Fork 874
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
Clone request if search attributes are mapped #3299
Clone request if search attributes are mapped #3299
Conversation
c02da29
to
b95ff74
Compare
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 pretty ugly. I think this is one spot where I'd be okay with a little reflection (unfortunately generics won't do it yet). But maybe I'll look into it later
service/frontend/workflow_handler.go
Outdated
} | ||
|
||
func (wh *WorkflowHandler) mapCreateScheduleRequestStartWorkflowSearchAttributes(request *workflowservice.CreateScheduleRequest, namespaceName namespace.Name) (*workflowservice.CreateScheduleRequest, error) { | ||
if startWorkflow := request.GetSchedule().GetAction().GetStartWorkflow(); startWorkflow != 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.
flip this conditional so you can unindent most of this?
also this has to be in terms of schedulepb.Schedule, not CreateScheduleRequest, and one copy/replace has to move to the caller. you'll see when you merge...
handler.stopProcessing = true | ||
return err | ||
} | ||
if mappedSearchAttributes != nil { | ||
newAttr := *attr |
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.
😱 I thought "attr" wasn't allowed
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.
:-) This is another attr
. This is command attributes, not search.
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.
This is indeed ugly. :(
Is it possible to handle those at interceptor layer?
What could the interceptor do except clone the proto itself? If I were doing this from scratch, I think it might be better to go the other way and push the aliasing way down the stack, into visibility. So we're not touching the request at all, but we do it when we build the ES doc or whatever SQL thing. Or maybe slightly higher, after search attributes have already been split out of the request and attached to other metadata. We could still "dry-run" the mapping in the handler to validate. Then we shouldn't get errors later, but if so just ignore them. |
a2e2a9e
to
35a3ef1
Compare
common/searchattribute/mapper.go
Outdated
func ApplyAliases(mapper Mapper, searchAttributes *commonpb.SearchAttributes, namespace string) error { | ||
// ApplyAliases returns SearchAttributes struct where each search attribute name is replaced with alias. | ||
// If no replacement where made, it returns nil which means that original SearchAttributes struct should be used. | ||
func ApplyAliases(mapper Mapper, searchAttributes *commonpb.SearchAttributes, namespace string) (*commonpb.SearchAttributes, 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.
As long as this is still open...
Would it be possible to rename these to make it obvious that ApplyAliases and SubstituteAliases are inverses? E.g. ApplyAliases/UnapplyAliases or AliasFields/UnaliasFields?
35a3ef1
to
27756a5
Compare
I am against reflection, especially on such hot path. I could consider moving all these ugly funcs to dedicated package/struct and forget about them. |
27756a5
to
48ab1be
Compare
48ab1be
to
70d148c
Compare
What changed?
Clone request if search attributes are mapped.
Why?
To insure idempotence of handler functions.
How did you test it?
Exixting tests.
Potential risks
No risks.
Is hotfix candidate?
No.