You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ro...@apache.org on 2022/01/21 11:32:20 UTC

[iotdb] branch master updated: [IOTDB-2465][imple] fix implement of snapshot of dropwizard to UniformReservoir

This is an automated email from the ASF dual-hosted git repository.

rong pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iotdb.git


The following commit(s) were added to refs/heads/master by this push:
     new 633db3a  [IOTDB-2465][imple] fix implement of snapshot of dropwizard to UniformReservoir
633db3a is described below

commit 633db3a77a42cb78c60e59568b29a4c34a2ab130
Author: ZhangHongYin <46...@users.noreply.github.com>
AuthorDate: Fri Jan 21 19:31:42 2022 +0800

    [IOTDB-2465][imple] fix implement of snapshot of dropwizard to UniformReservoir
---
 .../apache/iotdb/metrics/dropwizard/DropwizardMetricManager.java | 9 +++++++--
 .../iotdb/metrics/dropwizard/DropwizardMetricManagerTest.java    | 5 +++++
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/metrics/dropwizard-metrics/src/main/java/org/apache/iotdb/metrics/dropwizard/DropwizardMetricManager.java b/metrics/dropwizard-metrics/src/main/java/org/apache/iotdb/metrics/dropwizard/DropwizardMetricManager.java
index 034880a..4a7fbff 100644
--- a/metrics/dropwizard-metrics/src/main/java/org/apache/iotdb/metrics/dropwizard/DropwizardMetricManager.java
+++ b/metrics/dropwizard-metrics/src/main/java/org/apache/iotdb/metrics/dropwizard/DropwizardMetricManager.java
@@ -30,6 +30,7 @@ import org.apache.iotdb.metrics.utils.PredefinedMetric;
 
 import com.codahale.metrics.MetricFilter;
 import com.codahale.metrics.MetricRegistry;
+import com.codahale.metrics.UniformReservoir;
 import com.codahale.metrics.jvm.*;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -53,6 +54,8 @@ public class DropwizardMetricManager implements MetricManager {
 
   com.codahale.metrics.MetricRegistry metricRegistry;
   MetricConfig metricConfig = MetricConfigDescriptor.getInstance().getMetricConfig();
+  MetricRegistry.MetricSupplier<com.codahale.metrics.Timer> metricSupplier =
+      () -> new com.codahale.metrics.Timer(new UniformReservoir());
 
   /** init the field with dropwizard library. */
   public DropwizardMetricManager() {
@@ -156,7 +159,8 @@ public class DropwizardMetricManager implements MetricManager {
     MetricName name = new MetricName(metric, tags);
     IMetric m =
         currentMeters.computeIfAbsent(
-            name, key -> new DropwizardTimer(metricRegistry.timer(name.toFlatString())));
+            name,
+            key -> new DropwizardTimer(metricRegistry.timer(name.toFlatString(), metricSupplier)));
     if (m instanceof Timer) {
       return (Timer) m;
     }
@@ -241,7 +245,8 @@ public class DropwizardMetricManager implements MetricManager {
     MetricName name = new MetricName(metric, tags);
     IMetric m =
         currentMeters.computeIfAbsent(
-            name, key -> new DropwizardTimer(metricRegistry.timer(name.toFlatString())));
+            name,
+            key -> new DropwizardTimer(metricRegistry.timer(name.toFlatString(), metricSupplier)));
 
     if (m instanceof Timer) {
       ((Timer) m).update(delta, timeUnit);
diff --git a/metrics/dropwizard-metrics/src/test/java/org/apache/iotdb/metrics/dropwizard/DropwizardMetricManagerTest.java b/metrics/dropwizard-metrics/src/test/java/org/apache/iotdb/metrics/dropwizard/DropwizardMetricManagerTest.java
index 6e07cf5..6583e2d 100644
--- a/metrics/dropwizard-metrics/src/test/java/org/apache/iotdb/metrics/dropwizard/DropwizardMetricManagerTest.java
+++ b/metrics/dropwizard-metrics/src/test/java/org/apache/iotdb/metrics/dropwizard/DropwizardMetricManagerTest.java
@@ -174,6 +174,11 @@ public class DropwizardMetricManagerTest {
     metricManager.timer(2L, TimeUnit.MINUTES, "timer_mark", "tag1", "tag2");
     metricManager.timer(4L, TimeUnit.MINUTES, "timer_" + "mark", "tag1", "tag2");
     metricManager.timer(6L, TimeUnit.MINUTES, "timer_mark", "tag1", "tag2");
+    try {
+      Thread.sleep(1000);
+    } catch (Exception e) {
+      // do nothing
+    }
     metricManager.timer(8L, TimeUnit.MINUTES, "timer_mark", "tag1", "tag2");
     metricManager.timer(10L, TimeUnit.MINUTES, "timer_mark", "tag1", "tag2");
     assertEquals(5, timer.getImmutableRate().getCount());