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 is the case for health checks (since dropwizard-metrics 4.1).

Example

With the following gauge in class Example:

class Example(db: Database) extends nl.grons.metrics4.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

See also FreshMetricRegistry and FreshHealthCheckRegistry in case your class only extends InstrumentedBuilder or CheckedBuilder respectively.

class Object
trait Matchable
class Any

Value members

Concrete fields

lazy override
val metricRegistry: MetricRegistry
lazy override
val registry: HealthCheckRegistry