Faced this need while deploying a simple Spring Boot application with actuator on a container AWS Elastic Container Service and exposing it through an Elastic Load Balancer: the container was failing the load balancer health checks and was continuously restarted.
I had configurred the health check as HTTP GET on /actuator/health
giving 200 OK. A look at the log revealed the health check getting instead HTTP 406.
I replicated this behaviour locally with Postman (which sends Accept:*/*
by default) and looked at the Actuator code where I found that application/json
is the only accepted media type.
Relaxing the media type requirement (but I don't know if this was a design choice), possibly only on the health check, could make the actuator health endpoint usable even in this scenario.
Of course defining a custom SpringMVC endpoint would be another solution for my use case.
Comment From: wilkinsona
Thanks for the report, @AlexFalappa, but I don't think I understand the problem. A request sent to /actuator/health
with Accept:*/*
works for me:
$ curl -v localhost:8080/actuator/health
* Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 8080 (#0)
> GET /actuator/health HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.54.0
> Accept: */*
>
< HTTP/1.1 200
< Content-Type: application/vnd.spring-boot.actuator.v3+json
< Transfer-Encoding: chunked
< Date: Thu, 09 Apr 2020 08:49:31 GMT
<
* Connection #0 to host localhost left intact
{"status":"UP","components":{"db":{"status":"UP","details":{"database":"H2","validationQuery":"isValid()"}},"diskSpace":{"status":"UP","details":{"total":1000240963584,"free":637280677888,"threshold":10485760,"exists":true}},"example":{"status":"UP","details":{"counter":42}},"hello":{"status":"UP","details":{"hello":"world"}},"ping":{"status":"UP"}},"groups":["live","ready"]}
What version of Spring Boot do I need to use and what steps do I need to follow to reproduce the 406 response?
Comment From: AlexFalappa
@wilkinsona I am using 2.2.6.RELEASE on Linux, the application has spring-boot-starter-actuator
, spring-boot-starter-thymeleaf
and spring-boot-starter-web
dependencies, the problem shows up using curl
as well:
Comment From: AlexFalappa
A freshly generated project on start.spring.io does not exhibit the wrong behaviour.
Investigating...
Comment From: AlexFalappa
Found the reason.
This is the main class:
@SpringBootApplication
public class EchoApplication implements WebMvcConfigurer {
public static void main(String[] args) {
SpringApplication.run(EchoApplication.class, args);
}
@Override
public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
configurer.defaultContentType(MediaType.TEXT_PLAIN);
}
}
Setting the default content type to MediaType.TEXT_PLAIN
interferes with selection of media type for actuator responses. I had to specify the deault content type to have the application prefer text over JSON when using curl from command line.
Can the actuator endpoints be shielded from such configurations by default? Can I have the default media type specified for application @Controller
beans only?
Given that my request is a bit borderline I think you can close the issue as not designed/supported.
Comment From: bclozel
This would be covered with #20290, which we're currently investigating right now. I'm closing this issue as a duplicate, then.
Thanks!