Search in sources :

Example 1 with ChannelConfig

use of com.netflix.netty.common.channel.config.ChannelConfig in project zuul by Netflix.

the class BaseServerStartup method defaultChannelDependencies.

protected ChannelConfig defaultChannelDependencies(String listenAddressName) {
    ChannelConfig channelDependencies = new ChannelConfig();
    addChannelDependencies(channelDependencies, listenAddressName);
    return channelDependencies;
}
Also used : ChannelConfig(com.netflix.netty.common.channel.config.ChannelConfig)

Example 2 with ChannelConfig

use of com.netflix.netty.common.channel.config.ChannelConfig in project zuul by Netflix.

the class BaseServerStartup method defaultChannelConfig.

public static ChannelConfig defaultChannelConfig(String listenAddressName) {
    ChannelConfig config = new ChannelConfig();
    config.add(new ChannelConfigValue<>(CommonChannelConfigKeys.maxConnections, chooseIntChannelProperty(listenAddressName, "connection.max", CommonChannelConfigKeys.maxConnections.defaultValue())));
    config.add(new ChannelConfigValue<>(CommonChannelConfigKeys.maxRequestsPerConnection, chooseIntChannelProperty(listenAddressName, "connection.max.requests", 20000)));
    config.add(new ChannelConfigValue<>(CommonChannelConfigKeys.maxRequestsPerConnectionInBrownout, chooseIntChannelProperty(listenAddressName, "connection.max.requests.brownout", CommonChannelConfigKeys.maxRequestsPerConnectionInBrownout.defaultValue())));
    config.add(new ChannelConfigValue<>(CommonChannelConfigKeys.connectionExpiry, chooseIntChannelProperty(listenAddressName, "connection.expiry", CommonChannelConfigKeys.connectionExpiry.defaultValue())));
    config.add(new ChannelConfigValue<>(CommonChannelConfigKeys.httpRequestReadTimeout, chooseIntChannelProperty(listenAddressName, "http.request.read.timeout", CommonChannelConfigKeys.httpRequestReadTimeout.defaultValue())));
    int connectionIdleTimeout = chooseIntChannelProperty(listenAddressName, "connection.idle.timeout", CommonChannelConfigKeys.idleTimeout.defaultValue());
    config.add(new ChannelConfigValue<>(CommonChannelConfigKeys.idleTimeout, connectionIdleTimeout));
    config.add(new ChannelConfigValue<>(CommonChannelConfigKeys.serverTimeout, new ServerTimeout(connectionIdleTimeout)));
    // For security, default to NEVER allowing XFF/Proxy headers from client.
    config.add(new ChannelConfigValue<>(CommonChannelConfigKeys.allowProxyHeadersWhen, StripUntrustedProxyHeadersHandler.AllowWhen.NEVER));
    config.set(CommonChannelConfigKeys.withProxyProtocol, true);
    config.set(CommonChannelConfigKeys.preferProxyProtocolForClientIp, true);
    config.add(new ChannelConfigValue<>(CommonChannelConfigKeys.connCloseDelay, chooseIntChannelProperty(listenAddressName, "connection.close.delay", CommonChannelConfigKeys.connCloseDelay.defaultValue())));
    return config;
}
Also used : ChannelConfig(com.netflix.netty.common.channel.config.ChannelConfig)

Example 3 with ChannelConfig

use of com.netflix.netty.common.channel.config.ChannelConfig in project zuul by Netflix.

the class Http2SslChannelInitializer method initChannel.

