KAFKA-20443: Move RequestChannel Requests to server module#22075
Conversation
m1a2st
left a comment
There was a problem hiding this comment.
Thanks for this patch, one nit comment
| buffer, | ||
| requestChannelMetrics, | ||
| Some(envelope) | ||
| Optional.ofNullable(envelope) |
There was a problem hiding this comment.
I think Optional.of() is preferable to Optional.ofNullable(), since envelope should never be null.
There was a problem hiding this comment.
You're right, not need for ofNullable() here. Updated, thanks
72ed87e to
65e8328
Compare
0a753b4 to
d9cac70
Compare
|
@showuon can you take a look? |
|
|
||
| private volatile OptionalLong callbackRequestDequeueTimeNanos = OptionalLong.empty(); | ||
| private volatile OptionalLong callbackRequestCompleteTimeNanos = OptionalLong.empty(); | ||
| private volatile Optional<Consumer<Long>> recordNetworkThreadTimeCallback = Optional.empty(); |
There was a problem hiding this comment.
private volatile LongConsumer recordNetworkThreadTimeCallback = __ -> {};| import java.util.Objects; | ||
| import java.util.function.Consumer; | ||
|
|
||
| public final class CallbackRequest implements BaseRequest { |
There was a problem hiding this comment.
That looks like a good candidate for a record class. WDYT?
| * to the nearest long. | ||
| */ | ||
| private static double nanosToMs(long nanos) { | ||
| long positiveNanos = Math.max(nanos, 0); |
There was a problem hiding this comment.
private static double nanosToMs(long nanos) {
return (double) TimeUnit.NANOSECONDS.toMicros(nanos) / 1000.0;
}| */ | ||
| package org.apache.kafka.network; | ||
|
|
||
| public final class ShutdownRequest implements BaseRequest { |
There was a problem hiding this comment.
public enum ShutdownRequest implements BaseRequest {
INSTANCE;
}| */ | ||
| package org.apache.kafka.network; | ||
|
|
||
| public final class WakeupRequest implements BaseRequest { |
|
Thanks @chia7712 for the review. All your suggestions made sense, so I applied them all. |
| * to the nearest long. | ||
| */ | ||
| private static double nanosToMs(long nanos) { | ||
| return (double) TimeUnit.NANOSECONDS.toMicros(nanos) / 1000; |
There was a problem hiding this comment.
ugh, my previous comment missed the protection Math.max(0L, nanos). Would you please add it back?
There was a problem hiding this comment.
It's not entirely clear if nanos can ever be negative here but I think it's probably best to be safe and keep this protection. I pushed an update
| double messageConversionsTimeMs = nanosToMs(messageConversionsTimeNanos); | ||
| double totalTimeMs = nanosToMs(endTimeNanos - startTimeNanos); | ||
|
|
||
| List<String> overrideMetricNames; |
There was a problem hiding this comment.
How about using switch expression ?
List<String> overrideMetricNames = switch (header().apiKey()) {
case FETCH -> {
String specifiedMetricName = body(FetchRequest.class).isFromFollower()
? RequestMetrics.FOLLOW_FETCH_METRIC_NAME
: RequestMetrics.CONSUMER_FETCH_METRIC_NAME;
yield List.of(specifiedMetricName, ApiKeys.FETCH.name);
}
case ADD_PARTITIONS_TO_TXN -> body(AddPartitionsToTxnRequest.class).allVerifyOnlyRequest()
? List.of(RequestMetrics.VERIFY_PARTITIONS_IN_TXN_METRIC_NAME)
: List.of(ApiKeys.ADD_PARTITIONS_TO_TXN.name);
case LIST_CONFIG_RESOURCES -> (header().apiVersion() == 0)
? List.of(RequestMetrics.LIST_CLIENT_METRICS_RESOURCES_METRIC_NAME, ApiKeys.LIST_CONFIG_RESOURCES.name)
: List.of(ApiKeys.LIST_CONFIG_RESOURCES.name);
default -> List.of(header().apiKey().name);
};There was a problem hiding this comment.
Good idea that's slightly more elegant
|
@mimaison would you mind fixing the conflicts? |
Rewrite in Java and move to server module
|
Rebased on trunk |
| expectedNode.set("isForwarded", if (req.isForwarded) BooleanNode.TRUE else BooleanNode.FALSE) | ||
| expectedNode.set("requestHeader", RequestConvertToJson.requestHeaderNode(req.header)) | ||
| expectedNode.set("request", req.requestLog.getOrElse(new TextNode(""))) | ||
| expectedNode.set("request", req.requestLog.orElse(new TextNode(""))) |
There was a problem hiding this comment.
This comment is orthogonal to the PR, but it appears NullNode.getInstance() is more suitable than new TextNode("") if the filed is non-existent
…ponse fields (#22295) See #22075 (comment) , use `NullNode.getInstance()` instead of `new TextNode("")` as the fallback for missing `request`/`response` fields. Reviewers: Chia-Ping Tsai <chia7712@gmail.com>
Rewrite in Java and move to server module Reviewers: Ken Huang <s7133700@gmail.com>, Chia-Ping Tsai <chia7712@gmail.com>
…ponse fields (apache#22295) See apache#22075 (comment) , use `NullNode.getInstance()` instead of `new TextNode("")` as the fallback for missing `request`/`response` fields. Reviewers: Chia-Ping Tsai <chia7712@gmail.com>
| }; | ||
|
|
||
| for (String metricName : overrideMetricNames) { | ||
| RequestMetrics m = metrics.apply(metricName); |
There was a problem hiding this comment.
The apply naming wasn't migrated to follow Java conventions
I'll label this as a 'good first issue' :)
Rewrite in Java and move to server module
Reviewers: Ken Huang s7133700@gmail.com, Chia-Ping Tsai
chia7712@gmail.com