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

17 views
Skip to first unread message

Aime Soleil Zhu

unread,
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?

Thanks,
Julian

Erik van Oosten

unread,
Mar 19, 2020, 3:52:06 AM3/19/20
to metric...@googlegroups.com
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,
    Erik.



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 metrics-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/metrics-user/f6643a9c-e8f4-46cc-bf3e-d562b5e52cb4%40googlegroups.com.

Aime Soleil Zhu

unread,
Apr 26, 2020, 11:50:09 PM4/26/20
to metric...@googlegroups.com
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 <metric...@googlegroups.com> 于2020年3月19日周四 上午12:52写道:
Reply all
Reply to author
Forward
0 new messages