@Override
protected void initChannel(Channel ch) throws Exception {
    SslHandler sslHandler = sslContext.newHandler(ch.alloc());
    sslHandler.engine().setEnabledProtocols(serverSslConfig.getProtocols());
    if (LOG.isDebugEnabled()) {
        LOG.debug("ssl protocols supported: {}", String.join(", ", sslHandler.engine().getSupportedProtocols()));
        LOG.debug("ssl protocols enabled: {}", String.join(", ", sslHandler.engine().getEnabledProtocols()));
        LOG.debug("ssl ciphers supported: {}", String.join(", ", sslHandler.engine().getSupportedCipherSuites()));
        LOG.debug("ssl ciphers enabled: {}", String.join(", ", sslHandler.engine().getEnabledCipherSuites()));
    }
    // Configure our pipeline of ChannelHandlerS.
    ChannelPipeline pipeline = ch.pipeline();
    storeChannel(ch);
    addTimeoutHandlers(pipeline);
    addPassportHandler(pipeline);
    addTcpRelatedHandlers(pipeline);
    pipeline.addLast(new Http2FrameLoggingPerClientIpHandler());
    pipeline.addLast("ssl", sslHandler);
    addSslInfoHandlers(pipeline, isSSlFromIntermediary);
    addSslClientCertChecks(pipeline);
    Http2MetricsChannelHandlers http2MetricsChannelHandlers = new Http2MetricsChannelHandlers(registry, "server", "http2-" + metricId);
    Http2ConnectionCloseHandler connectionCloseHandler = new Http2ConnectionCloseHandler(registry);
    Http2ConnectionExpiryHandler connectionExpiryHandler = new Http2ConnectionExpiryHandler(maxRequestsPerConnection, maxRequestsPerConnectionInBrownout, connectionExpiry);
    pipeline.addLast("http2CodecSwapper", new Http2OrHttpHandler(new Http2StreamInitializer(ch, this::http1Handlers, http2MetricsChannelHandlers, connectionCloseHandler, connectionExpiryHandler), channelConfig, cp -> {
        http1Codec(cp);
        http1Handlers(cp);
    }));
    pipeline.addLast("codec_placeholder", DUMMY_HANDLER);
    pipeline.addLast(swallowSomeHttp2ExceptionsHandler);
}
Also used : Http2FrameLoggingPerClientIpHandler(com.netflix.zuul.logging.Http2FrameLoggingPerClientIpHandler) ChannelGroup(io.netty.channel.group.ChannelGroup) Logger(org.slf4j.Logger) SslContext(io.netty.handler.ssl.SslContext) SwallowSomeHttp2ExceptionsHandler(com.netflix.netty.common.SwallowSomeHttp2ExceptionsHandler) ServerSslConfig(com.netflix.netty.common.ssl.ServerSslConfig) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) LoggerFactory(org.slf4j.LoggerFactory) ChannelPipeline(io.netty.channel.ChannelPipeline) BaseZuulChannelInitializer(com.netflix.zuul.netty.server.BaseZuulChannelInitializer) CommonChannelConfigKeys(com.netflix.netty.common.channel.config.CommonChannelConfigKeys) Channel(io.netty.channel.Channel) SslHandler(io.netty.handler.ssl.SslHandler) Http2ConnectionExpiryHandler(com.netflix.netty.common.Http2ConnectionExpiryHandler) SslContextFactory(com.netflix.zuul.netty.ssl.SslContextFactory) Http2ConnectionCloseHandler(com.netflix.netty.common.Http2ConnectionCloseHandler) ChannelConfig(com.netflix.netty.common.channel.config.ChannelConfig) Http2MetricsChannelHandlers(com.netflix.netty.common.metrics.Http2MetricsChannelHandlers) Http2FrameLoggingPerClientIpHandler(com.netflix.zuul.logging.Http2FrameLoggingPerClientIpHandler) Http2MetricsChannelHandlers(com.netflix.netty.common.metrics.Http2MetricsChannelHandlers) Http2ConnectionExpiryHandler(com.netflix.netty.common.Http2ConnectionExpiryHandler) Http2ConnectionCloseHandler(com.netflix.netty.common.Http2ConnectionCloseHandler) SslHandler(io.netty.handler.ssl.SslHandler) ChannelPipeline(io.netty.channel.ChannelPipeline)

Example 4 with ChannelConfig

use of com.netflix.netty.common.channel.config.ChannelConfig in project zuul by Netflix.

the class BaseZuulChannelInitializerTest method tcpHandlersAdded_withProxyProtocol.

