spring-boot icon indicating copy to clipboard operation
spring-boot copied to clipboard

Support multi-segment paths when mapping a health group to an additional path

Open MelleD opened this issue 1 month ago • 4 comments

Context: I have all actuator endpoints on a protected server port. In addition to health, I would also like to share them on the main server. However, health is then always directly on the root path, e.g. http://localhost:8080/health.

I have tested various options for inserting a base path.

None of them work.

Case 1:

management.endpoint.health.group.public.additional-path=server:/myBasePath/health

Error:
Caused by: java.lang.IllegalArgumentException: 'value' must contain only one segment.
	at org.springframework.util.Assert.isTrue(Assert.java:116) ~[spring-core-6.2.12.jar:6.2.12]

Case 2:

management.endpoint.health.group.public.additional-path=server:/health
management.server.base-path=/myBasePath
#management.endpoints.web.base-path=/myBasePath
#management.endpoints.web.path-mapping.health=myBasePath/health

http://localhost:8080/myBasePath/health --> not found

Is this a bug or what is the reason that there is no base path on the main port?

MelleD avatar Dec 02 '25 08:12 MelleD

This isn't supported at the moment.

Case 1 is working as documented:

This would make the live health group available on the main server port at /healthz. The prefix is mandatory and must be either server: (represents the main server port) or management: (represents the management port, if configured.) The path must be a single path segment.

Case 2 is also working as I would expect. The management server's base path has no effect as you're exposing the endpoint on the main (not management) server.

We might be able to relax the restriction in case 1, but I don't recall the reasons for it so it may not be possible. I'll discuss it with the rest of the team.

wilkinsona avatar Dec 02 '25 09:12 wilkinsona

That would be great, because if you are behind a Spring Cloud gateway with the same domain, for example, you have no chance (except with a lot of configuration and stripping) of forwarding the health check to the service if you have more than 1 service

MelleD avatar Dec 02 '25 09:12 MelleD

I have a feeling we used a single path to align with standard actuator mappings where the endpoint ID is used as the path and cannot contains /. Looking at AdditionalHealthEndpointPathsWebMvcHandlerMapping, I think it should be possible to support more segments (at least for Spring MVC). The org.springframework.boot.webmvc.actuate.endpoint.web.AbstractWebMvcEndpointHandlerMapping.createRequestMappingInfo(WebOperationRequestPredicate, String) method already has subPath support.

philwebb avatar Dec 02 '25 17:12 philwebb

I have a feeling we used a single path to align with standard actuator mappings where the endpoint ID is used as the path and cannot contains /. Looking at AdditionalHealthEndpointPathsWebMvcHandlerMapping, I think it should be possible to support more segments (at least for Spring MVC). The org.springframework.boot.webmvc.actuate.endpoint.web.AbstractWebMvcEndpointHandlerMapping.createRequestMappingInfo(WebOperationRequestPredicate, String) method already has subPath support.

Yes could be: then maybe an additional-base-path is missing, but looks then maybe confusing with the server: and management: prefix

MelleD avatar Dec 02 '25 17:12 MelleD