Search in sources :

Example 1 with CurrentPassport

use of com.netflix.zuul.passport.CurrentPassport in project zuul by Netflix.

the class PassportLoggingHandler method logPassport.

private void logPassport(Channel channel) {
    // Collect attributes.
    CurrentPassport passport = CurrentPassport.fromChannel(channel);
    HttpRequestMessage request = ClientRequestReceiver.getRequestFromChannel(channel);
    HttpResponseMessage response = ClientRequestReceiver.getResponseFromChannel(channel);
    SessionContext ctx = request == null ? null : request.getContext();
    String topLevelRequestId = getRequestId(channel, ctx);
    // Do some debug logging of the Passport.
    if (LOG.isDebugEnabled()) {
        LOG.debug("State after complete. " + ", current-server-conns = " + ConnCounter.from(channel).getCurrentActiveConns() + ", current-http-reqs = " + HttpMetricsChannelHandler.getInflightRequestCountFromChannel(channel) + ", status = " + (response == null ? getRequestId(channel, ctx) : response.getStatus()) + ", nfstatus = " + String.valueOf(StatusCategoryUtils.getStatusCategory(ctx)) + ", toplevelid = " + topLevelRequestId + ", req = " + request.getInfoForLogging() + ", passport = " + String.valueOf(passport));
    }
    // Some logging of session states if certain criteria match:
    if (LOG.isInfoEnabled()) {
        if (passport.wasProxyAttempt()) {
            if (passport.findStateBackwards(PassportState.OUT_RESP_LAST_CONTENT_SENDING) == null) {
                incompleteProxySessionCounter.increment();
                LOG.info("Incorrect final state! toplevelid = " + topLevelRequestId + ", " + ChannelUtils.channelInfoForLogging(channel));
            }
        }
        if (!passport.wasProxyAttempt()) {
            if (ctx != null && !isHealthcheckRequest(request)) {
                // Why did we fail to attempt to proxy this request?
                RequestAttempts attempts = RequestAttempts.getFromSessionContext(ctx);
                LOG.debug("State after complete. " + ", context-error = " + String.valueOf(ctx.getError()) + ", current-http-reqs = " + HttpMetricsChannelHandler.getInflightRequestCountFromChannel(channel) + ", toplevelid = " + topLevelRequestId + ", req = " + request.getInfoForLogging() + ", attempts = " + String.valueOf(attempts) + ", passport = " + String.valueOf(passport));
            }
        }
        StartAndEnd inReqToOutResp = passport.findFirstStartAndLastEndStates(PassportState.IN_REQ_HEADERS_RECEIVED, PassportState.OUT_REQ_LAST_CONTENT_SENT);
        if (passport.calculateTimeBetween(inReqToOutResp) > WARN_REQ_PROCESSING_TIME_NS.get()) {
            LOG.info("Request processing took longer than threshold! toplevelid = " + topLevelRequestId + ", " + ChannelUtils.channelInfoForLogging(channel));
        }
        StartAndEnd inRespToOutResp = passport.findLastStartAndFirstEndStates(PassportState.IN_RESP_HEADERS_RECEIVED, PassportState.OUT_RESP_LAST_CONTENT_SENT);
        if (passport.calculateTimeBetween(inRespToOutResp) > WARN_RESP_PROCESSING_TIME_NS.get()) {
            LOG.info("Response processing took longer than threshold! toplevelid = " + topLevelRequestId + ", " + ChannelUtils.channelInfoForLogging(channel));
        }
    }
}
Also used : CurrentPassport(com.netflix.zuul.passport.CurrentPassport) HttpResponseMessage(com.netflix.zuul.message.http.HttpResponseMessage) HttpRequestMessage(com.netflix.zuul.message.http.HttpRequestMessage) RequestAttempts(com.netflix.zuul.niws.RequestAttempts) SessionContext(com.netflix.zuul.context.SessionContext) StartAndEnd(com.netflix.zuul.passport.StartAndEnd)

Example 2 with CurrentPassport

use of com.netflix.zuul.passport.CurrentPassport in project zuul by Netflix.

the class ChannelUtils method channelInfoForLogging.

public static String channelInfoForLogging(Channel ch) {
    if (ch == null) {
        return "null";
    }
    String channelInfo = ch.toString() + ", active=" + ch.isActive() + ", open=" + ch.isOpen() + ", registered=" + ch.isRegistered() + ", writable=" + ch.isWritable() + ", id=" + ch.id();
    CurrentPassport passport = CurrentPassport.fromChannel(ch);
    return "Channel: " + channelInfo + ", Passport: " + String.valueOf(passport);
}
Also used : CurrentPassport(com.netflix.zuul.passport.CurrentPassport)

Example 3 with CurrentPassport

use of com.netflix.zuul.passport.CurrentPassport in project zuul by Netflix.

the class ZuulSessionContextDecorator method decorate.

