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

Clone request if search attributes are mapped #3299

Merged
merged 7 commits into from
Sep 7, 2022

Conversation

alexshtin
Copy link
Member

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.

@alexshtin alexshtin requested a review from a team as a code owner September 2, 2022 00:22
service/frontend/workflow_handler.go Outdated Show resolved Hide resolved
service/frontend/workflow_handler.go Outdated Show resolved Hide resolved
@alexshtin alexshtin force-pushed the feature/sa-clone-request branch from c02da29 to b95ff74 Compare September 2, 2022 01:27
Copy link
Member

@dnr dnr left a 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

}

func (wh *WorkflowHandler) mapCreateScheduleRequestStartWorkflowSearchAttributes(request *workflowservice.CreateScheduleRequest, namespaceName namespace.Name) (*workflowservice.CreateScheduleRequest, error) {
if startWorkflow := request.GetSchedule().GetAction().GetStartWorkflow(); startWorkflow != nil {
Copy link
Member

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
Copy link
Member

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

Copy link
Member Author

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.

Copy link
Member

@yiminc yiminc left a 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?

@dnr
Copy link
Member

dnr commented Sep 2, 2022

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.

@alexshtin alexshtin force-pushed the feature/sa-clone-request branch from a2e2a9e to 35a3ef1 Compare September 6, 2022 23:37
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) {
Copy link
Member

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?

@alexshtin alexshtin force-pushed the feature/sa-clone-request branch from 35a3ef1 to 27756a5 Compare September 7, 2022 06:20
@alexshtin
Copy link
Member Author

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.

@alexshtin alexshtin force-pushed the feature/sa-clone-request branch from 27756a5 to 48ab1be Compare September 7, 2022 06:43
@alexshtin alexshtin force-pushed the feature/sa-clone-request branch from 48ab1be to 70d148c Compare September 7, 2022 17:02
@alexshtin alexshtin merged commit 3c2ddea into temporalio:master Sep 7, 2022
@alexshtin alexshtin deleted the feature/sa-clone-request branch September 7, 2022 18:40
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