Skip to content

Commit

Permalink
add touch instrumentation for FullHttpResponse instances
Browse files Browse the repository at this point in the history
  • Loading branch information
artgon authored and argha-c committed Apr 14, 2023
1 parent 22ba0e9 commit bc7027d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
package com.netflix.netty.common;

import com.netflix.zuul.message.ZuulMessage;
import com.netflix.zuul.message.http.HttpRequestMessage;
import io.netty.handler.codec.http.HttpResponse;
import io.netty.util.ReferenceCounted;
import io.netty.util.ResourceLeakDetector;

Expand Down Expand Up @@ -48,4 +50,10 @@ public static void touch(ReferenceCounted byteBuf, String hint, String filterNam
byteBuf.touch(hint + filterName);
}
}

public static void touch(HttpResponse originResponse, String hint, ZuulMessage msg) {
if (isAdvancedLeakDetection && originResponse instanceof ReferenceCounted) {
((ReferenceCounted) originResponse).touch(hint + msg);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@
import io.netty.handler.codec.http.HttpResponse;
import io.netty.handler.codec.http.LastHttpContent;
import io.netty.util.ReferenceCountUtil;
import io.netty.util.ReferenceCounted;
import io.netty.util.ResourceLeakDetectorFactory;
import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.GenericFutureListener;
import io.netty.util.concurrent.Promise;
Expand Down Expand Up @@ -724,6 +726,7 @@ public void responseFromOrigin(final HttpResponse originResponse) {
try (TaskCloseable ignore = PerfMark.traceTask("ProxyEndpoint.responseFromOrigin")) {
PerfMark.attachTag("uuid", zuulRequest, r -> r.getContext().getUUID());
PerfMark.attachTag("path", zuulRequest, HttpRequestInfo::getPath);
ByteBufUtil.touch(originResponse, "ProxyEndpoint handling response from origin, request: ", zuulRequest);
methodBinding.bind(() -> processResponseFromOrigin(originResponse));
} catch (Exception ex) {
unlinkFromOrigin();
Expand Down Expand Up @@ -756,6 +759,7 @@ protected void handleOriginSuccessResponse(final HttpResponse originResponse, Di
currentRequestAttempt.complete(respStatus, duration, null);
}
// separate nfstatus for 404 so that we can notify origins
ByteBufUtil.touch(originResponse, "ProxyEndpoint handling successful response, request: ", zuulRequest);
final StatusCategory statusCategory = respStatus == 404 ? SUCCESS_NOT_FOUND : SUCCESS;
zuulResponse = buildZuulHttpResponse(originResponse, statusCategory, context.getError());
invokeNext(zuulResponse);
Expand Down Expand Up @@ -787,6 +791,8 @@ private HttpResponseMessage buildZuulHttpResponse(final HttpResponse httpRespons
channelCtx.channel().attr(ATTR_ZUUL_RESP).set(zuulResponse);

if (httpResponse instanceof DefaultFullHttpResponse) {
ByteBufUtil.touch(httpResponse, "ProxyEndpoint converting Netty response to Zuul response, request: ",
zuulRequest);
final ByteBuf chunk = ((DefaultFullHttpResponse) httpResponse).content();
zuulResponse.bufferBodyContents(new DefaultLastHttpContent(chunk));
}
Expand Down Expand Up @@ -861,6 +867,7 @@ protected void handleOriginNonSuccessResponse(final HttpResponse originResponse,
respStatus, attemptNum, origin.getMaxRetriesForRequest(context),
startedSendingResponseToClient, zuulRequest.hasCompleteBody(), zuulRequest.getMethod());
//detach from current origin.
ByteBufUtil.touch(originResponse, "ProxyEndpoint handling non-success retry, request: ", zuulRequest);
unlinkFromOrigin();
releasePartialResponse(originResponse);

Expand All @@ -878,6 +885,7 @@ protected void handleOriginNonSuccessResponse(final HttpResponse originResponse,
respStatus, attemptNum, origin.getMaxRetriesForRequest(zuulCtx),
startedSendingResponseToClient, zuulRequest.hasCompleteBody(), zuulRequest.getMethod());
//This is a final response after all retries that will go to the client
ByteBufUtil.touch(originResponse, "ProxyEndpoint handling non-success response, request: ", zuulRequest);
zuulResponse = buildZuulHttpResponse(originResponse, statusCategory, obe);
invokeNext(zuulResponse);
}
Expand Down

0 comments on commit bc7027d

Please sign in to comment.