Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to set static discovery server in Zuul 2.3.0 #1119

Open
drmyr opened this issue Nov 4, 2021 · 1 comment
Open

Unable to set static discovery server in Zuul 2.3.0 #1119

drmyr opened this issue Nov 4, 2021 · 1 comment

Comments

@drmyr
Copy link

drmyr commented Nov 4, 2021

We are trying to disable Eureka and set a static discovery server in Zuul 2.3.0.

We have successfully disabled Eureka with the following configurations:

eureka.registration.enabled: "false"
eureka.shouldFetchRegistry: "false"
eureka.client.registerWithEureka: "false"
eureka.client.enabled: "false"
eureka.client.fetchRegistry: "false"
eureka.validateInstanceId: "false"
eureka.preferSameZone: "false"

After reading this prior ticket: #395, it seems like discovery can be set to a static server with the following configurations:

apibackend.ribbon.listOfServers: "https://other-path"
apibackend.ribbon.client.NIWSServerListClassName: "com.netflix.loadbalancer.ConfigurationBasedServerList"

and potentially also this config:

apibackend.ribbon.DeploymentContextBasedVipAddresses: "other-path:443"

However this configuration has not worked. The exception is always the same ClassCastException pasted below. It seems like the error has also been mentioned here: https://giters.com/Netflix/zuul/issues/1075. I have read their comments at the bottom, but have no figured out how to implement the workaround they are suggesting.

It seems like the exception is due to having to bind OriginManager.class to BasicNettyOriginManager.class, as the BasicNettyOriginManager.class will eventually create a DynamicServerResolver whose .resolve method does the cast to DiscoveryEnabledServer as seen in the stack trace below: https://github.com/Netflix/zuul/blob/master/zuul-discovery/src/main/java/com/netflix/zuul/discovery/DynamicServerResolver.java

However, I have not found any other implementations of OriginManager.class to bind to. Short of creating my own implemention of OriginManager.class, and copying all the code out of BasicNettyOriginManager.class et al, and replacing the DynamicServerResolver with something else, I am not sure how to proceed. The DynamicServerResolver is newed up in the DefaultClientChannelManager, which is in turn newed up in the BasicNettyOrigin.