@Test
public void tcpHandlersAdded_withProxyProtocol() {
    ChannelConfig channelConfig = new ChannelConfig();
    channelConfig.set(CommonChannelConfigKeys.withProxyProtocol, true);
    ChannelConfig channelDependencies = new ChannelConfig();
    channelDependencies.set(ZuulDependencyKeys.registry, new NoopRegistry());
    channelDependencies.set(ZuulDependencyKeys.rateLimitingChannelHandlerProvider, new NullChannelHandlerProvider());
    channelDependencies.set(ZuulDependencyKeys.sslClientCertCheckChannelHandlerProvider, new NullChannelHandlerProvider());
    ChannelGroup channelGroup = new DefaultChannelGroup(GlobalEventExecutor.INSTANCE);
    BaseZuulChannelInitializer init = new BaseZuulChannelInitializer("1234", channelConfig, channelDependencies, channelGroup) {

        @Override
        protected void initChannel(Channel ch) {
        }
    };
    EmbeddedChannel channel = new EmbeddedChannel();
    init.addTcpRelatedHandlers(channel.pipeline());
    assertNotNull(channel.pipeline().context(SourceAddressChannelHandler.class));
    assertNotNull(channel.pipeline().context(PerEventLoopMetricsChannelHandler.Connections.class));
    assertNotNull(channel.pipeline().context(ElbProxyProtocolChannelHandler.NAME));
    assertNotNull(channel.pipeline().context(MaxInboundConnectionsHandler.class));
}
Also used : DefaultChannelGroup(io.netty.channel.group.DefaultChannelGroup) SourceAddressChannelHandler(com.netflix.netty.common.SourceAddressChannelHandler) ChannelConfig(com.netflix.netty.common.channel.config.ChannelConfig) NoopRegistry(com.netflix.spectator.api.NoopRegistry) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) Channel(io.netty.channel.Channel) MaxInboundConnectionsHandler(com.netflix.netty.common.throttle.MaxInboundConnectionsHandler) NullChannelHandlerProvider(com.netflix.zuul.netty.ratelimiting.NullChannelHandlerProvider) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) ChannelGroup(io.netty.channel.group.ChannelGroup) DefaultChannelGroup(io.netty.channel.group.DefaultChannelGroup) Test(org.junit.Test)

Example 5 with ChannelConfig

use of com.netflix.netty.common.channel.config.ChannelConfig in project zuul by Netflix.

the class Http2OrHttpHandlerTest method swapInHttp2HandlerBasedOnALPN.

