-
Notifications
You must be signed in to change notification settings - Fork 955
Introduce BraveRpcService
#6115
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
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, I understood the intention was to open the possibility to support more request types. Updated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, @jrhee17! 🙇♂️🙇♂️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left some questions, but basically looks good. 👍
abstract Tracer tracer(); | ||
|
||
abstract RequestContextCurrentTraceContext currentTraceContext(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tracer
and currentTraceContext
are only used in AbstractBraverService
, so how about passing them through the constructor instead?
@@ -41,53 +52,25 @@ | |||
* <li>address.local</li> | |||
* </ul> | |||
*/ | |||
final class ArmeriaHttpServerParser implements HttpRequestParser, HttpResponseParser { | |||
public final class ArmeriaHttpServerParser { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Global comment: Could you add @UnstableApi
?
@Nullable | ||
@Override | ||
public String errorCode() { | ||
return null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question: Is returning null
okay?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shall we move these abstract methods down so they are grouped?
brave/brave6/src/main/java/com/linecorp/armeria/server/brave/ArmeriaHttpServerParser.java
Outdated
Show resolved
Hide resolved
@@ -41,53 +52,25 @@ | |||
* <li>address.local</li> | |||
* </ul> | |||
*/ | |||
final class ArmeriaHttpServerParser implements HttpRequestParser, HttpResponseParser { | |||
public final class ArmeriaHttpServerParser { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe just BraveServerParsers
? Any better names? 🤔
brave/brave6/src/main/java/com/linecorp/armeria/server/brave/ArmeriaRpcServerParser.java
Outdated
Show resolved
Hide resolved
* <li>address.local</li> | ||
* </ul> | ||
*/ | ||
public final class ArmeriaRpcServerParser { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@UnstableApi
- How about merging this class into
ArmeriaHttpServerParser
and provide all factory methods there? e.g.BraveServerParsers.rpcRequestParser()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2025 and LY
* 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 AbstractBraveService<RpcServerRequest, RpcServerResponse, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@UnstableApi
?
…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:
ArmeriaHttpServerParser
andArmeriaRpcServerParser
BraveService
orBraveRpcService
. This can provide more flexibility on whether to use onlyBraveService
, onlyBraveRpcService
, or bothBraveService
andBraveRpcService
BraveRpcService
which allows users to perform sampling or request/response parsing based onRpcRequest
Modifications:
BraveRpcService
. By default, armeria-specific tags/annotations recorded byBraveRpcService
is the same asBraveService
ArmeriaHttpServerParser
andArmeriaRpcServerParser
to allow users to easily construct aRpcTracing
orHttpTracing
Result:
RpcRequest
,RpcResponse
to apply sampling/tags/annotations