Search code examples
javaspring-bootjerseymetricsspring-boot-actuator

Exclude path params from actuator metrics


I have a Spring boot application that uses the actuator metrics and I have the following issue:

I have an endpoint like this :

GET /users/{userId}  

So every time I call this endpoint I use a different Id to get the specific user as you can think we can have hundreds of thousands. It is working correct, but i noticed that when calling my metrics endpoint :

GET /metrics

I get something like this:

counter.status.200.metrics: 1,
counter.status.200.api.users.4: 2,
counter.status.200.api.users.2: 3,
counter.status.200.api.users.3: 2,

So it makes me think that i will get a counter for every single call with different path params, so my question is how can i have a counter just for the endpoint /users/{anyId} and not for every single combination excluding the parameters?.

--- EDIT ---

I'm using Spring boot + Jersey (I'm not using Spring MVC), the following is my controller code:

@Component
@Path("/users")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public class UserResource {

    @GET
    public Response getUsers() {
        return Response.ok("It works !").build();
    }

    @GET
    @Path("/{userId}")
    public Response getUserById(@PathParam("userId") String id) {
        return Response.ok("It works !").build();
    }

}

And the following is the Jersey configuration:

@Component
@ApplicationPath("/api")
public class JerseyConfig extends ResourceConfig {
    public JerseyConfig() {
        register(UserResource.class);
        register(PingResource.class);
    }
}

Solution

  • It's a known issue with Spring Boot 1.x when using Jersey. There's a workaround described in the issue, alternatively you can disable the metrics filter by adding the following to application.properties:

    endpoints.metrics.filter.enabled=false