Skip to content
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

Obtain the channel from ChannelHandlerContext instead of HttpServerOperations #3231

Merged
merged 1 commit into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -175,16 +175,13 @@ public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise)

if (msg instanceof LastHttpContent) {
promise.addListener(future -> {
ChannelOperations<?, ?> channelOps = ChannelOperations.get(ctx.channel());
if (channelOps instanceof HttpServerOperations) {
try {
recordWrite((HttpServerOperations) channelOps);
}
catch (RuntimeException e) {
// Allow request-response exchange to continue, unaffected by metrics problem
if (log.isWarnEnabled()) {
log.warn(format(ctx.channel(), "Exception caught while recording metrics."), e);
}
try {
recordWrite(ctx.channel());
}
catch (RuntimeException e) {
// Allow request-response exchange to continue, unaffected by metrics problem
if (log.isWarnEnabled()) {
log.warn(format(ctx.channel(), "Exception caught while recording metrics."), e);
}
}

Expand Down Expand Up @@ -299,7 +296,7 @@ protected void recordRead() {
recorder().recordDataReceived(remoteSocketAddress, path, dataReceived);
}

protected void recordWrite(HttpServerOperations ops) {
protected void recordWrite(Channel channel) {
Duration dataSentTimeDuration = Duration.ofNanos(System.nanoTime() - dataSentTime);
recorder().recordDataSentTime(path, method, status, dataSentTimeDuration);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package reactor.netty.http.server;

import io.netty.channel.Channel;
import reactor.util.annotation.Nullable;
import reactor.util.context.ContextView;

Expand Down Expand Up @@ -72,7 +73,7 @@ protected void recordRead() {
}

@Override
protected void recordWrite(HttpServerOperations ops) {
protected void recordWrite(Channel channel) {
Duration dataSentTimeDuration = Duration.ofNanos(System.nanoTime() - dataSentTime);
recorder().recordDataSentTime(contextView, path, method, status, dataSentTimeDuration);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import io.micrometer.core.instrument.Timer;
import io.micrometer.observation.Observation;
import io.micrometer.observation.transport.RequestReplyReceiverContext;
import io.netty.channel.Channel;
import io.netty.handler.codec.http.HttpRequest;
import io.netty.handler.codec.http.HttpResponse;
import reactor.netty.observability.ReactorNettyHandlerContext;
Expand Down Expand Up @@ -85,7 +86,7 @@ protected HttpServerMetricsRecorder recorder() {
}

@Override
protected void recordWrite(HttpServerOperations ops) {
protected void recordWrite(Channel channel) {
Duration dataSentTimeDuration = Duration.ofNanos(System.nanoTime() - dataSentTime);
recorder().recordDataSentTime(path, method, status, dataSentTimeDuration);

Expand All @@ -100,7 +101,7 @@ protected void recordWrite(HttpServerOperations ops) {
// Move the implementation from the recorder here
responseTimeObservation.stop();

setChannelContext(ops.channel(), parentContextView);
setChannelContext(channel, parentContextView);

responseTimeHandlerContext = null;
responseTimeObservation = null;
Expand Down
Loading