Skip to content

Commit

Permalink
allow overrides for metrics handler order
Browse files Browse the repository at this point in the history
  • Loading branch information
argha-c committed Jan 24, 2024
1 parent 715ee4e commit 806e36d
Showing 1 changed file with 20 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@
import io.netty.channel.ChannelPipeline;
import io.netty.handler.codec.http2.Http2StreamFrameToHttpObjectCodec;
import io.netty.util.AttributeKey;

import java.util.function.Consumer;

/**
* TODO - can this be done when we create the Http2StreamChannelBootstrap instead now?
*/
@ChannelHandler.Sharable
public class Http2StreamInitializer extends ChannelInboundHandlerAdapter {

private static final Http2StreamHeaderCleaner http2StreamHeaderCleaner = new Http2StreamHeaderCleaner();
private static final Http2ResetFrameHandler http2ResetFrameHandler = new Http2ResetFrameHandler();
private static final Http2StreamErrorHandler http2StreamErrorHandler = new Http2StreamErrorHandler();
Expand Down Expand Up @@ -66,16 +66,14 @@ public Http2StreamInitializer(
@Override
public void handlerAdded(ChannelHandlerContext ctx) throws Exception {
copyAttrsFromParentChannel(this.parent, ctx.channel());

addHttpMetricsHandlers(ctx.pipeline());
addHttp2StreamSpecificHandlers(ctx.pipeline());
addHttpHandlerFn.accept(ctx.pipeline());

ctx.pipeline().remove(this);
}

protected void addHttp2StreamSpecificHandlers(ChannelPipeline pipeline) {
pipeline.addLast("h2_metrics_inbound", http2MetricsChannelHandlers.inbound());
pipeline.addLast("h2_metrics_outbound", http2MetricsChannelHandlers.outbound());
pipeline.addLast("h2_max_requests_per_conn", connectionExpiryHandler);
pipeline.addLast("h2_conn_close", connectionCloseHandler);

Expand All @@ -86,21 +84,26 @@ protected void addHttp2StreamSpecificHandlers(ChannelPipeline pipeline) {
pipeline.addLast(new Http2ContentLengthEnforcingHandler());
}

protected void addHttpMetricsHandlers(ChannelPipeline pipeline) {
pipeline.addLast("h2_metrics_inbound", http2MetricsChannelHandlers.inbound());
pipeline.addLast("h2_metrics_outbound", http2MetricsChannelHandlers.outbound());
}

protected void copyAttrsFromParentChannel(Channel parent, Channel child) {
AttributeKey[] attributesToCopy = {
SourceAddressChannelHandler.ATTR_LOCAL_ADDRESS,
SourceAddressChannelHandler.ATTR_LOCAL_INET_ADDR,
SourceAddressChannelHandler.ATTR_SOURCE_ADDRESS,
SourceAddressChannelHandler.ATTR_REMOTE_ADDR,
SourceAddressChannelHandler.ATTR_SOURCE_INET_ADDR,
SourceAddressChannelHandler.ATTR_SERVER_LOCAL_ADDRESS,
SourceAddressChannelHandler.ATTR_SERVER_LOCAL_PORT,
SourceAddressChannelHandler.ATTR_PROXY_PROTOCOL_DESTINATION_ADDRESS,
Http2OrHttpHandler.PROTOCOL_NAME,
SslHandshakeInfoHandler.ATTR_SSL_INFO,
HAProxyMessageChannelHandler.ATTR_HAPROXY_MESSAGE,
HAProxyMessageChannelHandler.ATTR_HAPROXY_VERSION,
BaseZuulChannelInitializer.ATTR_CHANNEL_CONFIG
SourceAddressChannelHandler.ATTR_LOCAL_ADDRESS,
SourceAddressChannelHandler.ATTR_LOCAL_INET_ADDR,
SourceAddressChannelHandler.ATTR_SOURCE_ADDRESS,
SourceAddressChannelHandler.ATTR_REMOTE_ADDR,
SourceAddressChannelHandler.ATTR_SOURCE_INET_ADDR,
SourceAddressChannelHandler.ATTR_SERVER_LOCAL_ADDRESS,
SourceAddressChannelHandler.ATTR_SERVER_LOCAL_PORT,
SourceAddressChannelHandler.ATTR_PROXY_PROTOCOL_DESTINATION_ADDRESS,
Http2OrHttpHandler.PROTOCOL_NAME,
SslHandshakeInfoHandler.ATTR_SSL_INFO,
HAProxyMessageChannelHandler.ATTR_HAPROXY_MESSAGE,
HAProxyMessageChannelHandler.ATTR_HAPROXY_VERSION,
BaseZuulChannelInitializer.ATTR_CHANNEL_CONFIG
};

for (AttributeKey key : attributesToCopy) {
Expand Down

0 comments on commit 806e36d

Please sign in to comment.