How to correctly set management.context-path for spring boot admin client under eureka discovery environment?
Asked Answered
A

1

5

I am setting up the spring boot admin using spring cloud. Now I have set up a stand alone eureka server and one spring boot admin and some spring boot apps as admin clients. If I don't set management.context-path for all the clients, everything works fine. But Now I need to monitor all clients(some with no management.context-path, some with different management.context-paths). I know that I should use the meta-data to achieve this, but after reading the relative docs, I still could get this done. Here are my configurations on client and admin sides.

Client side:

spring:
  application:
    instance_id: user
    name: microservice-provider-user
management:
  context-path: '/mgmt'
eureka:
  client:
    serviceUrl:
      defaultZone: http://localhost:8761/eureka/
  instance:
    preferIpAddress: false
    statusPageUrlPath: ${management.context-path}${endpoints.info.path:/info}
    healthCheckUrlPath: ${management.context-path}${endpoints.health.path:/health}
    metadata-map:
      instanceId:
${spring.application.name}:${spring.application.instance_id:${random.value}}

Admin side:

spring:
  application:
    name: wahaha-admin
  boot:
    admin:
      routes:
        endpoints: env,metrics,trace,dump,jolokia,info,configprops,trace,logfile,refresh,flyway,liquibase,heapdump,hystrix.stream,turbine.stream

      url: http://${HOST_NAME:localhost}:${server.port}
      discovery:
        converter.management-context-path: '/mgmt'

Questions:

  1. I set the spring.boot.admin.discovery.converter.management-context-path to be /mgmt, the value is the same as the client side and this only works fine if I set all the client apps with the same value, and this is impossible. How should I do to support different management.context-path?

PS: I did all of these on my local desktop not on any public cloud, and will move to the product env later(still not using public cloud).

Analysis answered 9/11, 2016 at 10:39 Comment(0)
N
13

On the client:

eureka:
  instance:
    metadata-map:
      management.context-path: ${management.context-path}

As described in the docs:

If you want to customize the default conversion of services you can either add health.path, management.port and/or mangament.context-path entries to the services metadata.

Newfeld answered 9/11, 2016 at 12:17 Comment(8)
Hi, If I want to set different management.context-path for different clients, what should I set in the admin side for spring.boot.admin.discovery.converter.management-context-path?Analysis
How to set this config spring.boot.admin.discovery.converter on the admin side? @NewfeldAnalysis
leave spring.boot.admin.discovery.converter.management-context-pat‌​h empty (default)Newfeld
if you set eureka.instance.metadata-map.management.context-path=${management.context-path} on all clients sba will use the individal values from the metadata.Newfeld
You are right, I made it works this way. Thanks so much.Analysis
@Newfeld : What if my management.port is different ? I understand that we can set the port also within this metadata-map but that doesnt solve for healthCheckUrlPath. Currently, I have ${management.context-path}/health, but I want it to use the management.port for health check as well (without giving the entire path with hostname). Any suggestions? PS : Not posting as a new question since I thought this question was much relevant here since its very related.Bolognese
You can force the Spring Boot Admin to use the DefaultServiceInstanceConverter if you add a bean of this type. Then the management.port from the instance metadata is used to construct the healthUrl. And the healthCheckUrlPath from Eureka is ignored.Newfeld
I was chasing spring-admin configurations not fully groking the fact that spring-admin was only getting the values from eureka!! This worked perfectly!Small

© 2022 - 2024 — McMap. All rights reserved.