Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

spring-boot v2 actuator selector

Based on this blog post, I have tried to implement an actuator endpoint like this:

@Component 
@Endpoint(id = "test/filter/configurator")
@RequiredArgsConstructor 
public class AdvisorFilterConfigurator {

private final AdvisorFilterConfig filterConfig;

@ReadOperation 
public Boolean rewrite(@Selector Boolean enable) { 
  filterConfig.setEnable(enable); 
  return filterConfig.isEnable(); 
 } 
}

When I am try to access http://localhost:9992/admin/test/filter/configurator/true, it says Missing parameters: enable, as it can be seen on this screenshot:

enter image description here

I can only access that endpoint this way: http://localhost:9992/admin/test/filter/configurator/{anystring}?enable=true.

Am I doing something wrong or this is issue with actuator?

like image 420
b1gs Avatar asked Oct 15 '25 14:10

b1gs


1 Answers

The "missing parameters" bits happen because you've not compiled the code with -parameters as described in the documentation.

If you didn't you should see something like this in the logs

2018-08-21 10:35:21.098 INFO 78181 --- [ main] s.b.a.e.w.s.WebMvcEndpointHandlerMapping : Mapped "{[/actuator/test/{arg0}],methods=[GET],produces=[application/vnd.spring-boot.actuator.v2+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.web.servlet.AbstractWebMvcEndpointHandlerMapping$OperationHandler.handle(javax.servlet.http.HttpServletRequest,java.util.Map)

Once you've made sure the code is compiled with -parameters you should see something like this instead:

2018-08-21 10:34:20.802 INFO 77977 --- [ main] s.b.a.e.w.s.WebMvcEndpointHandlerMapping : Mapped "{[/actuator/test/{enable}],methods=[GET],produces=[application/vnd.spring-boot.actuator.v2+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.web.servlet.AbstractWebMvcEndpointHandlerMapping$OperationHandler.handle(javax.servlet.http.HttpServletRequest,java.util.Map)

Notice that in the first case the selector is {arg0} (auto-generated parameter name when the information is not available) while in the second it is {enable}.

You can also run the app from the command line if you're using Maven and the spring boot parent (mvn clean spring-boot:run) as it takes care of enabling -parameters automatically.

I've also created #14159 to check how we can improve that error message.

like image 76
Stephane Nicoll Avatar answered Oct 18 '25 06:10

Stephane Nicoll



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!