Bewang
Bewang

Reputation: 483

Spring-boot metrics count and gauge every requestURI for RESTful service

I'm using starter-jersey and starter-actuator. If I have an endpoint as below,

@Component
@Path("/greeting")
public class GreetingEndpoint {

  @GET
  @Path("{id}/{message}")
  @Produces(MediaType.APPLICATION_JSON)
  public Greeting sayHello(@PathParam("id") Long id, @PathParam("message") String message) {
    return new Greeting(id, message);
  }
}

I would have counters/gauges for every request URI. Will this cause memory blowup?

counter.status.200.greeting.1000.look: 1
counter.status.200.greeting.1001.watch-out: 1
counter.status.200.metrics: 1
gauge.response.greeting.1000.look: 109
gauge.response.greeting.1001.watch-out: 6
gauge.response.metrics: 32

Upvotes: 2

Views: 2312

Answers (1)

jst
jst

Reputation: 1747

To answer the question asked, yes it could blow up if you have essentially unlimited id/message combos. All that information is getting stored in memory. Which unless you control the client calling the endpoint is certainly the case. It might take a long time, but nothing is reaping the metrics repository so they will live indefinitely for the life of the app.

There may be a workaround for you (I can't explain why this works however). Use @RestController+@RequestMapping+@PathVariable. In my experience it will create 1 entry for counter.status.200.greeting.id,message. If you just want to get rid of the counters/gauges for HTTP request but keep all the other auto-configure features then you can include this

@EnableAutoConfiguration(exclude={MetricFilterAutoConfiguration.class})

Hope this helps.

Upvotes: 2

Related Questions