Search in sources :

Example 6 with CurrentPassport

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

the class ZuulFilterChainRunner method filter.

@Override
public void filter(T inMesg, HttpContent chunk) {
    String filterName = "-";
    try (TaskCloseable ignored = PerfMark.traceTask(this, s -> s.getClass().getSimpleName() + ".filterChunk")) {
        addPerfMarkTags(inMesg);
        Preconditions.checkNotNull(inMesg, "input message");
        final AtomicInteger runningFilterIdx = getRunningFilterIndex(inMesg);
        final int limit = runningFilterIdx.get();
        for (int i = 0; i < limit; i++) {
            final ZuulFilter<T, T> filter = filters[i];
            filterName = filter.filterName();
            if ((!filter.isDisabled()) && (!shouldSkipFilter(inMesg, filter))) {
                final HttpContent newChunk = filter.processContentChunk(inMesg, chunk);
                if (newChunk == null) {
                    // Filter wants to break the chain and stop propagating this chunk any further
                    return;
                }
                // deallocate original chunk if necessary
                if ((newChunk != chunk) && (chunk.refCnt() > 0)) {
                    chunk.release(chunk.refCnt());
                }
                chunk = newChunk;
            }
        }
        if (limit >= filters.length) {
            // Filter chain has run to end, pass down the channel pipeline
            invokeNextStage(inMesg, chunk);
        } else {
            inMesg.bufferBodyContents(chunk);
            boolean isAwaitingBody = isFilterAwaitingBody(inMesg);
            // Record passport states for start and end of buffering bodies.
            if (isAwaitingBody) {
                CurrentPassport passport = CurrentPassport.fromSessionContext(inMesg.getContext());
                if (inMesg.hasCompleteBody()) {
                    if (inMesg instanceof HttpRequestMessage) {
                        passport.addIfNotAlready(PassportState.FILTERS_INBOUND_BUF_END);
                    } else if (inMesg instanceof HttpResponseMessage) {
                        passport.addIfNotAlready(PassportState.FILTERS_OUTBOUND_BUF_END);
                    }
                } else {
                    if (inMesg instanceof HttpRequestMessage) {
                        passport.addIfNotAlready(PassportState.FILTERS_INBOUND_BUF_START);
                    } else if (inMesg instanceof HttpResponseMessage) {
                        passport.addIfNotAlready(PassportState.FILTERS_OUTBOUND_BUF_START);
                    }
                }
            }
            if (isAwaitingBody && inMesg.hasCompleteBody()) {
                // whole body has arrived, resume filter chain
                runFilters(inMesg, runningFilterIdx);
            }
        }
    } catch (Exception ex) {
        handleException(inMesg, filterName, ex);
    }
}
Also used : CurrentPassport(com.netflix.zuul.passport.CurrentPassport) HttpResponseMessage(com.netflix.zuul.message.http.HttpResponseMessage) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HttpRequestMessage(com.netflix.zuul.message.http.HttpRequestMessage) HttpContent(io.netty.handler.codec.http.HttpContent) TaskCloseable(io.perfmark.TaskCloseable)

Example 7 with CurrentPassport

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

the class PooledConnection method release.

public void release() {
    if (released) {
        return;
    }
    if (isActive()) {
        if (connectionState != ConnectionState.WRITE_READY) {
            closeWrtBusyConnCounter.increment();
        }
    }
    if (!isShouldClose() && connectionState != ConnectionState.WRITE_READY) {
        CurrentPassport passport = CurrentPassport.fromChannel(channel);
        LOG.info("Error - Attempt to put busy connection into the pool = " + this.toString() + ", " + String.valueOf(passport));
        this.shouldClose = true;
    }
    // reset the connectionState
    connectionState = ConnectionState.WRITE_READY;
    released = true;
    channelManager.release(this);
}
Also used : CurrentPassport(com.netflix.zuul.passport.CurrentPassport)

Example 8 with CurrentPassport

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

the class PerServerConnectionPool method release.

@Override
public boolean release(PooledConnection conn) {
    if (conn == null) {
        return false;
    }
    if (conn.isInPool()) {
        return false;
    }
    // Get the eventloop for this channel.
    EventLoop eventLoop = conn.getChannel().eventLoop();
    Deque<PooledConnection> connections = getPoolForEventLoop(eventLoop);
    CurrentPassport passport = CurrentPassport.fromChannel(conn.getChannel());
    // Discard conn if already at least above waterline in the pool already for this server.
    int poolWaterline = config.perServerWaterline();
    if (poolWaterline > -1 && connections.size() >= poolWaterline) {
        closeAboveHighWaterMarkCounter.increment();
        conn.close();
        conn.setInPool(false);
        return false;
    } else // Attempt to return connection to the pool.
    if (connections.offer(conn)) {
        conn.setInPool(true);
        connsInPool.incrementAndGet();
        passport.add(PassportState.ORIGIN_CH_POOL_RETURNED);
        return true;
    } else {
        // If the pool is full, then close the conn and discard.
        conn.close();
        conn.setInPool(false);
        return false;
    }
}
Also used : CurrentPassport(com.netflix.zuul.passport.CurrentPassport) EventLoop(io.netty.channel.EventLoop)

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