Project provides the ability to use micrometer metrics in your dropwizard project that uses Dagger for dependency injection.
Also provides a test package (metrics-test) so your tests can extend BaseMetricsTest and have access to metrics during your development. Makes it easier to use metrics in general by making testing easier.
Include the following in your pom/gradle
dependencies {
implementation 'com.codeheadsystems:metrics:1.0.3'
testImplementation 'com.codeheadsystems:metrics-test:1.0.3'
}
The following is a basic example case. More complex examples are possible.
public class AClass {
private final Metrics metrics;
public AClass(final Metrics metrics){
this.metrics = metrics;
}
public boolean doSomething() {
return metrics.time("MetricName", () -> {
return System.currentTimeMillis() > 1000;
});
}
}
public class AClassTest extends BaseMetricTest {
@Test
public void testDoSomething_works(){
final ACLass testInstance = new AClass(metrics); // metrics from parent class
assert testInstance.doSomething == true; // The supplier is called from the metrics object
}
}