3

I am trying to implement Prometheus in my microservices based spring boot application, deployed over weblogic server. As part of POC,I have included the configs as part of one war. To enable it, i have set below config -

Application.properties

 management:
  endpoint:
   prometheus:
    enabled: true   
 endpoints:
  web:
    exposure:
     include: "*"

Gradle -

    implementation 'io.micrometer:micrometer-registry-prometheus'

But the actuator request is getting blocked by existing interceptors. It asks to pass values in headers specific to our project. Through postman(http:localhost:8080/abc/actuator/prometheus), I am able to test my POC(with required headers) and it returns time-series data expected by Prometheus. But Prometheus is not able to scrap data on its own(with pull approach), as the call lacks headers in request.

I tried following links (link1,link2) to bypass it, but my request still got intercepted by existing interceptor. Interceptors blocking the request are part of dependent jars.

Edited -- I have used following way to exclude all calls to interceptor -

 @Configuration
 public class MyConfig implements WebMvcConfigurer{

@Override
public void addInterceptors(InterceptorRegistry registry){
    registry.addInterceptor(new MyCustomInterceptor()).addPathPatterns("**/actuator/**");
}

}

MyCustomInterceptor

@Component
 public class MyCustomInterceptor implements HandlerInterceptor{

  }

I have not implemented anything custom in MyCustomInterceptor(as i only want to exclude all calls to 'actuator' endpoint from other interceptors).

Narendra Pandey
  • 514
  • 4
  • 11
  • 26

2 Answers2

0
@Configuration
public class ActuatorConfig extends WebMvcEndpointManagementContextConfiguration {

  public WebMvcEndpointHandlerMapping webEndpointServletHandlerMapping(WebAnnotationEndpointDiscoverer endpointDiscoverer,
                                                                       EndpointMediaTypes endpointMediaTypes,
                                                                       CorsEndpointProperties corsProperties,
                                                                       WebEndpointProperties webEndpointProperties) {
    WebMvcEndpointHandlerMapping mapping = super.webEndpointServletHandlerMapping(
      endpointDiscoverer,
      endpointMediaTypes,
      corsProperties,
      webEndpointProperties);

    mapping.setInterceptors(null);

    return mapping;
  }
}

Maybe you can override with setting null. I got code from https://github.com/spring-projects/spring-boot/issues/11234

Gurkan İlleez
  • 1,503
  • 1
  • 10
  • 12
0

AFAIK Spring HandlerInterceptor do not intercept actuator's endpoints by default. Spring Boot can't intercept actuator access

Oleg Kuts
  • 769
  • 1
  • 13
  • 26