metrics-facade icon indicating copy to clipboard operation
metrics-facade copied to clipboard

Add possibility to reset metric value

Open rc-mairovichaa opened this issue 1 year ago • 0 comments

To reduce time required for test runs application context is reused sometimes in different tests. It is highly relevant for integration tests. By "application context" here could be considered Spring-context.

It's suggested to introduce "reset" method to metrics to be able to start from scratch in a particular test case if it's needed. Also it makes sense to add such method on MetricRegistry level (moreover, maybe it's enough - no need to add for each Metric type).

For example

MetricRegistry registry = new DefaultMetricRegistry();
Counter counter = registry.counter(withName("counter"));

counter.inc();
counter.inc();
counter.forEach(instance -> {
    Long v = (Long)instance.valueOf(COUNT);
    
    // Current value: 2
    System.out.println("Current value: " + v);
});
counter.reset();
// or
registry.resetMetrics();

// Current value: 0
System.out.println("Current value: " + v);

rc-mairovichaa avatar Sep 23 '24 17:09 rc-mairovichaa