metrics-cdi
metrics-cdi copied to clipboard
Generic Producers
Hi,
I wonder if it's possible to have generic/default producers? I understand that I can use explicit producers, but that creates a lot of duplicated code.
@Produces
@Metric
Timer Timer = new Timer(new MyFancyReservoir());
@Timed(name = "customTimerA")
void timedMethodA() {
// Timer name => TimedMethodBean.customTimerA
}
@Timed(name = "customTimerB")
void timedMethodB() {
// Timer name => TimedMethodBean.customTimerB
}
It's not possible for the time being. Metrics CDI conveniently uses the metrics registry to register custom metrics declared with @Produces without adding any other logic for the retrieval.
I agree with you and your use case makes sense. One way of doing thing would be to add support for name matching, e.g.:
@Produces
@Metric(name = "*")
Timer Timer = new Timer(new MyFancyReservoir());
Another way would be to provide a way to customise the reservoir for instance globally. I've already introduced the MetricsConfiguration class for that kind of need.
@mseitner sorry for the late reply. Would the MetricsConfiguration.reservoirFunction function introduced in version 1.5.0 that enables the configuration of reservoirs solve your issue?