spring-cloud-netflix-eureka-client reports wrong health-check-url and status-page-url , when server.port == management.port and server.context-path is set.
server.context-path=/sc
management.context-path=/actuator
It report health-check-url as 'http://localhost:8080/actuator/health' instead of 'http://localhost:8080/sc/actuator/health'.
It is the error of DefaultManagementMetadataProvider.refineManagementContextPath of commit 62a8f72b983a5dd501cbbda327291bee834544f1
And the code shuold be:
private boolean isSamePort(int serverPort, Integer managementPort) {
return managementPort == null || (serverPort == managementPort && serverPort != RANDOM_PORT);
}
private String refineManagementContextPath(String serverContextPath, String managementContextPath,
int serverPort, Integer managementPort) {
if(isSamePort(serverPort, managementPort)) {
if (managementContextPath != null) {
if (serverContextPath.endsWith("/") || managementContextPath.startsWith("/")) {
return serverContextPath + managementContextPath;
} else {
return serverContextPath + "/" + managementContextPath;
}
} else {
return serverContextPath;
}
} else {
if (managementContextPath != null) {
return managementContextPath;
} else {
return "/";
}
}
}
PRs welcome
Related to this is also if server.context-path and management.context-path is set. Then the server.context-path is not respected and/or management.context-path is added twice, leading to urls similar to hostname:port/manage/app/manage/health.
I found this in Edgware.SR2.
Here some configuration examples and resulting URLs.
server:
context-path: /${spring.application.name}
management:
context-path: /manage
eureka:
instance:
health-check-url-path: ${server.context-path}${management.context-path}/health
home-page-url-path: ${server.context-path}
lease-renewal-interval-in-seconds: 15
metadata-map:
management:
context-path: ${server.context-path}${management.context-path}
non-secure-port: ${server.port}
non-secure-port-enabled: false
secure-port: ${server.port}
secure-port-enabled: true
status-page-url-path: ${server.context-path}${management.context-path}/info
Health URL: http://10.0.2.15:8443/manage/spring-template/manage/health
Management URL: http://10.0.2.15:8443/spring-template/manage
Service URL: http://10.0.2.15:8443/
2018-02-16 06:55:01.183Z DEBUG [ main] .n.e.m.DefaultManagementMetadataProvider {} : Constructed eureka meta-data healthcheckUrl: http://10.0.2.15:8443/manage/spring-template/manage/health
2018-02-16 06:55:01.184Z DEBUG [ main] .n.e.m.DefaultManagementMetadataProvider {} : Constructed eureka meta-data statusPageUrl: http://10.0.2.15:8443/manage/spring-template/manage/info
As you can see Health URL, healthcheckUrl and statusPageUrl are not created correctly as the management-context is added twice. The Management URL in turn is created correctly.
It seems to be that the server.context-path is ignored and that the management.context-path is always used as the prefix for the health url. I checked also other combinations with the same result. By this it is practically impossible to construct a valid health URL
I think the problem is in https://github.com/spring-cloud/spring-cloud-netflix/blob/6b023df258491017f21de2d802234e79b48cf1c5/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/metadata/DefaultManagementMetadataProvider.java#L72 which ignores any server context path if a management context path is set.
In Dalston this was working properly.
@christiangalsterer are you interested in submitting a PR? If not we will try to get to it soon.
This one works for me
eureka:
instance:
health-check-url-path: /health
home-page-url-path: ${server.servlet.context-path}
lease-renewal-interval-in-seconds: 15
metadata-map:
management:
context-path: ${management.server.servlet.context-path}
status-page-url-path: /info
client:
registryFetchIntervalSeconds: 5
serviceUrl:
defaultZone: ${EUREKA_SERVICE_URL:http://localhost:8082}/eureka
Most helpful comment
Here some configuration examples and resulting URLs.
Health URL: http://10.0.2.15:8443/manage/spring-template/manage/health
Management URL: http://10.0.2.15:8443/spring-template/manage
Service URL: http://10.0.2.15:8443/
As you can see Health URL, healthcheckUrl and statusPageUrl are not created correctly as the management-context is added twice. The Management URL in turn is created correctly.
It seems to be that the server.context-path is ignored and that the management.context-path is always used as the prefix for the health url. I checked also other combinations with the same result. By this it is practically impossible to construct a valid health URL
I think the problem is in https://github.com/spring-cloud/spring-cloud-netflix/blob/6b023df258491017f21de2d802234e79b48cf1c5/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/metadata/DefaultManagementMetadataProvider.java#L72 which ignores any server context path if a management context path is set.
In Dalston this was working properly.