question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add configuration to set href base-path in WebMvcEndpointHandlerMapping Actuator links

See original GitHub issue

If you run a spring-boot application inside a docker container on context root, the actuator endpoint is exposed at: localhost:8080/actuator. (assuming the docker container runs on 8080).

Spring generated the base url for the actuator links by request.getRequestURL(). And as inside a docker container, this is also always the context root:

{
    "_links": {
        "self": {
            "href": "http://localhost:8080/actuator",
            "templated": false
        },
        "auditevents": {
            "href": "http://localhost:8080/actuator/auditevents",
            "templated": false
        },
        "health": {
            "href": "http://localhost:8080/actuator/health",
            "templated": false
        },
        ....

Problem: when you’re behind a loadbalancer or a simple apache2 reverse proxy, you may face situations where the actuator endpoint must be “rewritten”. If you run multiple applications on a host, you often have a subpath mapping as follows (in this case apache2, but it does not matter):

ProxyPass https://yourhost/api1 http://localhost:8080
ProxyPassReverse https://yourhost/api1 http://localhost:8080

ProxyPass https://yourhost/api2 http://localhost:8081
ProxyPassReverse https://yourhost/api2 http://localhost:8081

This way, clients can connect via SSL without opening extra ports, and forward them to the desired docker app.

Problem: request.getRequestURL() only sees the forwarded request, not the original request. As a result, health endpoints always result in https://yourhost/actuator or https://yourhost/actuator/health, which thus never reach the desired actuator endpoint (as the subpath mapping for apache2 is missing).

It should thus be possible to set the base-path for the actuator endpoint href links explicit via configuration, but without changing the actual path on which the actuator endpoint is accessed (it should still be exposed under the /actuator root context).

org.springframework.boot.actuate.endpoint.web.servlet.WebMvcEndpointHandlerMapping.class:

	class WebMvcLinksHandler implements LinksHandler {
		@Override
		@ResponseBody
		public Map<String, Map<String, Link>> links(HttpServletRequest request, HttpServletResponse response) {
			return Collections.singletonMap("_links",
					WebMvcEndpointHandlerMapping.this.linksResolver.resolveLinks(request.getRequestURL().toString()));
		}
	}

I know there is management.endpoints.web.base-path, but this actually changes also the path where the actuator is exposed. I’m looking for a way that only changes the base path that is used to generate the links, but keeps the actuator at default path.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
bclozelcommented, Jun 28, 2022

This is really a proxy issue. You could address this limitation with a Servlet filter, but I strongly suggest to try and solve this problem at the proxy level as it should.

0reactions
philwebbcommented, Jul 6, 2022

There’s not way to use ForwardedHeaderFilter and not remove the headers. The source code for the filter is here.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can you configure the base url for Spring Boot Actuator ...
I ran into the same issue with my application. Spring Boot uses the current request URL to generate the hypermedia links on the...
Read more >
Spring Boot Actuator Endpoints - DigitalOcean
Customizing Actuator End Points Base Path. By default base-path of actuator endpoints is /actuator , we can change it to any other value...
Read more >
Spring Boot Actuator Web API Documentation
This API documentation describes Spring Boot Actuators web endpoints. ... The /actuator base path can be configured by using the ...
Read more >
When using Spring MVC, unlike other endpoints, controller ...
When we create WebMvcEndpointHandlerMapping we use the path pattern parser ... MVC auto-configuration: spring-boot/spring-boot-project/spring-boot-actuator- ...
Read more >
Solved: Re: Unable to find region using springboot app
I'm trying to create a simple springboot application that contains hbase-site.xml ... Exposing 2 endpoint(s) beneath base path '/actuator'
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found