A mixin trait to get a fresh empty metric and health check registry every time.
Often a singleton service class defines a gauge with a static name. However, during testing multiple instances
are needed. Unfortunately the metrics registry doesn't allow registering a gauge under the same name twice.
This is not a problem when a new registry is used for each instance.
The same should be the case for health checks. 'Should' because currently health check registries ignore duplicate
registrations even though maybe it should not. This may change when
https://github.com/dropwizard/metrics/issues/1245 is accepted.
*Example*
With the following gauge in class Example:
class Example(db: Database) extends nl.grons.metrics.scala.DefaultInstrumented {
// Define a gauge with a static name
metrics.gauge("aGauge") { db.rowCount() }
}
This trait can be mixed in with any instance of Example:
val example = new Example(db) with FreshRegistries
A mixin trait to get a fresh empty metric and health check registry every time.
Often a singleton service class defines a gauge with a static name. However, during testing multiple instances are needed. Unfortunately the metrics registry doesn't allow registering a gauge under the same name twice. This is not a problem when a new registry is used for each instance.
The same should be the case for health checks. 'Should' because currently health check registries ignore duplicate registrations even though maybe it should not. This may change when https://github.com/dropwizard/metrics/issues/1245 is accepted.
*Example*
With the following gauge in class
Example:This trait can be mixed in with any instance of
Example:See also FreshMetricRegistry and FreshHealthCheckRegistry in case your class only extends InstrumentedBuilder or CheckedBuilder respectively.