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

Call RedirectionInterceptor only for WorkflowHandler #3924

Merged

Conversation

alexshtin
Copy link
Member

What changed?
Call RedirectionInterceptor only for WorkflowHandler.

Why?
RedirectionInterceptor is not intended to be used by other than WorkflowHandler handler.

How did you test it?
Existing tests.

Potential risks
No risks.

Is hotfix candidate?
No.

@alexshtin alexshtin requested a review from a team as a code owner February 9, 2023 07:41
Comment on lines +171 to +173
if _, isWorkflowHandler := info.Server.(*WorkflowHandler); !isWorkflowHandler {
return handler(ctx, req)
}
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 actual fix.

Copy link
Contributor

Choose a reason for hiding this comment

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

Is this necessary? All requests will have this extra check.

Copy link
Member Author

Choose a reason for hiding this comment

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

I believe this is very cheap check. The other option is to compare strings: first return value from SplitMethodName with hardcoded string temporal.api.workflowservice.v1.WorkflowService but I believe checking type is better and faster.

Copy link
Contributor

Choose a reason for hiding this comment

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

no strong opinion. however, admin and operator are mostly manual trigger requests. most of the requests are workflow service requests.

Copy link
Member

@yycptt yycptt Feb 9, 2023

Choose a reason for hiding this comment

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

Don't forget health check. I see tons of unknown API: Check warning logs.

Copy link
Member

Choose a reason for hiding this comment

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

I don't have a strong opinion between this type check and string check either. but I agree we should do one since the redirection logic only applies to workflowservice

info *grpc.UnaryServerInfo,
handler grpc.UnaryHandler,
methodName string,
respAllocFn func() interface{},
respCtorFn responseConstructorFn,
Copy link
Member

Choose a reason for hiding this comment

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

what is Ctor? constructor?

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 reflection of my nostalgic memories from the past years: https://stackoverflow.com/questions/4614099/what-is-the-meaning-of-ctor.

@yycptt yycptt requested a review from wxing1292 February 9, 2023 20:34
@@ -45,75 +45,75 @@ import (
var (
dcRedirectionMetricsPrefix = "DCRedirection"

localAPIResults = map[string]respAllocFn{
localAPIResponses = map[string]responseConstructorFn{
Copy link
Member

Choose a reason for hiding this comment

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

now that I'm looking at this, have we benchmarked this against the equivalent reflection-based code? I see we need the maps anyway but they could just be sets and use reflection to construct the response. I'm curious about code bloat effects

Copy link
Member Author

Choose a reason for hiding this comment

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

I also thought about it. I even have a func for it:

func newOfSameType(val reflect.Value) reflect.Value {
	valType := val.Type().Elem()
	newValue := reflect.New(valType)
	val.Set(newValue)
	return newValue
}

but as soon as map is needed anyway, I am in doubt. Best thing, I guess, is code-gen the map.

Copy link
Member

Choose a reason for hiding this comment

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

not quite that easy, you have to go from grpc method name to first return value of that method on WorkflowService. but only like 3-4 more lines.

we can't just code-gen, the maps hold the semantics about which calls need to be forwarded. but they could be map[string]struct{}, and then use reflection to make the response values

Comment on lines +171 to +173
if _, isWorkflowHandler := info.Server.(*WorkflowHandler); !isWorkflowHandler {
return handler(ctx, req)
}
Copy link
Member

Choose a reason for hiding this comment

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

I don't have a strong opinion between this type check and string check either. but I agree we should do one since the redirection logic only applies to workflowservice

@alexshtin alexshtin merged commit 75c05a2 into temporalio:master Feb 9, 2023
@alexshtin alexshtin deleted the fix/redirection-interceptor-log branch February 9, 2023 23:33
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.

4 participants