Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Actuator health endpoint could accept any media type #20880

Closed
AlexFalappa opened this issue Apr 8, 2020 · 5 comments
Closed

Actuator health endpoint could accept any media type #20880

AlexFalappa opened this issue Apr 8, 2020 · 5 comments
Labels
status: duplicate A duplicate of another issue

Comments

@AlexFalappa
Copy link
Contributor

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.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Apr 8, 2020
@mbhave mbhave changed the title Actuator heallth endpoint could accept any media type Actuator health endpoint could accept any media type Apr 8, 2020
@wilkinsona
Copy link
Member

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?

@wilkinsona wilkinsona added the status: waiting-for-feedback We need additional information before we can continue label Apr 9, 2020
@AlexFalappa
Copy link
Contributor Author

@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:
actuator-406

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Apr 9, 2020
@AlexFalappa
Copy link
Contributor Author

A freshly generated project on start.spring.io does not exhibit the wrong behaviour.

Investigating...

@mbhave mbhave added status: waiting-for-feedback We need additional information before we can continue and removed status: feedback-provided Feedback has been provided labels Apr 9, 2020
@AlexFalappa
Copy link
Contributor Author

AlexFalappa commented Apr 9, 2020

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.

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Apr 9, 2020
@bclozel
Copy link
Member

bclozel commented Apr 9, 2020

This would be covered with #20290, which we're currently investigating right now.
I'm closing this issue as a duplicate, then.

Thanks!

@bclozel bclozel closed this as completed Apr 9, 2020
@bclozel bclozel added status: duplicate A duplicate of another issue and removed status: feedback-provided Feedback has been provided status: waiting-for-triage An issue we've not yet triaged labels Apr 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: duplicate A duplicate of another issue
Projects
None yet
Development

No branches or pull requests

5 participants