@Test
public void swapInHttp2HandlerBasedOnALPN() throws Exception {
    EmbeddedChannel channel = new EmbeddedChannel();
    final NoopRegistry registry = new NoopRegistry();
    final ChannelConfig channelConfig = new ChannelConfig();
    channelConfig.add(new ChannelConfigValue<>(CommonChannelConfigKeys.maxHttp2HeaderListSize, 32768));
    Http2ConnectionCloseHandler connectionCloseHandler = new Http2ConnectionCloseHandler(registry);
    Http2ConnectionExpiryHandler connectionExpiryHandler = new Http2ConnectionExpiryHandler(100, 100, 20 * 60 * 1000);
    Http2MetricsChannelHandlers http2MetricsChannelHandlers = new Http2MetricsChannelHandlers(registry, "server", "http2-443");
    final Http2OrHttpHandler http2OrHttpHandler = new Http2OrHttpHandler(new Http2StreamInitializer(channel, (x) -> {
    }, http2MetricsChannelHandlers, connectionCloseHandler, connectionExpiryHandler), channelConfig, cp -> {
    });
    channel.pipeline().addLast("codec_placeholder", new DummyChannelHandler());
    channel.pipeline().addLast(Http2OrHttpHandler.class.getSimpleName(), http2OrHttpHandler);
    http2OrHttpHandler.configurePipeline(channel.pipeline().lastContext(), ApplicationProtocolNames.HTTP_2);
    assertThat(channel.pipeline().get(Http2FrameCodec.class.getSimpleName() + "#0")).isInstanceOf(Http2FrameCodec.class);
    assertThat(channel.pipeline().get(BaseZuulChannelInitializer.HTTP_CODEC_HANDLER_NAME)).isInstanceOf(Http2MultiplexHandler.class);
    assertEquals("HTTP/2", channel.attr(Http2OrHttpHandler.PROTOCOL_NAME).get());
}
Also used : NoopRegistry(com.netflix.spectator.api.NoopRegistry) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) RunWith(org.junit.runner.RunWith) Http2FrameCodec(io.netty.handler.codec.http2.Http2FrameCodec) ChannelConfigValue(com.netflix.netty.common.channel.config.ChannelConfigValue) ApplicationProtocolNames(io.netty.handler.ssl.ApplicationProtocolNames) Test(org.junit.Test) JUnit4(org.junit.runners.JUnit4) Truth.assertThat(com.google.common.truth.Truth.assertThat) BaseZuulChannelInitializer(com.netflix.zuul.netty.server.BaseZuulChannelInitializer) CommonChannelConfigKeys(com.netflix.netty.common.channel.config.CommonChannelConfigKeys) Http2ConnectionExpiryHandler(com.netflix.netty.common.Http2ConnectionExpiryHandler) Http2MultiplexHandler(io.netty.handler.codec.http2.Http2MultiplexHandler) Http2ConnectionCloseHandler(com.netflix.netty.common.Http2ConnectionCloseHandler) ChannelConfig(com.netflix.netty.common.channel.config.ChannelConfig) Assert.assertEquals(org.junit.Assert.assertEquals) Http2MetricsChannelHandlers(com.netflix.netty.common.metrics.Http2MetricsChannelHandlers) ChannelConfig(com.netflix.netty.common.channel.config.ChannelConfig) NoopRegistry(com.netflix.spectator.api.NoopRegistry) Http2ConnectionExpiryHandler(com.netflix.netty.common.Http2ConnectionExpiryHandler) Http2MetricsChannelHandlers(com.netflix.netty.common.metrics.Http2MetricsChannelHandlers) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) Http2ConnectionCloseHandler(com.netflix.netty.common.Http2ConnectionCloseHandler) Test(org.junit.Test)

Aggregations

ChannelConfig (com.netflix.netty.common.channel.config.ChannelConfig)10 NoopRegistry (com.netflix.spectator.api.NoopRegistry)4 Channel (io.netty.channel.Channel)4 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)4 ChannelGroup (io.netty.channel.group.ChannelGroup)4 Test (org.junit.Test)4 NullChannelHandlerProvider (com.netflix.zuul.netty.ratelimiting.NullChannelHandlerProvider)3 DefaultChannelGroup (io.netty.channel.group.DefaultChannelGroup)3 Http2ConnectionCloseHandler (com.netflix.netty.common.Http2ConnectionCloseHandler)2 Http2ConnectionExpiryHandler (com.netflix.netty.common.Http2ConnectionExpiryHandler)2 SourceAddressChannelHandler (com.netflix.netty.common.SourceAddressChannelHandler)2 CommonChannelConfigKeys (com.netflix.netty.common.channel.config.CommonChannelConfigKeys)2 Http2MetricsChannelHandlers (com.netflix.netty.common.metrics.Http2MetricsChannelHandlers)2 ServerSslConfig (com.netflix.netty.common.ssl.ServerSslConfig)2 MaxInboundConnectionsHandler (com.netflix.netty.common.throttle.MaxInboundConnectionsHandler)2 BaseZuulChannelInitializer (com.netflix.zuul.netty.server.BaseZuulChannelInitializer)2 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 Truth.assertThat (com.google.common.truth.Truth.assertThat)1 DynamicIntProperty (com.netflix.config.DynamicIntProperty)1 SwallowSomeHttp2ExceptionsHandler (com.netflix.netty.common.SwallowSomeHttp2ExceptionsHandler)1