In the MetricRegistry deisng of 3.1.2, why not gauge has getOrAdd method, like other metrics,counter/timer/meter/histogram

Skip to first unread message

Aime Soleil Zhu

Mar 16, 2020, 2:25:33 AM3/16/20
to metrics-user
In the MetricRegistry deisng of 3.1.2, Notices that gauge has no getOrAdd method, like other metrics,counter/timer/meter/histogram. 

public <T> Gauge<T> newGauge(MetricName metricName,Gauge<T> metric){
return getOrAdd(metricName, metric);

Then it's been deleted.

May I know the thoughts why we remove getOrAdd for gauge?


Erik van Oosten

Mar 19, 2020, 3:52:06 AM3/19/20
Hi Julian,

Gauges in Dropwizard metrics refer to some executable code. That code might depend on some resources. If you were to call getOrAdd you are passing in second block of code. Call getOrAdd often enough and you have a resource leak.

If you are sure you want to replace a gauge, the only thing you can do is remove the existing gauge and add a new one.

BTW, there is almost no good reason ever to use the return value from newGauge (nor from getOrAdd).

Kind regards,

Op 16-03-2020 om 07:25 schreef Aime Soleil Zhu:
You received this message because you are subscribed to the Google Groups "metrics-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To view this discussion on the web visit

Aime Soleil Zhu

Apr 26, 2020, 11:50:09 PM4/26/20
thanks @Erik van Oosten for the clarification. Sorry for my late reply due to some network reasons. It dose help understand the behind design thoughts about Dropwizrd metrics. 

'Erik van Oosten' via metrics-user <> 于2020年3月19日周四 上午12:52写道:
Reply all
Reply to author
0 new messages