2021-11-03 19:09:52,894 ERROR com.netflix.zuul.filters.endpoint.ProxyEndpoint [Salamander-ClientToZuulWorker-1] Error while connecting to origin, UUID {} 0d5de62e-29a7-4391-92d6-f0a7e3b37b95 java.lang.ClassCastException: class com.netflix.loadbalancer.Server cannot be cast to class com.netflix.niws.loadbalancer.DiscoveryEnabledServer (com.netflix.loadbalancer.Server and com.netflix.niws.loadbalancer.DiscoveryEnabledServer are in unnamed module of loader 'app') at com.netflix.zuul.discovery.DynamicServerResolver.resolve(DynamicServerResolver.java:55) at com.netflix.zuul.discovery.DynamicServerResolver.resolve(DynamicServerResolver.java:41) at com.netflix.zuul.netty.connectionpool.DefaultClientChannelManager.acquire(DefaultClientChannelManager.java:328) at com.netflix.zuul.origins.BasicNettyOrigin.connectToOrigin(BasicNettyOrigin.java:122) at com.netflix.zuul.filters.endpoint.ProxyEndpoint.proxyRequestToOrigin(ProxyEndpoint.java:423) at com.netflix.zuul.filters.endpoint.ProxyEndpoint.apply(ProxyEndpoint.java:297) at com.netflix.zuul.filters.endpoint.ProxyEndpoint.apply(ProxyEndpoint.java:121) at com.netflix.zuul.netty.filter.BaseZuulFilterRunner.filter(BaseZuulFilterRunner.java:221) at com.netflix.zuul.netty.filter.ZuulEndPointRunner.filter(ZuulEndPointRunner.java:95) at com.netflix.zuul.netty.filter.ZuulEndPointRunner.filter(ZuulEndPointRunner.java:51) at com.netflix.zuul.netty.filter.BaseZuulFilterRunner.invokeNextStage(BaseZuulFilterRunner.java:144) at com.netflix.zuul.netty.filter.ZuulFilterChainRunner.runFilters(ZuulFilterChainRunner.java:88) at com.netflix.zuul.netty.filter.ZuulFilterChainRunner.filter(ZuulFilterChainRunner.java:56) at com.netflix.zuul.netty.filter.ZuulFilterChainHandler.channelRead(ZuulFilterChainHandler.java:81) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357) at com.netflix.zuul.netty.server.ClientRequestReceiver.channelReadInternal(ClientRequestReceiver.java:168) at com.netflix.zuul.netty.server.ClientRequestReceiver.channelRead(ClientRequestReceiver.java:115) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357) at io.netty.handler.logging.LoggingHandler.channelRead(LoggingHandler.java:271) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357) at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:93) at com.netflix.netty.common.proxyprotocol.StripUntrustedProxyHeadersHandler.channelRead(StripUntrustedProxyHeadersHandler.java:93) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357) at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:93) at com.netflix.netty.common.accesslog.AccessLogChannelHandler$AccessLogInboundChannelHandler.channelRead(AccessLogChannelHandler.java:71) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357) at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:93) at com.netflix.netty.common.metrics.HttpBodySizeRecordingChannelHandler$InboundChannelHandler.channelRead(HttpBodySizeRecordingChannelHandler.java:85) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357) at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:93) at com.netflix.netty.common.HttpServerLifecycleChannelHandler$HttpServerLifecycleInboundChannelHandler.channelRead(HttpServerLifecycleChannelHandler.java:43) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357) at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:93) at com.netflix.netty.common.HttpRequestReadTimeoutHandler.channelRead(HttpRequestReadTimeoutHandler.java:78) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357) at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:93) at com.netflix.zuul.netty.insights.PassportStateHttpServerHandler$InboundHandler.channelRead(PassportStateHttpServerHandler.java:70) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357) at io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.fireChannelRead(CombinedChannelDuplexHandler.java:436) at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:324) at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:311) at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:432) at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:276) at io.netty.channel.CombinedChannelDuplexHandler.channelRead(CombinedChannelDuplexHandler.java:251) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357) at io.netty.handler.ssl.SslHandler.unwrap(SslHandler.java:1504) at io.netty.handler.ssl.SslHandler.decodeNonJdkCompatible(SslHandler.java:1265) at io.netty.handler.ssl.SslHandler.decode(SslHandler.java:1302) at io.netty.handler.codec.ByteToMessageDecoder.decodeRemovalReentryProtection(ByteToMessageDecoder.java:508) at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:447) at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:276) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357) at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:93) at com.netflix.zuul.logging.Http2FrameLoggingPerClientIpHandler.channelRead(Http2FrameLoggingPerClientIpHandler.java:46) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357) at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:93) at com.netflix.netty.common.throttle.MaxInboundConnectionsHandler.channelRead(MaxInboundConnectionsHandler.java:83) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357) at io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:286) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357) at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365) at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919) at io.netty.channel.epoll.AbstractEpollStreamChannel$EpollStreamUnsafe.epollInReady(AbstractEpollStreamChannel.java:795) at io.netty.channel.epoll.EpollEventLoop.processReady(EpollEventLoop.java:480) at io.netty.channel.epoll.EpollEventLoop.run(EpollEventLoop.java:378) at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989) at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) at java.base/java.lang.Thread.run(Thread.java:835)

@drmyr
Copy link
Author

drmyr commented Nov 4, 2021

I don't think this is the intended way to fix the issue, but the following appears to be working:

Add this config:

yourapp.ribbon.NFLoadBalancerClassName: com.example.StaticServerListLoadBalancer

And then add that class to your project:

package com.example;

import com.netflix.appinfo.InstanceInfo;
import com.netflix.loadbalancer.Server;
import com.netflix.loadbalancer.ZoneAwareLoadBalancer;
import com.netflix.niws.loadbalancer.DiscoveryEnabledServer;

public class StaticServerListLoadBalancer<T extends Server> extends ZoneAwareLoadBalancer<T> {

    @Override
    public Server chooseServer(final Object key) {
        final Server server = super.chooseServer(key);
        final InstanceInfo instanceInfo = InstanceInfo.Builder.newBuilder()
            .setPort(server.getPort())
            .setHostName(server.getHost())
            .setAppName("yourappname")
            .setInstanceId(server.getMetaInfo().getInstanceId())
            .build();
        return new DiscoveryEnabledServer(instanceInfo, true);
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant