Micrometer Counter vs DistributionSummary

Viewed 1421

Using summary for request size I would track

  • total requests
  • total total request size
  • biggest request size

I can do it like this

meterRegistry.summary("request.size", <tag for url>).record(<size>);

However I can achieve the same using counters and a gauge for the biggest size

meterRegistry.counter("request.size.total", <tag for url>).increment(<size>);
meterRegistry.counter("request.size.count", <tag for url>).increment();
meterRegistry.gauge("request.size.max", <tag for url>).set(<new value if needed>);
// and the gauge value will be stored in atomic variable

Question is, is there any benefit of summary over the longer solution except for being shorter?

2 Answers

Using DistributionSummary means:

  • writing and maintaining less code
  • using Micrometer's naming conventions
  • decay values over time (see: distributionStatisticExpiry and distributionStatisticBufferLength)
  • you can have histograms and percentiles
  • you can define SLOs

In addition to @Jonatan Ivanov's answer.

Using counter with tag = <request size> means a new metric will be created for every request size. Which means you might end up with huge amount of counters.

If you think that the distinguishing tag is something with less possible values and not too many counter metrics will be created, you can still use counter and make all of the aggregations the summary provides. (except quantiles).

I would use counter is I am interested in for example the number of requests with size 450, this is not possible with the summary.

TLDR:

Use summary if you are interested only in total count and average size

Use counter if the size variance isn't too big and you are interested in the exact count for a given size.

Related