When I access the /health
endpoint from my Spring Boot application (1.2.4.RELEASE) it is returning a status of DOWN
:
{
status: \"DO
I built a filter to log the health response when it fails.
package br.gov.go.sspj.k9.util;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.endpoint.mvc.HealthMvcEndpoint;
import org.springframework.stereotype.Component;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@Component
public class BadHealthCheckLogFilter implements Filter {
private @Autowired HealthMvcEndpoint hme;
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
chain.doFilter(request, response);
HttpServletRequest req = (HttpServletRequest) request;
HttpServletResponse res = (HttpServletResponse) response;
if (req.getRequestURI().endsWith("/health") && res.getStatus() != 200)
log.error(hme.invoke(req, null).toString());
}
@Override
public void init(FilterConfig filterConfig) {
}
@Override
public void destroy() {
}
}