Springboot Actuator with Consul - spring-boot

In Consul, the health status configured in SpringBoot applications can be viewed.
Can anyone know let me know what other metrics (Other than health) can be seen in Consul through Actuator ?
Or can we make Consul to pull/invoke any services/URLs of a services so that the response could be viewed in consul ?

Consul is using health endpoints to determine whether service instance is healthy. If you want custom health status which considers some custom metrics you should implement HealthIndicator interface.
You can expose more information in health api by setting management.security.enabled=false in application.properties
In this case you'll see something like this in consul admin UI for your service
HTTP GET http://192.168.0.102:8080/health: 200 Output: {"description":"Composite Discovery Client","status":"UP","discoveryComposite":{"description":"Composite Discovery Client","status":"UP","discoveryClient":{"description":"Composite Discovery Client","status":"UP","services":["application","consul"]}},"diskSpace":{"status":"UP","total":499963170816,"free":341478899712,"threshold":10485760},"consul":{"status":"UP","leader":"127.0.0.1:8300","services":{"application":[],"consul":[]}},"hystrix":{"status":"UP"}}
You can configure health URL to different endpoint. For instance if you specify spring.cloud.consul.discovery.healthCheckPath=/health2 then your spring-boot instance will register with the following json (see log snippet below):
Registering service with consul: NewService{id='application', name='application', tags=[], address='192.168.0.102', port=8080, enableTagOverride=null, check=Check{script='null', interval='10s', ttl='null', http='http://192.168.0.102:8080/health2', tcp='null', timeout='null', deregisterCriticalServiceAfter='null', tlsSkipVerify=null, status='null'}, checks=null}

Related

Spring boot microservices are getting registered to Eureka with the pod name as the hostname in the Kubernetes cluster - docker desktop

The microservices are getting registered to Eureka with the pod name as hostname, this causing UnknownHostException, when the Zull API gateway trying to forward the request to the service.
The complete setup working fine with the docker-compose, the issues are happening when I am trying to use the Kubernetes.
For example, the order microservice running with the pod name as "oc-order-6b64576f4b-7gp85" and the order microservice getting register to to Eureka with "oc-order-6b64576f4b-7gp85" as the hostname. Which is causing
java.net.UnknownHostException: oc-order-6b64576f4b-7gp85: Name does not resolve
I am running just one instance of each micro-services as a POC and one instance of the Eureka server. How to fix, how micro-service can register them self with the right hostname.
I want to use the Eureka as discovery service as it is well integrated with spring boot and I do not want to do code changes for Kubernetes deployment.
Add the below property to your spring properties file in each service project:
eureka.instance.hostName=${spring.application.name}
or (if you want a different name than the spring application name)
eureka.instance.hostName=<custom-host-name>
Spring boot will now register with the provided hostname in Eureka

Call to service by the gateway is not found

