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

已查看 17 次
跳至第一个未读帖子

Aime Soleil Zhu

未读,
2020年3月16日 02:25:332020/3/16
收件人 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

未读,
2020年3月19日 03:52:062020/3/19
收件人 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

未读,
2020年4月26日 23:50:092020/4/26
收件人 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写道:
回复全部
回复作者
转发
0 个新帖子