Spring boot admin with Eureka client and custom context path fails on health status - spring-boot

I have configured my spring boot application monitor-client to register to Eureka. I have a separate spring boot admin (SBA) application monitor that monitors all applications registered to Eureka.
If the context-path is not set in my application, everything is working fine. However if the context-path is set, SBA does not show correct information anymore. From the documentation it seems that I need to update the metadata properties of Eureka which I have done.
My monitor application is configured as follows:
application.properties:
spring.application.name=monitor-client
server.servlet.context-path=/monitor-client
server.port=9876
# Monitoring config
management.endpoints.web.exposure.include=*
eureka.instance.metadataMap.management.context-path=/monitor-client/actuator
My application is showing as 'offline' but I can browse all the details in the 'insight' tab. I suppose SBA correctly access the actuator endpoints but incorrectly uses the /health endpoint and I do not understand how that is possible?
If I go to the administration interface of SBA, I notice that the wrench endpoint and the health endpoint are not the same:
localhost:9876/monitor-client/actuator (wrench)
localhost:9876/actuator/health (health)
I've fiddled around with some settings but between the managment settings, the actuator settings and the eureka settings, I'm not sure which one is to be configured for this to work.
I've tried:
management.endpoints.web.base-path
eureka.instance.health-check-url-path
I'm currently using spring boot 2.1.2.RELEASE and matching version of SBA

