Configure consul health check to spring boot actuator '/health' - spring

For a microservice that I have been working on, I created a custom health check class extending AbstractHealthIndicator and able to get the output in
http://localhost:8080/actuator/health
But when I register the service with consul, the health check status is failing.
Tried to configure the actuator url with consul health check asspring.cloud.consul.discovery.health-check-url= http://localhost:8080/actuator/health in bootstrap. But it is still failing with error Get http://localhost:8566/actuator/health: dial tcp 127.0.0.1:8566: connect: connection refused
If I try with health-check-path: /actuator/health, it is not taking this path at all and defaulting to http://QINDW062.it.local:8566/my-health-check.
Any suggestions?
Edit:

You need to set a property in your configurations file (application.yml for example) pointing to your health check endpoint:
spring:
cloud:
consul:
discovery:
healthCheckPath: /actuator/health
You can also decide the time interval for the health check (how often Consul will call the health check) with the following property:
spring:
cloud:
consul:
discovery:
healthCheckInterval: 20s

Related

What is the use of "wait-time-in-ms-when-sync-empty" in Spring Eureka Server?

I was going through a tutorial and I came across with this config in .yml file.
eureka:
client:
registerWithEureka: false
fetchRegistry: false
server:
waitTimeInMsWhenSyncEmpty: 0
Here, what exactly is the purpose of "waitTimeInMsWhenSyncEmpty"? Also what does "fetchRegistry" flag say?
Thank you.
eureka:
client:
registerWithEureka: false
fetchRegistry: false
server:
waitTimeInMsWhenSyncEmpty: 0
Basically above three lines tells:
this instance to not register itself with the Eureka instance it finds, because that instance is.. itself.
Source :Spring Doc
Below are the individual statement level meanings:
Configuration tells eureka(client) to gets the registration information from the eureka server registry, the default is true
eureka:
client:
fetchRegistry: false
Configuration tells when the eureka server is started, you cannot wait for the instance registration information from the peer node. How long should it wait?source
eureka:
client:
server:
waitTimeInMsWhenSyncEmpty: 0
Usage : By default euraka server could act as both client and server.This is useful when we run multiple eureka servers to face SPOF issues.In this case , eureka could register both other microservice instances and naming server instances.

spring cloud discovery service - registering secure clients - healthCheckUrl

I have all clients (eureka instances) running with https. I have configured my eureka clients as mentioned in https://cloud.spring.io/spring-cloud-netflix/2.2.x/reference/html/#registering-a-secure-application
Everything in the config shown below works except the port information. Note that the config is clearly missing port information for all URLs, viz, statusPageUrl, healthCheckUrl and homePageUrl.
eureka:
instance:
nonSecurePortEnabled: false
securePortEnabled: true
**statusPageUrl: https://${eureka.hostname}/info**
**healthCheckUrl: https://${eureka.hostname}/health**
**homePageUrl: https://${eureka.hostname}/**
client:
serviceUrl:
defaultZone: ${EUREKA_SERVER}
healthcheck:
enabled: true
Since I have configured random port, I cannot hard code the port information in above urls. Could anyone please help me on this?
server:
port: 0

Spring Boot Eureka - Faster offline detection

