You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ha...@apache.org on 2022/02/23 07:59:10 UTC
[iotdb] branch master updated: [IOTDB-2594][Metric] fix implement of histogram of dropwizard to UniformReservoir(#5109)
This is an automated email from the ASF dual-hosted git repository.
haonan 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 d0389ce [IOTDB-2594][Metric] fix implement of histogram of dropwizard to UniformReservoir(#5109)
d0389ce is described below
commit d0389ce1d31f82f77e67bee8718dc1f09678004e
Author: ZhangHongYin <46...@users.noreply.github.com>
AuthorDate: Wed Feb 23 15:58:29 2022 +0800
[IOTDB-2594][Metric] fix implement of histogram of dropwizard to UniformReservoir(#5109)
---
.../dropwizard/DropwizardMetricManager.java | 22 +++++++++++++++++-----
.../dropwizard/DropwizardMetricManagerTest.java | 5 +++++
2 files changed, 22 insertions(+), 5 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 4a7fbff..adb3be4 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
@@ -54,8 +54,10 @@ public class DropwizardMetricManager implements MetricManager {
com.codahale.metrics.MetricRegistry metricRegistry;
MetricConfig metricConfig = MetricConfigDescriptor.getInstance().getMetricConfig();
- MetricRegistry.MetricSupplier<com.codahale.metrics.Timer> metricSupplier =
+ MetricRegistry.MetricSupplier<com.codahale.metrics.Timer> timerMetricSupplier =
() -> new com.codahale.metrics.Timer(new UniformReservoir());
+ MetricRegistry.MetricSupplier<com.codahale.metrics.Histogram> histogramMetricSupplier =
+ () -> new com.codahale.metrics.Histogram(new UniformReservoir());
/** init the field with dropwizard library. */
public DropwizardMetricManager() {
@@ -144,7 +146,10 @@ public class DropwizardMetricManager implements MetricManager {
MetricName name = new MetricName(metric, tags);
IMetric m =
currentMeters.computeIfAbsent(
- name, key -> new DropwizardHistogram(metricRegistry.histogram(name.toFlatString())));
+ name,
+ key ->
+ new DropwizardHistogram(
+ metricRegistry.histogram(name.toFlatString(), histogramMetricSupplier)));
if (m instanceof Histogram) {
return (Histogram) m;
}
@@ -160,7 +165,9 @@ public class DropwizardMetricManager implements MetricManager {
IMetric m =
currentMeters.computeIfAbsent(
name,
- key -> new DropwizardTimer(metricRegistry.timer(name.toFlatString(), metricSupplier)));
+ key ->
+ new DropwizardTimer(
+ metricRegistry.timer(name.toFlatString(), timerMetricSupplier)));
if (m instanceof Timer) {
return (Timer) m;
}
@@ -229,7 +236,10 @@ public class DropwizardMetricManager implements MetricManager {
MetricName name = new MetricName(metric, tags);
IMetric m =
currentMeters.computeIfAbsent(
- name, key -> new DropwizardHistogram(metricRegistry.histogram(name.toFlatString())));
+ name,
+ key ->
+ new DropwizardHistogram(
+ metricRegistry.histogram(name.toFlatString(), histogramMetricSupplier)));
if (m instanceof Histogram) {
((Histogram) m).update(value);
return;
@@ -246,7 +256,9 @@ public class DropwizardMetricManager implements MetricManager {
IMetric m =
currentMeters.computeIfAbsent(
name,
- key -> new DropwizardTimer(metricRegistry.timer(name.toFlatString(), metricSupplier)));
+ key ->
+ new DropwizardTimer(
+ metricRegistry.timer(name.toFlatString(), timerMetricSupplier)));
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 6583e2d..fcca7b1 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
@@ -158,6 +158,11 @@ public class DropwizardMetricManagerTest {
metricManager.histogram(10, "history_count", "tag1", "tag2");
metricManager.histogram(20L, "history_count", "tag1", "tag2");
metricManager.histogram(30, "history_count", "tag1", "tag2");
+ try {
+ Thread.sleep(1000);
+ } catch (Exception e) {
+ // do nothing
+ }
metricManager.histogram(40L, "history_count", "tag1", "tag2");
metricManager.histogram(50, "history_count", "tag1", "tag2");
assertEquals(5, histogram.count());