Can you try with these configuration
server:
servlet:
context-path: /monitor-client
#management config
eureka:
instance:
health-check-url-path: /actuator/health
metadata-map:
management.context-path: /monitor-client/actuator
client:
serviceUrl:
defaultZone: ${EUREKA_SERVICE_URL:http://localhost:8761}/eureka/
management:
endpoint:
health:
show-details: always
endpoints:
web:
base-path: /actuator
exposure:
include: "*"

Related

How can I debug a failing spring boot actuator health indicator while spring security is on the classpath?

I am trying to see which health indicators get auto configured in spring boot actuator. i'm using spring boot 2.2.6, when I run my application locally and I navigate to /actuator/health I see "Status":"up". when I deploy my application on a openshift cluster however the status always shows down so i'm guessing one of the auto configured health indicators are failing. I use a custom JWT security implementation and it would be impossible to configure the Openshift readiness and liveness probes to use my security implementation. I tried all suggestions I could find on Stackoverflow to set the actuator health endpoint to show all details including setting management.endpoint.show-details to always, management.endpoints.sensitive to "*" or false, management.security.enabled to false etc etc. Nothing seems to work and i'm running out of ideas... i'm thinking that I manually need to start disabling all health checks and then re-enable them one by one to debug this? Any help/suggestions would be much appreciated, my latest management section of my application config file is below...
my config:
management:
security:
enabled: false
#defaults:
#enabled: false
#consul:
#enabled: false
endpoint:
health:
show-details: always
show-components: always
solr:
enabled: false
endpoints:
health:
sensitive: "*"
web:
exposure:
include: "*"
set
endpoints.health.sensitive : false
NOT "management.endpoints.health.sensitive".
It should help you to debug. Also
management.endpoint.health.show-details: always
in your setup there is a security level between management and endpoint.

Actuator endpoints not exposed via HTTP in Spring boot 1.5.2 version in same port as application is running

I am using springboot version 1.5.2.RELEASE and i tried to implement spring boot actuator in my application. I am running my application in port 8081 . I just want to expose two end points i.e health and info. When i try to access end points in port 8081 same as my application, it does not gives the result and shows 404 not found status in Postman. I can access the health end point in port 8089 as http://localhost:8089/admin/info. Same thing i could not achieve in port 8081. I have searched for the answer and could not find proper answer for spring boot version 1.5.2.
My application.yml file looks like this:
management:
context-path : /admin
endpoints:
web:
exposure:
include: health,info
jmx:
exposure:
exclude: '*'
security:
enabled: true
port: 8081
If you have your management.port set to 8089, then you will only be able to access the management APIs at that port. You will not be able to reach them at the application port 8081
If you would like to reach the management APIs at the application port, do not set the managment.port value. It defaults to the same port as the application port.

Auto-configure routes with Zuul and Eureka

Through reading various books / tutorials, it appears that it is possible to auto-configure routes in Zuul when using it in combination with Eureka service discovery. That means that I don't have to explicitly add routes to Zuul's application.properties.
So I understand this correctly? Or do I still need to add routes explicitly to Zuul in order it to work as a gateway?
I would like it to automatically create routes from the application name's that are registered with Eureka. Is this possible?
(Note: I have actually tried this, but when I go to http://localhost:8762/routes I just get an error page.)
Sure. In most microservices implementations, internal microservices endpoints are not exposed outside. A set of public services will be exposed to the clients using an API gateway.
The zuul proxy internally uses the Eureka Server for service discovery.
I would like it to automatically create routes from the application name's that are registered with Eureka. Is this possible?
Sure. I will show you gateway example.
1. Create your service project (user-service)
create application.properties file
# --- Spring Config
spring:
application:
name: OVND-USER-SERVICE
# Eureka client
eureka:
client:
serviceUrl:
defaultZone: ${EUREKA_URL:http://localhost:8761/eureka/}
2. Setting up Zuul project (Gateway-service)
1.#EnableZuulproxy to tell Spring Boot that this is a Zuul proxy
#SpringBootApplication
#EnableZuulProxy
#EnableDiscoveryClient
public class GatewayServiceApplication {
2.create an application.properties file
# =======================================
# Gateway-service Server Configuration
# =======================================
# --- Spring Config
spring:
application:
name: gateway-service
server:
port: ${PORT:8080}
# Eureka client
eureka:
client:
serviceUrl:
defaultZone: ${EUREKA_URL:http://localhost:8761/eureka/}
zuul:
host:
routes:
## By default, all requests to user service for example will start with: "/user/"
## What will be sent to the user service is what comes after the path defined,
## So, if request is "/user/v1/user/tedkim", user service will get "/v1/user/tedkim".
user-service:
path: /user/**
service-id: OVND-USER-SERVICE
another-service:
path: /another/**
service-id: OVND-ANOTHER-SERVICE
Eureka website ( localhost:8761 )
Yes. You can integrate Zuul with Eureka and configure the routes based on application names registered in Eureka. Just add the following configuration to Zuul application:
zuul:
ignoredServices: "*"
routes:
a-service: /a-service/**
b-service: /b-service/**
c-service: /c-service/**
d-service: /d-service/**

Actuator Exposing Endpoints not working

I am using spring boot 2.0.4 and want to expose my actuator endpoints. When adding the following to application.yml only info, health are being exposed.
management:
endpoints:
web:
exposure:
include: "*"
When I run http://localhost:8080/actuator I get
{"_links":{"self":{"href":"http://localhost:8080/actuator","templated":false},"health":{"href":"http://localhost:8080/actuator/health","templated":false},"info":{"href":"http://localhost:8080/actuator/info","templated":false}}}
Spring Boot 2.0 takes a slightly different approach to ensure web endpoints security. The majority of Web endpoints are now disabled by default (Only the /health and /info endpoints are exposed) and the management.security.enabled property has been removed. There is no longer a separate security auto-configuration for the Actuator, individual endpoints may be enabled/disabled and/or exposed via configuration in the application.properties file. For example:
# disable beans endpoint
management.endpoints.beans.enabled=false
# expose all endpoints:
management.endpoints.web.exposure.include=*
See additional info Spring official documentation: https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.0-Migration-Guide#endpoints

Combining SpringBoot, Zuul and Eureka but bind Services to Localhost

I have set up Zuul for routing and Eureka for service discovery, which works fine. Before setting up Eureka, I used server.address=127.0.0.1 to bind my actual service to localhost so that they could only be accessed from within the Api gateway.
When combining Zuul and Eureka, server.address=127.0.0.1 does not work anymore. I cannot access my actual REST endpoints, neither from within my network nor from the outside.
application.properties of my Eureka service discovery:
spring.application.name=service-discovery
server.port=8761
eureka.client.registerWithEureka=false
eureka.client.fetchRegistry=false
application.properties of my Zuul API gateway:
spring.application.name=api-gateway
zuul.prefix=/api
server.port=8080
ribbon.eureka.enabled=true
eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka/
zuul.routes.library.path=/library/**
zuul.routes.library.serviceId=library
application.properties of my actual REST service:
spring.application.name=library
server.servlet.context-path=/library
server.port=8090
server.address=127.0.0.1
ribbon.eureka.enabled=true
eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka/
When I remove server.address=127.0.0.1 from the REST service's properties file, I can of course access the resource - But also from without localhost, which is not what I want.
So what I try to achieve is that my little microservices can only be accessed from within localhost (after the request has passed the Zuul API gateway). Furthermore I want to use Eureka for service discovery and for having the chance to provide second instances of serives.
Registering the actual microservices with eureka.instance.hostname=localhost or eureka.instance.ip-address=127.0.0.1 to the Eureka server, combined with a binding of the microservice to localhost (server.address=127.0.0.1) did the job.
These are the application.properties files:
application.properties of my Eureka service discovery:
spring.application.name=service-discovery
server.port=8761
server.address=127.0.0.1
eureka.client.registerWithEureka=false
eureka.client.fetchRegistry=false
application.properties of my Zuul API gateway:
spring.application.name=api-gateway
zuul.prefix=/api
server.port=8080
ribbon.eureka.enabled=true
eureka.client.registerWithEureka=false
zuul.routes.library.path=/library/**
zuul.routes.library.serviceId=library
zuul.routes.library.stripPrefix=false
application.properties of my actual REST service:
spring.application.name=library
server.servlet.context-path=/library
server.port=8090
server.address=127.0.0.1
ribbon.eureka.enabled=true
eureka.client.registerWithEureka=true
eureka.instance.hostname=localhost
eureka.instance.ip-address=127.0.0.1
The "library" microservice is now only available from localhost but still registered at Eureka and behind the Zuul API gateway.

Resources