groupon/spark-metrics

Can't use SlidingTimeWindowReservoir in histogram metric

Opened this issue · 0 comments

It is not possible to use SlidingTimeWindowReservoir in histogram metrics. Only the default ReservoirClass ExponentiallyDecaying works.

The issue is in class MetricsReceiver.scala, getOrCreateHistogram() uses reservoirClass.newInstance() (line 125). But SlidingTimeWindowReservoir class doesn't have the default constructor and has only constructors with arguments, hence the call newInstance() fails with java.lang.InstantiationException with error: java.lang.NoSuchMethodException: com.codahale.metrics.SlidingTimeWindowReservoir.()

The solution is getting the arguments from the user through the UserMetricsSystem.histogram(...) method (I want to be able to set these values my self) and instead of calling newInstance without arguments, it should use getDeclaredConstructors and newInstance with the arguments.