Repository: dropwizard/metrics (java)

Issue:
`NoopMetricRegistry.NoopTimer::time(Runnable)` should actually run the supplied Runnable
The implementation of `NoopMetricRegistry.NoopTimer`'s `time` method which takes a `Callable<T>` is as follows:
```
        @Override
        public <T> T time(Callable<T> event) throws Exception {
            return event.call();
        }
```

However the implementation of the method overload which takes a `Runnable` is:
```
        @Override
        public void time(Runnable event) {
            // NOP
        }
```
This [latter implementation](https://github.com/dropwizard/metrics/blob/release/4.2.x/metrics-core/src/main/java/com/codahale/metrics/NoopMetricRegistry.java#L433C1-L436C10) is incorrect as the `Runnable` represents important business logic. That is, switching implementations (e.g. during testing) to a `NoopMetricRegistry` actually effects the behaviour of the system!

The method body should be as follows:
```
        @Override
        public void time(Runnable event) {
            event.run();
        }
```

Pull request description:
fix: NoopTimer#time(Runnable) should run the Runnable
Fixes #4536

Patch:
diff --git a/metrics-core/src/main/java/com/codahale/metrics/NoopMetricRegistry.java b/metrics-core/src/main/java/com/codahale/metrics/NoopMetricRegistry.java
index db6519307..5af6e94d8 100644
--- a/metrics-core/src/main/java/com/codahale/metrics/NoopMetricRegistry.java
+++ b/metrics-core/src/main/java/com/codahale/metrics/NoopMetricRegistry.java
@@ -432,7 +432,7 @@ public final class NoopMetricRegistry extends MetricRegistry {
          */
         @Override
         public void time(Runnable event) {
-            // NOP
+            event.run();
         }
 
         /**


Test patch:
diff --git a/metrics-core/src/test/java/com/codahale/metrics/NoopMetricRegistryTest.java b/metrics-core/src/test/java/com/codahale/metrics/NoopMetricRegistryTest.java
index 700c2a0fc..aa1c24466 100644
--- a/metrics-core/src/test/java/com/codahale/metrics/NoopMetricRegistryTest.java
+++ b/metrics-core/src/test/java/com/codahale/metrics/NoopMetricRegistryTest.java
@@ -6,6 +6,7 @@ import org.junit.Test;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Set;
+import java.util.concurrent.atomic.AtomicBoolean;
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.assertThatNullPointerException;
@@ -492,4 +493,13 @@ public class NoopMetricRegistryTest {
                 .isThrownBy(() -> registry.register("any_name", null))
                 .withMessage("metric == null");
     }
+
+    @Test
+    public void timesRunnableInstances() {
+        final Timer timer = registry.timer("thing");
+        final AtomicBoolean called = new AtomicBoolean();
+        timer.time(() -> called.set(true));
+
+        assertThat(called).isTrue();
+    }
 }