Extract grpc-status from responseContent when not in headers/trailers#6621
Extract grpc-status from responseContent when not in headers/trailers#6621
Conversation
Motivation: When a client cancels a gRPC request (e.g., via RST_STREAM), the grpc-status may not be present in response headers or trailers, causing metrics to be recorded with UNKNOWN status. Resolves line#6606 Modifications: - Added fallback in GrpcMeterIdPrefixFunction to extract grpc-status from responseContent using Status.fromThrowable() - Added integration test for client cancellation scenario Result: - gRPC metrics now correctly record the status when client cancels Co-Authored-By: Claude Opus 4.5 <[email protected]>
📝 WalkthroughWalkthroughAdded a fallback in GrpcMeterIdPrefixFunction that inspects RequestLog.responseContent() for an RpcResponse and, when headers/trailers lack grpc-status, derives and sets the grpc.status from the RPC response cause (e.g., client cancellation). Tests added to exercise the cancellation path. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
jrhee17
left a comment
There was a problem hiding this comment.
Changes look good once CI passes
|
|
||
| final ClientRequestContext ctx; | ||
| try (ClientRequestContextCaptor captor = Clients.newContextCaptor()) { | ||
| final ListenableFuture<ExtendedTestMessage> future = |
There was a problem hiding this comment.
This unfortunately fails due to how shadedTest works in our codebase at the moment.
You may need to either:
- Avoid using
*FutureStubin tests - Or move the added test to a module without the
relocateflag (i.e.:it:grpc:java)
grpc/src/main/java/com/linecorp/armeria/common/grpc/GrpcMeterIdPrefixFunction.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In
`@grpc/src/test/java/com/linecorp/armeria/common/grpc/GrpcMeterIdPrefixFunctionTest.java`:
- Around line 279-289: In unaryCallWithAllDifferentParameterTypes (in
GrpcMeterIdPrefixFunctionTest) stop processing when the Thread.sleep is
interrupted: in the catch block for InterruptedException, after re-setting the
interrupt flag (Thread.currentThread().interrupt()), return immediately so you
do not call responseObserver.onNext/onCompleted after an interruption (which can
race with cancellation/stream closure).
grpc/src/test/java/com/linecorp/armeria/common/grpc/GrpcMeterIdPrefixFunctionTest.java
Show resolved
Hide resolved
7b8c2c2 to
5a79d3f
Compare
Motivation
When a client cancels a gRPC request (e.g., via RST_STREAM), the grpc-status may not be present in response headers or trailers, causing metrics to be recorded with UNKNOWN status.
Resolves #6606
Modifications
GrpcMeterIdPrefixFunctionto extract grpc-status fromresponseContentusingStatus.fromThrowable()Result