I'm starting with spring cloud.
I created 3 application, one is for discovery service, one for gateway and one is a service.
I'm not using actually spring cloud config and any load balacing
For my discovery
server.port=8761
spring.application.name=discovery-service
eureka.instance.hostname=localhost
eureka.client.registerWithEureka=false
eureka.client.fetchRegistry=false
eureka.client.serviceUrl.defaultZone=http://${eureka.instance.hostname}:${server.port}/eureka/
For my gateway
#Port for Registry service
server.port=8080
spring.application.name=gateway-service
spring.cloud.gateway.discovery.locator.enabled=true
spring.cloud.gateway.routes[0].id=hostel-service
spring.cloud.gateway.routes[0].uri=lb://hostel-service
spring.cloud.gateway.routes[0].predicates[0]=Path=/hostels/**
eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka/
For my hostels service
server.port=9000
spring.application.name=hostel-service
eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka/
I see then hostel service is registered in the discovery service
Registered instance HOSTEL-SERVICE/192.168.102.129:hostel-service:9000
with status UP (replication=false)
See it to when i go to http://localhost:8761/
When I try to call
http://localhost:8080/hostels
or
http://localhost:8080/hostel-service/hostels
I get a 404 error
If I do
http://localhost:9000/hostels
I get good results
Edit
Code on github
https://github.com/mctdi/hostel
https://github.com/mctdi/gateway
https://github.com/mctdi/discovery
The hostels app registers in Service Discovery, but the gateway app doesn't. Add 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client' to you implementation dependencies in build.gradle - it will then register in Eureka and the http://localhost:8080/hostels request will be routed to the hostels app.

Problems setting up Zuul proxy server with Eureka discovery

I am trying to set up a zuul proxy server which will act as a gateway service for other apis in my microservice architecture.
So far all the tutorials that I have come across have the discovery client and zuul proxy set up in different gradle modules while I am trying to set them up in the same gradle module.
I have defined the routes and can see that my services have been successfully registered in the eureka dashboard.
I have also verified that I can ping the services using a discovery client from my gatekeeper service but whenever I try to access the services from the URL, I get
"Load balancer does not have available server for client:xyz"
exception.
Can somebody please help me setting this up?

How to capture log on each instance of the microservice through zuul

I have setup multiple instances of my microservice and registered to my eureka server. It uses ribbon for client side load balancing and uses zuul as gateway server. All usual stuff. I would like to capture the logs of which instance of my service is responding for each request. So that I can able to bring some conclusion based on my usage of each instances. How to do that?
You can try to set the loglevel just of the LoadBalancerContext to debug in application.properties
#logging
logging.level.com.netflix.loadbalancer.LoadBalancerContext=DEBUG

Load Balancing micro services using Spring cloud Netflix OSS

I have a microservice built using Spring Boot and Netflix OSS. I have used Central config server, Eureka and Zuul. Because of scalability multiple instances of the services is running on different port. All the instances are registered in Eureka but requests are going to only last registered server.
How to load balance services. Should I use ribbon in Zuul to load balance? Please let me know how to achieve load balancing on same service running on multiple instances.
If there is a code change required a snippet then please post a code snippet as well.
Application Config
spring.application.name=book-service
server.port=0
eureka.client.region = default
eureka.client.registryFetchIntervalSeconds = 5
eureka.client.serviceUrl.defaultZone=http://discUser:discPassword#localhost:10082/eureka/
#eureka.instance.metadataMap.instanceId=${spring.application.name}:${spring.application.instance_id:${random.value}}
eureka.instance.instanceId=${spring.application.name}:${spring.application.instance_id:${random.value}}
eureka.instance.leaseRenewalIntervalInSeconds=5
eureka.instance.leaseExpirationDurationInSeconds=5
Eureka Config
spring.application.name=discovery
server.port=10082
eureka.instance.hostname=localhost
eureka.client.serviceUrl.defaultZone=http://discUser:discPassword#localhost:10082/eureka/
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false
spring.session.store-type=hash-map
ZUUL Config
spring.application.name=gateway
server.port=10080
eureka.client.region = default
eureka.client.registryFetchIntervalSeconds = 5
management.security.sessions=always
zuul.routes.book-service.path=/book-service/**
zuul.routes.book-service.sensitive-headers=Set-Cookie,Authorization
hystrix.command.book-service.execution.isolation.thread.timeoutInMilliseconds=600000
#zuul.routes.rating-service.path=/rating-service/**
#zuul.routes.rating-service.sensitive-headers=Set-Cookie,Authorization
#hystrix.command.rating-service.execution.isolation.thread.timeoutInMilliseconds=600000
zuul.routes.discovery.path=/discovery/**
zuul.routes.discovery.sensitive-headers=Set-Cookie,Authorization
zuul.routes.discovery.url=http://localhost:8082
hystrix.command.discovery.execution.isolation.thread.timeoutInMilliseconds=600000
logging.level.org.springframework.web.=debug
logging.level.org.springframework.security=debug
logging.level.org.springframework.cloud.netflix.zuul=debug
spring.session.store-type=hash-map
Registering application properly with Eureka will do the trick.
Below entries will uniquely register services with Eureka.
#eureka.instance.metadataMap.instanceId=${spring.application.name}:${spring.application.instance_id:${random.value}}
eureka.instance.instanceId=${spring.application.name}:${spring.application.instance_id:${random.value}}

Categories

Resources