Search code examples
spring-cloudturbinehystrixnetflix-eureka

Spring Boot with server.contextPath set vs. URL to hystrix.stream via Eureka Server


I have Eureka Server with Turbine instance running and a few discovery clients that are connected to it. Everything works fine, but if I register a discovery client that has server.contextPath set, it didn't get recognized by InstanceMonitor and Turbine stream is not able to combine its hystrix.stream.

This is how it looks in the logs of Eureka/Turbine server:

2015-02-12 06:56:23.265  INFO 1 --- [        Timer-0] c.n.t.discovery.InstanceObservable       : Hosts up:3, hosts down: 0
2015-02-12 06:56:23.266  INFO 1 --- [        Timer-0] c.n.t.monitor.instance.InstanceMonitor   : Url for host: http://user-service:8887/hystrix.stream default
2015-02-12 06:56:23.268 ERROR 1 --- [InstanceMonitor] c.n.t.monitor.instance.InstanceMonitor   : Could not initiate connection to host, giving up: []
2015-02-12 06:56:23.269  WARN 1 --- [InstanceMonitor] c.n.t.monitor.instance.InstanceMonitor   : Stopping InstanceMonitor for: user-service default

com.netflix.turbine.monitor.instance.InstanceMonitor$MisconfiguredHostException: []
    at com.netflix.turbine.monitor.instance.InstanceMonitor.init(InstanceMonitor.java:318)
    at com.netflix.turbine.monitor.instance.InstanceMonitor.access$100(InstanceMonitor.java:103)
    at com.netflix.turbine.monitor.instance.InstanceMonitor$2.call(InstanceMonitor.java:235)
    at com.netflix.turbine.monitor.instance.InstanceMonitor$2.call(InstanceMonitor.java:229)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)

It tries to get hystrix stream from http://user-service:8887/hystrix.stream where the correct URL including sever.contextPath should be http://user-service:8887/uaa/hystrix.stream

The application.yml of that client contains:

server:
  port: 8887
  contextPath: /uaa

security:
  ignored: /css/**,/js/**,/favicon.ico,/webjars/**
  basic:
    enabled: false

My question is: should I add some additional configuration options to this user-service discovery client to register proper hystrix.stream URL location?

I didn't dig into that yet, I will let you know if found something before getting answer to that question.

Current solution

There is one problem when it comes to using server.contextPath and management.context-path. When both are set, turbine stream is being served on ${HOST_URL}/${server.contextPath}/${management.context-path}/hystrix.stream. In that case I had to drop using server.contextPath (I replaced it with a prefix in controllers @RequestMapping).

Now, when you user management.context-path, then your hystrix.stream is being served from the URL that uses it as a prefix. In that case you have to follow Spencer's suggestion and set

turbine.instanceUrlSuffix=/{PUT_YOUR_MANAGEMENT_CONTEXT_PATH_HERE}/hystrix.stream

And of course this management.context-path must be set with the same value for all your Discovery Clients - it can be done easily with Spring Cloud Config http://cloud.spring.io/spring-cloud-config/spring-cloud-config.html


Solution

  • You can set turbine.instanceUrlSuffix.<CLUSTERNAME>=/uaa/hystrix.stream. Where <CLUSTERNAME> is the value set in turbine.aggregator.clusterConfig. All of the config options from the Turbine 1 wiki work. You don't need to add the port to the suffix as Spring Cloud Netflix Turbine adds the port from eureka.