@Override
public SessionContext decorate(SessionContext ctx) {
    // TODO split out commons parts from BaseSessionContextDecorator
    ChannelHandlerContext nettyCtx = (ChannelHandlerContext) ctx.get(CommonContextKeys.NETTY_SERVER_CHANNEL_HANDLER_CONTEXT);
    if (nettyCtx == null) {
        return null;
    }
    Channel channel = nettyCtx.channel();
    // set injected origin manager
    ctx.put(CommonContextKeys.ORIGIN_MANAGER, originManager);
    // TODO
    /*        // The throttle result info.
        ThrottleResult throttleResult = channel.attr(HttpRequestThrottleChannelHandler.ATTR_THROTTLE_RESULT).get();
        ctx.set(CommonContextKeys.THROTTLE_RESULT, throttleResult);*/
    // Add a container for request attempts info.
    ctx.put(CommonContextKeys.REQUEST_ATTEMPTS, new RequestAttempts());
    // Providers for getting the size of read/written request and response body sizes from channel.
    ctx.put(CommonContextKeys.REQ_BODY_SIZE_PROVIDER, HttpBodySizeRecordingChannelHandler.getCurrentInboundBodySize(channel));
    ctx.put(CommonContextKeys.RESP_BODY_SIZE_PROVIDER, HttpBodySizeRecordingChannelHandler.getCurrentOutboundBodySize(channel));
    CurrentPassport passport = CurrentPassport.fromChannel(channel);
    ctx.put(CommonContextKeys.PASSPORT, passport);
    ctx.setUUID(UUID_FACTORY.generateRandomUuid().toString());
    return ctx;
}
Also used : CurrentPassport(com.netflix.zuul.passport.CurrentPassport) Channel(io.netty.channel.Channel) RequestAttempts(com.netflix.zuul.niws.RequestAttempts) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext)

Example 4 with CurrentPassport

use of com.netflix.zuul.passport.CurrentPassport in project zuul by Netflix.

the class HttpLifecycleChannelHandler method addPassportState.

protected static void addPassportState(ChannelHandlerContext ctx, PassportState state) {
    CurrentPassport passport = CurrentPassport.fromChannel(ctx.channel());
    passport.add(state);
}
Also used : CurrentPassport(com.netflix.zuul.passport.CurrentPassport)

Example 5 with CurrentPassport

use of com.netflix.zuul.passport.CurrentPassport in project zuul by Netflix.

the class ClientRequestReceiver method userEventTriggered.

@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
    if (evt instanceof CompleteEvent) {
        final CompleteReason reason = ((CompleteEvent) evt).getReason();
        if (zuulRequest != null) {
            zuulRequest.getContext().cancel();
            zuulRequest.disposeBufferedBody();
            final CurrentPassport passport = CurrentPassport.fromSessionContext(zuulRequest.getContext());
            if ((passport != null) && (passport.findState(PassportState.OUT_RESP_LAST_CONTENT_SENT) == null)) {
                // Only log this state if the response does not seem to have completed normally.
                passport.add(PassportState.IN_REQ_CANCELLED);
            }
        }
        if (reason == CompleteReason.INACTIVE && zuulRequest != null) {
            // Client closed connection prematurely.
            StatusCategoryUtils.setStatusCategory(zuulRequest.getContext(), ZuulStatusCategory.FAILURE_CLIENT_CANCELLED);
        }
        if (reason == CompleteReason.PIPELINE_REJECT && zuulRequest != null) {
            StatusCategoryUtils.setStatusCategory(zuulRequest.getContext(), ZuulStatusCategory.FAILURE_CLIENT_PIPELINE_REJECT);
        }
        if (reason != SESSION_COMPLETE && zuulRequest != null) {
            final SessionContext zuulCtx = zuulRequest.getContext();
            if (clientRequest != null) {
                if (LOG.isInfoEnabled()) {
                    // thats ok, so don't log in that case.
                    if (!"HTTP/2".equals(zuulRequest.getProtocol())) {
                        LOG.debug("Client {} request UUID {} to {} completed with reason = {}, {}", clientRequest.method(), zuulCtx.getUUID(), clientRequest.uri(), reason.name(), ChannelUtils.channelInfoForLogging(ctx.channel()));
                    }
                }
            }
            if (zuulCtx.debugRequest()) {
                LOG.debug("Endpoint = {}", zuulCtx.getEndpoint());
                dumpDebugInfo(Debug.getRequestDebug(zuulCtx));
                dumpDebugInfo(Debug.getRoutingDebug(zuulCtx));
            }
        }
        if (zuulRequest == null) {
            Spectator.globalRegistry().counter("zuul.client.complete.null", "reason", String.valueOf(reason)).increment();
        }
        clientRequest = null;
        zuulRequest = null;
    }
    super.userEventTriggered(ctx, evt);
    if (evt instanceof CompleteEvent) {
        final Channel channel = ctx.channel();
        channel.attr(ATTR_ZUUL_REQ).set(null);
        channel.attr(ATTR_ZUUL_RESP).set(null);
        channel.attr(ATTR_LAST_CONTENT_RECEIVED).set(null);
    }
}
Also used : CurrentPassport(com.netflix.zuul.passport.CurrentPassport) Channel(io.netty.channel.Channel) CompleteEvent(com.netflix.netty.common.HttpLifecycleChannelHandler.CompleteEvent) SessionContext(com.netflix.zuul.context.SessionContext) CompleteReason(com.netflix.netty.common.HttpLifecycleChannelHandler.CompleteReason)

Aggregations

CurrentPassport (com.netflix.zuul.passport.CurrentPassport)8 SessionContext (com.netflix.zuul.context.SessionContext)2 HttpRequestMessage (com.netflix.zuul.message.http.HttpRequestMessage)2 HttpResponseMessage (com.netflix.zuul.message.http.HttpResponseMessage)2 RequestAttempts (com.netflix.zuul.niws.RequestAttempts)2 Channel (io.netty.channel.Channel)2 CompleteEvent (com.netflix.netty.common.HttpLifecycleChannelHandler.CompleteEvent)1 CompleteReason (com.netflix.netty.common.HttpLifecycleChannelHandler.CompleteReason)1 StartAndEnd (com.netflix.zuul.passport.StartAndEnd)1 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)1 EventLoop (io.netty.channel.EventLoop)1 HttpContent (io.netty.handler.codec.http.HttpContent)1 TaskCloseable (io.perfmark.TaskCloseable)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1