public static synchronized void resetAllMetrics() {
    long startTime = System.currentTimeMillis();
    // Gauge metrics don't need to be changed because they calculate value when getting them
    // Counters can be reset to zero values.
    for (Counter counter : METRIC_REGISTRY.getCounters().values()) {
      counter.dec(counter.getCount());
    }

    // No reset logic exist in Meter, a remove and add combination is needed
    for (String meterName : METRIC_REGISTRY.getMeters().keySet()) {
      METRIC_REGISTRY.remove(meterName);
      METRIC_REGISTRY.meter(meterName);
    }

    // No reset logic exist in Timer, a remove and add combination is needed
    for (String timerName : METRIC_REGISTRY.getTimers().keySet()) {
      METRIC_REGISTRY.remove(timerName);
      METRIC_REGISTRY.timer(timerName);
    }

    // Reset the InstrumentedExecutorServices last as it needs to keep the
    // reference to the new metrics objects
    EXECUTOR_SERVICES.values().forEach(InstrumentedExecutorService::reset);

    LAST_REPORTED_METRICS.clear();
    LOG.info("Reset all metrics in the metrics system in {}ms",
        System.currentTimeMillis() - startTime);
  }
@Test
  public void testResetAllMetrics() {
    String counterName = "Worker.Counter";
    MetricsSystem.counter(counterName).inc();
    assertEquals(1, MetricsSystem.counter(counterName).getCount());

    String meterName = "Worker.Meter";
    MetricsSystem.meter(meterName).mark(1000);
    assertEquals(1000, MetricsSystem.meter(meterName).getCount());

    String timerName = "Worker.Timer";
    MetricsSystem.timer(timerName).time().close();
    assertEquals(1, MetricsSystem.timer(timerName).getCount());

    MetricsSystem.resetAllMetrics();
    assertEquals(0, MetricsSystem.counter(counterName).getCount());
    assertEquals(0, MetricsSystem.meter(meterName).getCount());
    assertEquals(0, MetricsSystem.reportWorkerMetrics().size());
    assertEquals(0, MetricsSystem.timer(timerName).getCount());
  }