I am using Spring Boot with Eureka and it works really good. But since a few hours, I wanted to detect offline Eureka instances/clients more quickly and I found no good documentation about Eureka's configuration properties. And I'm not even sure if it's possible because Eureka seems to presume that clients send their updates every 30 seconds.
I started to deactivate self-preservation mode and to increase the speed of renewal and interval updates and lower expiration durations but my Eureka server still needs two minutes to discover its offline clients.
After changing the renewal percent threshold the Eureka server didn't remove offline clients ever.
Is there any way to detect offline Eureka clients more quickly?
Server configuration:
eureka:
client:
registerWithEureka: false
fetchRegistry: false
server:
enableSelfPreservation: false
eviction-interval-timer-in-ms: 10000
response-cache-update-interval-ms: 5000
Client configuration:
eureka:
client:
serviceUrl:
defaultZone: ${EUREKA_URI:http://localhost:8761/eureka}
healthcheck:
enabled: true
instance:
lease-renewal-interval-in-seconds: 5
lease-expiration-duration-in-seconds: 15
edit:
Even health check url is not called more often. It is still called every 30 seconds.
Did you check Ribbon configuration. Ribbon can cache servers configuration upfront during startup and make use of it when Eureka-sever is down. Please check if ribbon is enabled on eureka-client app
The correct option to change the schedule was:
eureka.client.instance-info-replication-interval-seconds

hystrix.stream, management.port and Spring Cloud Turbine

My microservice with #EnableTurbine config:
turbine:
clusterNameExpression: new String('default')
appConfig: bestallning
bestallning is a #SpringCloudApplication, hystrix.stream is enabled. It registers in eureka and turbine app can find it. But it has management.port set to 8092 and server.port 8082. hystrix.stream binds to management.port
Turbine now tries to fetch hystrix.stream from server.port of bestallning, not management.port that hystrix.stream is bound to.
Fetching instance list for apps: [bestallning]
Fetching instances for app: bestallning
Received instance list for app: bestallning, size=1
Retrieved hosts from InstanceDiscovery: 1
Found hosts that have been previously terminated: 0
Hosts up:1, hosts down: 0
Url for host: http://143.237.21.196:8082/hystrix.stream default
Could not initiate connection to host, giving up: [{"timestamp":1460035761979,"status":404,"error":"Not Found","message":"No message available","path":"/hystrix.stream"}]
Stopping InstanceMonitor for: 143.237.21.196 default
Is it possible to have turbine look for hystrix.stream using the correct port?
I think you'd have to write your own InstanceDiscovery (and create a #Bean of that type). Might be a useful feature in the existing implementations though, so please open an issue in Spring Cloud Netflix.

Spring Cloud Turbine - Unable to handle multiple clients?

I’m having a bit of trouble getting Turbine to work in Spring Cloud. In a nutshell, I can’t determine how to configure it to aggregate circuits from more than one application at a time.
I have 6 separate services, a eureka server, and a turbine server running in standalone mode. I can see from my Eureka server that all of the services are registered, including turbine. My turbine server is up and running, and I can see its /hystrix page without issue. But when I try to use it to examine turbine.stream, I only see the FIRST server that is listed in turbine.appConfig, the rest are ignored.
This is my Turbine server’s application.yml, or at least the relevant parts:
---
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8010/eureka/
server:
port: 8030
info:
component: Turbine
turbine:
clusterNameExpression: new String(“default”)
appConfig: sentence,subject,verb,article,adjective,noun
management:
port: 8990
When I run this and access the hystrix dashboard on my turbine instance, asking for the turbine.stream, the ONLY circuit breakers listed in the output are for the first service listed in appConfig, the “sentence” service in this case. Curiously, if I re-arrange the order of these services and put another one first (like “noun”), I see only the circuits for THAT service. Only the first service in the list is displayed.
I’ll admit to being a little confused on some of the terminology, like streams, clusters, etc., so I could be missing some basic concept here, but my understanding is that Turbine could digest streams from more than one service and aggregate them in a single display. Suggestions would be appreciated.
I don't have enough reputation to comment, so I have to write this in an answer :)
I had the exactly same problem:
There are two services "test-service" and "other-service", each with it's own working hystrix-stream
and there is one Turbine-Application, which is configured like this:
turbine:
clusterNameExpression: new String("default")
appConfig: test-service,other-service
All of my services are running on my local machine.
Result is: My Hystrix-Dashboard just shows the metrics from "test-service".
Reason:
It seems to be, that a Turbine-Client which is configured the described way doesn't handle multiple services when they are running at the same host.
This is explained here:
https://github.com/Netflix/Hystrix/issues/117#issuecomment-14262713
Turbine maintains state of all these instances in order to maintain persistent connections to them and it does rely on the "hostname" and if the host name is the same then it won't instantiate a new connection to that same server (on a different port).
So the main point is, that all of your services must be registered with different hostnames. How you could do this on your local machine is described below.
UPDATE 2015-06-12/2016-01-23: Workaround for local testing
Change your hostfile:
# ...
127.0.0.1 localhost
127.0.0.1 localdomain1
127.0.0.1 localdomain2
# ...
127.0.0.1 localdomainx
And then set the hostname for your clients each to a different domain-entry like this:
application.yml:
eureka:
instance:
hostname: localdomainx

Resources