I do have a spring boot project developed using Java 11 in which I am adding the spring boot actuator to use the metrics endpoint to analyze the API response time and codes. I have added the following in pom.xml and in the application.properties file. First I do hit the REST APIs that I have developed which return the required response and when I do check metrics using http://localhost:8080/metrics I cannot find http.server.requests in response.

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.6.6</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>


# Spring Boot Actuator Configurations
management.endpoints.web.base-path=
management.endpoint.health.show-details=ALWAYS
management.endpoints.web.path-mapping.health=/healthcheck
management.endpoint.metrics.enabled = true
management.endpoints.web.exposure.include = *

Comment From: wilkinsona

Can you please try with 2.6.13, the latest Spring Boot 2.6.x release? If the problem remains and you would like us to spend some more time investigating, please spend some time providing a complete yet minimal sample that reproduces the problem. You can share it with us by pushing it to a separate repository on GitHub or by zipping it up and attaching it to this issue.

Comment From: romil-patel-integrella

I have removed all other classes and services and just kept the rest controller with one API which returns sample message and now I can see the http.server.requests in response. So I have tried to further invistage issue with my original project and found that it is due to the filter that I am using for authentication purpose. I am not sure why this filter is breaking the metrics endpoint. We do have some public endpoints for which we don't need authentication and FilterConfiguration class contains endpoints for which authentication is required and If I do comment FilterConfiguration class I am getting the http.server.requests in response

@Configuration
public class FilterConfiguration {

  @Autowired
  private AuthenticationFilter authenticationFilter;

  @Autowired
  private FilterRegistrationBean registration;

  /**
   * Filter configuration bean to apply filter for given url patterns.
   */
  @Bean
  public FilterRegistrationBean filterConfigurationForAuthentication() {
    registration.setFilter(authenticationFilter);
    registration.addUrlPatterns("/workers/endpoint-1");
    registration.addUrlPatterns("/workers/endpoint-2");
    registration.addUrlPatterns("/workers/endpoint-3");
    return registration;
  }

}

Filter

@Component
@Slf4j
public class AuthenticationFilter extends OncePerRequestFilter {

  @Value("${azure.jwt-key-validation-url}")
  private String azureJwtValidationUrl;

  @Value("${header-name.authorization}")
  private String authorizationHeader;

  @Value("${header-name.api-key}")
  private String apiKeyHeader;

  @Value("${basic-auth-username}")
  private String basicAuthUsername;

  @Value("${basic-auth-password}")
  private String basicAuthPassword;

  @Value("${invalid.jwt.message}")
  private String invalidJWT;

  @Value("${missing.jwt.message}")
  private String missingJWT;

  @Value("${invalid.api-key.message}")
  private String invalidApiKey;

  @Value("${missing.api-key.message}")
  private String missingApiKey;

  @Value("${api.key}")
  private String applicationApiKey;

  @Value("${invalid.username.message}")
  private String invalidUsername;

  @Value("${invalid.password.message}")
  private String invalidPassword;

  private final AuthenticationService authenticationService;

  public AuthenticationFilter(AuthenticationService authenticationService) {
    this.authenticationService = authenticationService;
  }

  /**
   * Filter to process request and manage authentication for APIs. If valid JWT is provided request
   * will be processed If JWT is invalid request will be terminated with required message
   *
   * @param request incoming request
   * @param response response for incoming request
   * @param chain filter chain
   * @throws IOException if unable to process request
   * @throws ServletException if unable to process request
   */
  @SneakyThrows
  @Override
  public void doFilterInternal(
      HttpServletRequest request, HttpServletResponse response, FilterChain chain)
      throws IOException, ServletException {
    String authorizationHeaderValue = request.getHeader(authorizationHeader);

    String apiKeyFromRequest = request.getHeader(apiKeyHeader);
    log.debug("api-key: {}, authorization: {}", apiKeyFromRequest, authorizationHeaderValue);
    ...
    chain.doFilter(request, response);
  }

  /**
   * Method to send forbidden response message
   *
   * @param response response for current request
   * @param message message for client or API user
   * @throws IOException if unable to send response
   */
  private void sendErrorMessage(HttpServletResponse response, String message)
      throws IOException, JSONException {
    JSONObject responseValue = new JSONObject();
    responseValue.put("message", message);
    response.setContentType(MediaType.APPLICATION_JSON_VALUE);
    response.setStatus(HttpServletResponse.SC_FORBIDDEN);
    response.getWriter().write(responseValue.toString());
  }
}

Comment From: bclozel

I think this is a configuration issue.

Your config is auto wiring your filter instance and a filter registration bean instance. That filter registration bean could be the one that registers the filter for metrics instrumentation. This means this registration now registers your filter instead of the metrics one. More, since your filter is already declared as a bean as well, this might mean that the authentication filter is registered three times.

I think you will need to rewrite that configuration and make sure that you're instantiating the authentication filter and the registration within the bean method and only contributing your own registration as a bean. You'll find more information here: https://docs.spring.io/spring-boot/docs/current/reference/html/web.html#web.servlet.embedded-container.servlets-filters-listeners.beans

Thanks!