Introduce BraveRpcService - #6115
Conversation
1c0572c to
c53cb0a
Compare
73dca92 to
7f89976
Compare
| * Decorates an {@link RpcService} to trace inbound {@link RpcRequest}s using | ||
| * <a href="https://github.com/openzipkin/brave">Brave</a>. | ||
| */ | ||
| public final class BraveRpcService extends SimpleDecoratingRpcService { |
There was a problem hiding this comment.
Question) Is it possible to share the common logic with BraveService by adding AbstractBraveService and extending it, as you did in AbstractMetricCollectingClient?
| super(delegate); | ||
| } | ||
|
|
||
| O serve0(ServiceRequestContext ctx, I req, BI braveReq, Span span) throws Exception { |
There was a problem hiding this comment.
This abstraction is slightly different from what I had in mind.
Instead of enforcing the subclass to call serve0() after preprocessing, should we handle all processes in AbstractBraveService but delegate the domain-specific part to the subclasses?
What do you think of this direction?
abstract class AbstractBraveService<BI extends brave.Request, BO extends brave.Response, ...>
abstract BI braveRequest(ServiceRequestContext ctx, I req);
abstract BO braveResponse(ServiceRequestContext ctx, RequestLog log, BI braveReq);
abstract Span handleReceive(BI braveReq);
abstract void handleSend(BO response, Span span);
@Override
public final O serve(ServiceRequestContext ctx, I req) throws Exception {
if (!ctx.config().transientServiceOptions().contains(TransientServiceOption.WITH_TRACING)) {
return unwrap().serve(ctx, req);
}
final BI braveReq = braveRequest(ctx, req);
final Span span = handleReceive(braveReq);
...
}There was a problem hiding this comment.
I see, I understood the intention was to open the possibility to support more request types. Updated
There was a problem hiding this comment.
Previously, IIRC, there was some duplicate code and there were functions for which subclasses had to call parent methods when implementing them.
My proposal is to allow implementations to focus only on domain-specific parts, without such constraints.
minwoox
left a comment
There was a problem hiding this comment.
Left some questions, but basically looks good. 👍
| abstract Tracer tracer(); | ||
|
|
||
| abstract RequestContextCurrentTraceContext currentTraceContext(); | ||
|
|
There was a problem hiding this comment.
Tracer and currentTraceContext are only used in AbstractBraverService, so how about passing them through the constructor instead?
| * </ul> | ||
| */ | ||
| final class ArmeriaHttpServerParser implements HttpRequestParser, HttpResponseParser { | ||
| public final class ArmeriaHttpServerParser { |
There was a problem hiding this comment.
Global comment: Could you add @UnstableApi?
| @Nullable | ||
| @Override | ||
| public String errorCode() { | ||
| return null; |
There was a problem hiding this comment.
Question: Is returning null okay?
There was a problem hiding this comment.
I'm not sure if there is a way to reliably fetch an error code for thrift (or is there even a concept of error codes in thrift?)
There was a problem hiding this comment.
I wasn't aware of that either. Let's fix this later if it becomes an issue.
| @Nullable | ||
| @Override | ||
| public Throwable error() { | ||
| final Object content = log.responseContent(); |
There was a problem hiding this comment.
Can't we use log.responseCause?
| * Copyright 2025 LINE Corporation | ||
| * | ||
| * LINE Corporation licenses this file to you under the Apache License, |
There was a problem hiding this comment.
Time to update the template?
| * Copyright 2025 LINE Corporation | |
| * | |
| * LINE Corporation licenses this file to you under the Apache License, | |
| * Copyright 2025 LY Corporation | |
| * | |
| * LY Corporation licenses this file to you under the Apache License, |
| abstract BI braveRequest(ServiceRequestContext ctx); | ||
|
|
||
| abstract BO braveResponse(ServiceRequestContext ctx, RequestLog log, BI braveReq); | ||
|
|
||
| abstract Span handleReceive(BI braveReq); | ||
|
|
||
| abstract void handleSend(BO response, Span span); |
There was a problem hiding this comment.
Shall we move these abstract methods down so they are grouped?
| * </ul> | ||
| */ | ||
| final class ArmeriaHttpServerParser implements HttpRequestParser, HttpResponseParser { | ||
| public final class ArmeriaHttpServerParser { |
There was a problem hiding this comment.
Maybe just BraveServerParsers? Any better names? 🤔
| * <li>address.local</li> | ||
| * </ul> | ||
| */ | ||
| public final class ArmeriaRpcServerParser { |
There was a problem hiding this comment.
@UnstableApi- How about merging this class into
ArmeriaHttpServerParserand provide all factory methods there? e.g.BraveServerParsers.rpcRequestParser()
There was a problem hiding this comment.
How about merging this class into ArmeriaHttpServerParser and provide all factory methods there?
I was assuming that most users will be interested in Http related integrations only.
Do you prefer that libs.brave6.instrumentation.rpc is included with the api scope instead?
There was a problem hiding this comment.
How about merging this class into ArmeriaHttpServerParser and provide all factory methods there? e.g. BraveServerParsers.rpcRequestParser()
Just merged the class and added the dependency since it seems you prefer this way.
| * Copyright 2019 LINE Corporation | ||
| * | ||
| * LINE Corporation licenses this file to you under the Apache License, |
…rmeriaHttpServerParser.java Co-authored-by: Trustin Lee <trustin@linecorp.com>
…rmeriaRpcServerParser.java Co-authored-by: Trustin Lee <trustin@linecorp.com>
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #6115 +/- ##
============================================
+ Coverage 74.46% 74.62% +0.15%
- Complexity 22234 22493 +259
============================================
Files 1963 1976 +13
Lines 82437 83062 +625
Branches 10764 10800 +36
============================================
+ Hits 61385 61983 +598
- Misses 15918 15929 +11
- Partials 5134 5150 +16 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Let me go ahead and merge this next week (5/19) unless anyone has further comments |
|
Let me go ahead and merge this PR. |
Motivation:
The motivation for this PR is better described in #6084
The changeset in this PR attempts to:
ArmeriaHttpServerParserandArmeriaRpcServerParserBraveServiceorBraveRpcService. This can provide more flexibility on whether to use onlyBraveService, onlyBraveRpcService, or bothBraveServiceandBraveRpcServiceBraveRpcServicewhich allows users to perform sampling or request/response parsing based onRpcRequestModifications:
BraveRpcService. By default, armeria-specific tags/annotations recorded byBraveRpcServiceis the same asBraveServiceArmeriaHttpServerParserandArmeriaRpcServerParserto allow users to easily construct aRpcTracingorHttpTracingResult:
RpcRequest,RpcResponseto apply sampling/tags/annotations