Skip to content

fix(gRPC): inject current method name to rpcinfo in server-side to fix FROM_METHOD missing #1792

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

Merged
merged 1 commit into from
Jun 10, 2025

Conversation

DMwangnima
Copy link
Contributor

@DMwangnima DMwangnima commented Jun 10, 2025

What type of PR is this?

fix

Check the PR title.

  • This PR title match the format: <type>(optional scope): <description>
  • The description of this PR title is user-oriented and clear enough for others to understand.
  • Attach the PR updating the user documentation if the current PR requires user awareness at the usage level. User docs repo

(Optional) Translate the PR title into Chinese.

(Optional) More detailed description for this PR(en: English/zh: Chinese).

en:
zh(optional):
在进行 RPC 调用时,client 会尝试从 ctx 中提取当前所处的 handler 对应的 method,从而知道是从哪个 handler 中发起的:

if fromMethod := ctx.Value(consts.CtxKeyMethod); fromMethod != nil {
    rpcinfo.AsMutableEndpointInfo(ri.From()).SetMethod(fromMethod.(string))
}

对于 Ping-Pong,FROM_METHOD 的注入在transmetaHandler.OnMessage中完成:

func (h *transMetaHandler) OnMessage(ctx context.Context, args, result remote.Message) (context.Context, error) {
        // ...
	if isServer && result.MessageType() != remote.Exception {
		// Pass through method name using ctx, the method name will be used as from method in the client.
		ctx = context.WithValue(ctx, consts.CtxKeyMethod, msg.RPCInfo().To().Method())
		// ...
	}
	return ctx, nil
}

但 streaming 流程中不会触发 OnMessage,因此需要额外注入

(Optional) Which issue(s) this PR fixes:

(optional) The PR that updates user documentation:

@DMwangnima DMwangnima requested review from a team as code owners June 10, 2025 07:33
Copy link

codecov bot commented Jun 10, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 60.38%. Comparing base (07c5078) to head (fdc2203).
Report is 1 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #1792   +/-   ##
========================================
  Coverage    60.38%   60.38%           
========================================
  Files          379      379           
  Lines        34438    34439    +1     
========================================
+ Hits         20795    20796    +1     
+ Misses       12381    12380    -1     
- Partials      1262     1263    +1     
Flag Coverage Δ
integration 48.21% <100.00%> (-0.04%) ⬇️
unit 50.83% <100.00%> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@DMwangnima DMwangnima force-pushed the fix/grpc_add_from_method branch from 91668d4 to 478e5bf Compare June 10, 2025 07:44
@DMwangnima DMwangnima force-pushed the fix/grpc_add_from_method branch from 98d5690 to fdc2203 Compare June 10, 2025 08:31
@DMwangnima DMwangnima changed the title fix(gRPC): inject from_method information in server-side fix(gRPC): inject current method name to rpcinfo in server-side to fix FROM_METHOD missing Jun 10, 2025
@DMwangnima DMwangnima merged commit 3eae01a into cloudwego:develop Jun 10, 2025
22 checks passed
@DMwangnima DMwangnima deleted the fix/grpc_add_from_method branch June 10, 2025 08:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants