You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ta...@apache.org on 2023/05/31 17:01:38 UTC
[iotdb] branch master updated: [IOTDB-5926] Remove Useless Rater in Timer (#9959)
This is an automated email from the ASF dual-hosted git repository.
tanxinyu 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 7c384409954 [IOTDB-5926] Remove Useless Rater in Timer (#9959)
7c384409954 is described below
commit 7c3844099547b063c0788656aeb5dcc91f146ad5
Author: ZhangHongYin <46...@users.noreply.github.com>
AuthorDate: Thu Jun 1 01:01:33 2023 +0800
[IOTDB-5926] Remove Useless Rater in Timer (#9959)
---
docs/UserGuide/Monitor-Alert/Metric-Tool.md | 14 +++++------
docs/zh/UserGuide/Monitor-Alert/Metric-Tool.md | 14 +++++------
.../type/DropwizardHistogramSnapshot.java | 14 ++---------
.../metrics/dropwizard/type/DropwizardTimer.java | 5 ++--
.../metrics/impl/DoNothingHistogramSnapshot.java | 14 ++---------
.../apache/iotdb/metrics/impl/DoNothingTimer.java | 5 ++--
.../reporter/prometheus/PrometheusReporter.java | 10 ++------
.../iotdb/metrics/type/HistogramSnapshot.java | 15 +++---------
.../java/org/apache/iotdb/metrics/type/Timer.java | 5 ++--
.../micrometer/MicrometerMetricManager.java | 4 ++--
.../micrometer/type/MicrometerHistogram.java | 2 +-
.../type/MicrometerHistogramSnapshot.java | 27 +++++----------------
.../metrics/micrometer/type/MicrometerTimer.java | 11 +++------
.../type/MicrometerTimerHistogramSnapshot.java | 28 ++++++----------------
.../apache/iotdb/db/metric/MetricServiceTest.java | 6 ++---
15 files changed, 50 insertions(+), 124 deletions(-)
diff --git a/docs/UserGuide/Monitor-Alert/Metric-Tool.md b/docs/UserGuide/Monitor-Alert/Metric-Tool.md
index 286519da493..a4bb701d481 100644
--- a/docs/UserGuide/Monitor-Alert/Metric-Tool.md
+++ b/docs/UserGuide/Monitor-Alert/Metric-Tool.md
@@ -567,13 +567,13 @@ the sidebar `org.apache.iotdb.db.service` to view the cache hit ratio:
> For metrics whose Metric Name is name and Tags are K1=V1, ..., Kn=Vn, the mapping is as follows, where value is a
> specific value
-| Metric Type | Mapping [...]
-| ---------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- [...]
-| Counter | name_total{cluster="clusterName", nodeType="nodeType", nodeId="nodeId", k1="V1", ..., Kn="Vn"} value [...]
-| AutoGauge、Gauge | name{cluster="clusterName", nodeType="nodeType", nodeId="nodeId", k1="V1", ..., Kn="Vn"} value [...]
-| Histogram | name_max{cluster="clusterName", nodeType="nodeType", nodeId="nodeId", k1="V1", ..., Kn="Vn"} value <br> name_sum{cluster="clusterName", nodeType="nodeType", nodeId="nodeId", k1="V1", ..., Kn="Vn"} value <br> name_count{cluster="clusterName", nodeType="nodeType", nodeId="nodeId", k1="V1", ..., Kn="Vn"} value <br> name{cluster="clusterName", nodeType="nodeType", nodeId="nodeId", k1="V1", ..., Kn="Vn", quantile="0.0"} value <br> name{cluster="clusterName", nodeType="nod [...]
-| Rate | name_total{cluster="clusterName", nodeType="nodeType", nodeId="nodeId", k1="V1", ..., Kn="Vn"} value <br> name_total{cluster="clusterName", nodeType="nodeType", nodeId="nodeId", k1="V1", ..., Kn="Vn", rate="m1"} value <br> name_total{cluster="clusterName", nodeType="nodeType", nodeId="nodeId", k1="V1", ..., Kn="Vn", rate="m5"} value <br> name_total{cluster="clusterName", nodeType="nodeType", nodeId="nodeId", k1="V1", ..., Kn="Vn", rate="m15"} value <br> name_total{c [...]
-| Timer | name_seconds_max{cluster="clusterName", nodeType="nodeType", nodeId="nodeId", k1="V1", ..., Kn="Vn"} value <br> name_seconds_sum{cluster="clusterName", nodeType="nodeType", nodeId="nodeId", k1="V1", ..., Kn="Vn"} value <br> name_seconds_count{cluster="clusterName", nodeType="nodeType", nodeId="nodeId", k1="V1", ..., Kn="Vn"} value <br> name_seconds{cluster="clusterName", nodeType="nodeType", nodeId="nodeId", k1="V1", ..., Kn="Vn", quantile="0.0"} value <br> name_seco [...]
+| Metric Type | Mapping [...]
+| ---------------- |---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- [...]
+| Counter | name_total{cluster="clusterName", nodeType="nodeType", nodeId="nodeId", k1="V1", ..., Kn="Vn"} value [...]
+| AutoGauge、Gauge | name{cluster="clusterName", nodeType="nodeType", nodeId="nodeId", k1="V1", ..., Kn="Vn"} value [...]
+| Histogram | name_max{cluster="clusterName", nodeType="nodeType", nodeId="nodeId", k1="V1", ..., Kn="Vn"} value <br> name_sum{cluster="clusterName", nodeType="nodeType", nodeId="nodeId", k1="V1", ..., Kn="Vn"} value <br> name_count{cluster="clusterName", nodeType="nodeType", nodeId="nodeId", k1="V1", ..., Kn="Vn"} value <br> name{cluster="clusterName", nodeType="nodeType", nodeId="nodeId", k1="V1", ..., Kn="Vn", quantile="0.5"} value <br> name{cluster="clusterName", nodeType="nod [...]
+| Rate | name_total{cluster="clusterName", nodeType="nodeType", nodeId="nodeId", k1="V1", ..., Kn="Vn"} value <br> name_total{cluster="clusterName", nodeType="nodeType", nodeId="nodeId", k1="V1", ..., Kn="Vn", rate="m1"} value <br> name_total{cluster="clusterName", nodeType="nodeType", nodeId="nodeId", k1="V1", ..., Kn="Vn", rate="m5"} value <br> name_total{cluster="clusterName", nodeType="nodeType", nodeId="nodeId", k1="V1", ..., Kn="Vn", rate="m15"} value <br> name_total{c [...]
+| Timer | name_seconds_max{cluster="clusterName", nodeType="nodeType", nodeId="nodeId", k1="V1", ..., Kn="Vn"} value <br> name_seconds_sum{cluster="clusterName", nodeType="nodeType", nodeId="nodeId", k1="V1", ..., Kn="Vn"} value <br> name_seconds_count{cluster="clusterName", nodeType="nodeType", nodeId="nodeId", k1="V1", ..., Kn="Vn"} value <br> name_seconds{cluster="clusterName", nodeType="nodeType", nodeId="nodeId", k1="V1", ..., Kn="Vn", quantile="0.5"} value <br> name_seco [...]
#### 5.2.2. Config File
diff --git a/docs/zh/UserGuide/Monitor-Alert/Metric-Tool.md b/docs/zh/UserGuide/Monitor-Alert/Metric-Tool.md
index 17c076d7da0..8bf9542fa62 100644
--- a/docs/zh/UserGuide/Monitor-Alert/Metric-Tool.md
+++ b/docs/zh/UserGuide/Monitor-Alert/Metric-Tool.md
@@ -540,13 +540,13 @@ Core 级别的监控指标在系统运行中默认开启,每一个 Core 级别
> 对于 Metric Name 为 name, Tags 为 K1=V1, ..., Kn=Vn 的监控指标有如下映射,其中 value 为具体值
-| 监控指标类型 | 映射关系 [...]
-| ---------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- [...]
-| Counter | name_total{cluster="clusterName", nodeType="nodeType", nodeId="nodeId",k1="V1" , ..., Kn="Vn"} value [...]
-| AutoGauge、Gauge | name{cluster="clusterName", nodeType="nodeType", nodeId="nodeId",k1="V1" , ..., Kn="Vn"} value [...]
-| Histogram | name_max{cluster="clusterName", nodeType="nodeType", nodeId="nodeId",k1="V1" , ..., Kn="Vn"} value <br> name_sum{cluster="clusterName", nodeType="nodeType", nodeId="nodeId",k1="V1" , ..., Kn="Vn"} value <br> name_count{cluster="clusterName", nodeType="nodeType", nodeId="nodeId",k1="V1" , ..., Kn="Vn"} value <br> name{cluster="clusterName", nodeType="nodeType", nodeId="nodeId",k1="V1" , ..., Kn="Vn", quantile="0.0"} value <br> name{cluster="clusterName", nodeType="nod [...]
-| Rate | name_total{cluster="clusterName", nodeType="nodeType", nodeId="nodeId",k1="V1" , ..., Kn="Vn"} value <br> name_total{cluster="clusterName", nodeType="nodeType", nodeId="nodeId",k1="V1" , ..., Kn="Vn", rate="m1"} value <br> name_total{cluster="clusterName", nodeType="nodeType", nodeId="nodeId",k1="V1" , ..., Kn="Vn", rate="m5"} value <br> name_total{cluster="clusterName", nodeType="nodeType", nodeId="nodeId",k1="V1" , ..., Kn="Vn", rate="m15"} value <br> name_total{c [...]
-| Timer | name_seconds_max{cluster="clusterName", nodeType="nodeType", nodeId="nodeId",k1="V1" , ..., Kn="Vn"} value <br> name_seconds_sum{cluster="clusterName", nodeType="nodeType", nodeId="nodeId",k1="V1" , ..., Kn="Vn"} value <br> name_seconds_count{cluster="clusterName", nodeType="nodeType", nodeId="nodeId",k1="V1" , ..., Kn="Vn"} value <br> name_seconds{cluster="clusterName", nodeType="nodeType", nodeId="nodeId",k1="V1" , ..., Kn="Vn", quantile="0.0"} value <br> name_seco [...]
+| 监控指标类型 | 映射关系 [...]
+| ---------------- |---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- [...]
+| Counter | name_total{cluster="clusterName", nodeType="nodeType", nodeId="nodeId",k1="V1" , ..., Kn="Vn"} value [...]
+| AutoGauge、Gauge | name{cluster="clusterName", nodeType="nodeType", nodeId="nodeId",k1="V1" , ..., Kn="Vn"} value [...]
+| Histogram | name_max{cluster="clusterName", nodeType="nodeType", nodeId="nodeId",k1="V1" , ..., Kn="Vn"} value <br> name_sum{cluster="clusterName", nodeType="nodeType", nodeId="nodeId",k1="V1" , ..., Kn="Vn"} value <br> name_count{cluster="clusterName", nodeType="nodeType", nodeId="nodeId",k1="V1" , ..., Kn="Vn"} value <br> name{cluster="clusterName", nodeType="nodeType", nodeId="nodeId",k1="V1" , ..., Kn="Vn", quantile="0.5"} value <br> name{cluster="clusterName", nodeType="nod [...]
+| Rate | name_total{cluster="clusterName", nodeType="nodeType", nodeId="nodeId",k1="V1" , ..., Kn="Vn"} value <br> name_total{cluster="clusterName", nodeType="nodeType", nodeId="nodeId",k1="V1" , ..., Kn="Vn", rate="m1"} value <br> name_total{cluster="clusterName", nodeType="nodeType", nodeId="nodeId",k1="V1" , ..., Kn="Vn", rate="m5"} value <br> name_total{cluster="clusterName", nodeType="nodeType", nodeId="nodeId",k1="V1" , ..., Kn="Vn", rate="m15"} value <br> name_total{cl [...]
+| Timer | name_seconds_max{cluster="clusterName", nodeType="nodeType", nodeId="nodeId",k1="V1" , ..., Kn="Vn"} value <br> name_seconds_sum{cluster="clusterName", nodeType="nodeType", nodeId="nodeId",k1="V1" , ..., Kn="Vn"} value <br> name_seconds_count{cluster="clusterName", nodeType="nodeType", nodeId="nodeId",k1="V1" , ..., Kn="Vn"} value <br> name_seconds{cluster="clusterName", nodeType="nodeType", nodeId="nodeId",k1="V1" , ..., Kn="Vn", quantile="0.5"} value value <br> nam [...]
#### 5.2.2. 修改配置文件
diff --git a/metrics/dropwizard-metrics/src/main/java/org/apache/iotdb/metrics/dropwizard/type/DropwizardHistogramSnapshot.java b/metrics/dropwizard-metrics/src/main/java/org/apache/iotdb/metrics/dropwizard/type/DropwizardHistogramSnapshot.java
index 7d430099ebf..732c3321b85 100644
--- a/metrics/dropwizard-metrics/src/main/java/org/apache/iotdb/metrics/dropwizard/type/DropwizardHistogramSnapshot.java
+++ b/metrics/dropwizard-metrics/src/main/java/org/apache/iotdb/metrics/dropwizard/type/DropwizardHistogramSnapshot.java
@@ -37,8 +37,8 @@ public class DropwizardHistogramSnapshot implements HistogramSnapshot {
}
@Override
- public double[] getValues() {
- return Arrays.stream(snapshot.getValues()).mapToDouble(k -> k).toArray();
+ public double getSum() {
+ return Arrays.stream(snapshot.getValues()).sum();
}
@Override
@@ -46,11 +46,6 @@ public class DropwizardHistogramSnapshot implements HistogramSnapshot {
return snapshot.size();
}
- @Override
- public double getMedian() {
- return snapshot.getMedian();
- }
-
@Override
public double getMax() {
return (double) snapshot.getMax();
@@ -60,9 +55,4 @@ public class DropwizardHistogramSnapshot implements HistogramSnapshot {
public double getMean() {
return snapshot.getMean();
}
-
- @Override
- public double getMin() {
- return (double) snapshot.getMin();
- }
}
diff --git a/metrics/dropwizard-metrics/src/main/java/org/apache/iotdb/metrics/dropwizard/type/DropwizardTimer.java b/metrics/dropwizard-metrics/src/main/java/org/apache/iotdb/metrics/dropwizard/type/DropwizardTimer.java
index 24a084937b7..24630438616 100644
--- a/metrics/dropwizard-metrics/src/main/java/org/apache/iotdb/metrics/dropwizard/type/DropwizardTimer.java
+++ b/metrics/dropwizard-metrics/src/main/java/org/apache/iotdb/metrics/dropwizard/type/DropwizardTimer.java
@@ -20,7 +20,6 @@
package org.apache.iotdb.metrics.dropwizard.type;
import org.apache.iotdb.metrics.type.HistogramSnapshot;
-import org.apache.iotdb.metrics.type.Rate;
import org.apache.iotdb.metrics.type.Timer;
import java.util.concurrent.TimeUnit;
@@ -43,7 +42,7 @@ public class DropwizardTimer implements Timer {
}
@Override
- public Rate getImmutableRate() {
- return new DropwizardRate(timer);
+ public long getCount() {
+ return timer.getCount();
}
}
diff --git a/metrics/interface/src/main/java/org/apache/iotdb/metrics/impl/DoNothingHistogramSnapshot.java b/metrics/interface/src/main/java/org/apache/iotdb/metrics/impl/DoNothingHistogramSnapshot.java
index c87af4ef563..a3a22435b02 100644
--- a/metrics/interface/src/main/java/org/apache/iotdb/metrics/impl/DoNothingHistogramSnapshot.java
+++ b/metrics/interface/src/main/java/org/apache/iotdb/metrics/impl/DoNothingHistogramSnapshot.java
@@ -28,17 +28,12 @@ public class DoNothingHistogramSnapshot implements HistogramSnapshot, DoNothingM
}
@Override
- public double[] getValues() {
- return new double[0];
- }
-
- @Override
- public int size() {
+ public double getSum() {
return 0;
}
@Override
- public double getMedian() {
+ public int size() {
return 0;
}
@@ -51,9 +46,4 @@ public class DoNothingHistogramSnapshot implements HistogramSnapshot, DoNothingM
public double getMean() {
return 0;
}
-
- @Override
- public double getMin() {
- return 0.0D;
- }
}
diff --git a/metrics/interface/src/main/java/org/apache/iotdb/metrics/impl/DoNothingTimer.java b/metrics/interface/src/main/java/org/apache/iotdb/metrics/impl/DoNothingTimer.java
index b5896b800ee..434a3709339 100644
--- a/metrics/interface/src/main/java/org/apache/iotdb/metrics/impl/DoNothingTimer.java
+++ b/metrics/interface/src/main/java/org/apache/iotdb/metrics/impl/DoNothingTimer.java
@@ -20,7 +20,6 @@
package org.apache.iotdb.metrics.impl;
import org.apache.iotdb.metrics.type.HistogramSnapshot;
-import org.apache.iotdb.metrics.type.Rate;
import org.apache.iotdb.metrics.type.Timer;
import java.util.concurrent.TimeUnit;
@@ -37,7 +36,7 @@ public class DoNothingTimer implements Timer, DoNothingMetric {
}
@Override
- public Rate getImmutableRate() {
- return new DoNothingRate();
+ public long getCount() {
+ return 0;
}
}
diff --git a/metrics/interface/src/main/java/org/apache/iotdb/metrics/reporter/prometheus/PrometheusReporter.java b/metrics/interface/src/main/java/org/apache/iotdb/metrics/reporter/prometheus/PrometheusReporter.java
index d70da782be0..6f17f865b52 100644
--- a/metrics/interface/src/main/java/org/apache/iotdb/metrics/reporter/prometheus/PrometheusReporter.java
+++ b/metrics/interface/src/main/java/org/apache/iotdb/metrics/reporter/prometheus/PrometheusReporter.java
@@ -48,7 +48,6 @@ import java.io.IOException;
import java.io.StringWriter;
import java.io.Writer;
import java.time.Duration;
-import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
@@ -152,7 +151,7 @@ public class PrometheusReporter implements Reporter {
metricInfo.getTags(),
metricType,
snapshot,
- timer.getImmutableRate().getCount(),
+ timer.getCount(),
prometheusTextWriter);
}
}
@@ -181,18 +180,13 @@ public class PrometheusReporter implements Reporter {
prometheusTextWriter.writeHelp(name);
prometheusTextWriter.writeType(name, type);
prometheusTextWriter.writeSample(name + "_max", tags, snapshot.getMax());
- prometheusTextWriter.writeSample(
- name + "_sum", tags, Arrays.stream(snapshot.getValues()).sum());
+ prometheusTextWriter.writeSample(name + "_sum", tags, snapshot.getSum());
prometheusTextWriter.writeSample(name + "_count", tags, count);
- prometheusTextWriter.writeSample(
- name, addTags(tags, "quantile", "0.0"), snapshot.getValue(0.0));
prometheusTextWriter.writeSample(
name, addTags(tags, "quantile", "0.5"), snapshot.getValue(0.5));
prometheusTextWriter.writeSample(
name, addTags(tags, "quantile", "0.99"), snapshot.getValue(0.99));
- prometheusTextWriter.writeSample(
- name, addTags(tags, "quantile", "0.999"), snapshot.getValue(0.999));
}
private Map<String, String> addTags(Map<String, String> tags, String key, String value) {
diff --git a/metrics/interface/src/main/java/org/apache/iotdb/metrics/type/HistogramSnapshot.java b/metrics/interface/src/main/java/org/apache/iotdb/metrics/type/HistogramSnapshot.java
index bd3e1bf9998..76163cc64f6 100644
--- a/metrics/interface/src/main/java/org/apache/iotdb/metrics/type/HistogramSnapshot.java
+++ b/metrics/interface/src/main/java/org/apache/iotdb/metrics/type/HistogramSnapshot.java
@@ -19,7 +19,6 @@
package org.apache.iotdb.metrics.type;
-import java.util.Arrays;
import java.util.Map;
/** Used by timer and histogram. */
@@ -28,18 +27,12 @@ public interface HistogramSnapshot extends IMetric {
/** Get value by quantile. */
double getValue(double quantile);
- /** Get values in snapshot. */
- double[] getValues();
+ /** Get sum. */
+ double getSum();
/** Get the size of values in snapshot. */
int size();
- /** Get min value in values. */
- double getMin();
-
- /** Get median value in values. */
- double getMedian();
-
/** Get mean value in values. */
double getMean();
@@ -49,11 +42,9 @@ public interface HistogramSnapshot extends IMetric {
@Override
default void constructValueMap(Map<String, Object> result) {
result.put("max", getMax());
- result.put("sum", Arrays.stream(getValues()).sum());
+ result.put("sum", getSum());
- result.put("p0", getValue(0.0));
result.put("p50", getValue(0.5));
result.put("p99", getValue(0.99));
- result.put("p999", getValue(0.999));
}
}
diff --git a/metrics/interface/src/main/java/org/apache/iotdb/metrics/type/Timer.java b/metrics/interface/src/main/java/org/apache/iotdb/metrics/type/Timer.java
index 020d209f930..0f7478991f1 100644
--- a/metrics/interface/src/main/java/org/apache/iotdb/metrics/type/Timer.java
+++ b/metrics/interface/src/main/java/org/apache/iotdb/metrics/type/Timer.java
@@ -45,12 +45,11 @@ public interface Timer extends IMetric {
/** Take snapshot of timer. */
HistogramSnapshot takeSnapshot();
- /** It's not safe to use the update interface of this rate. */
- Rate getImmutableRate();
+ /** Get the count */
+ long getCount();
@Override
default void constructValueMap(Map<String, Object> result) {
takeSnapshot().constructValueMap(result);
- getImmutableRate().constructValueMap(result);
}
}
diff --git a/metrics/micrometer-metrics/src/main/java/org/apache/iotdb/metrics/micrometer/MicrometerMetricManager.java b/metrics/micrometer-metrics/src/main/java/org/apache/iotdb/metrics/micrometer/MicrometerMetricManager.java
index 107235f89ac..3575b70e259 100644
--- a/metrics/micrometer-metrics/src/main/java/org/apache/iotdb/metrics/micrometer/MicrometerMetricManager.java
+++ b/metrics/micrometer-metrics/src/main/java/org/apache/iotdb/metrics/micrometer/MicrometerMetricManager.java
@@ -76,7 +76,7 @@ public class MicrometerMetricManager extends AbstractMetricManager {
io.micrometer.core.instrument.DistributionSummary distributionSummary =
io.micrometer.core.instrument.DistributionSummary.builder(metricInfo.getName())
.tags(metricInfo.getTagsInArray())
- .publishPercentiles(0, 0.5, 0.75, 0.99, 0.999)
+ .publishPercentiles(0.5, 0.99)
.register(meterRegistry);
return new MicrometerHistogram(distributionSummary);
}
@@ -93,7 +93,7 @@ public class MicrometerMetricManager extends AbstractMetricManager {
io.micrometer.core.instrument.Timer timer =
io.micrometer.core.instrument.Timer.builder(metricInfo.getName())
.tags(metricInfo.getTagsInArray())
- .publishPercentiles(0, 0.5, 0.75, 0.99, 0.999)
+ .publishPercentiles(0.5, 0.99)
.register(meterRegistry);
return new MicrometerTimer(timer);
}
diff --git a/metrics/micrometer-metrics/src/main/java/org/apache/iotdb/metrics/micrometer/type/MicrometerHistogram.java b/metrics/micrometer-metrics/src/main/java/org/apache/iotdb/metrics/micrometer/type/MicrometerHistogram.java
index 6f901823742..4d96818b6d8 100644
--- a/metrics/micrometer-metrics/src/main/java/org/apache/iotdb/metrics/micrometer/type/MicrometerHistogram.java
+++ b/metrics/micrometer-metrics/src/main/java/org/apache/iotdb/metrics/micrometer/type/MicrometerHistogram.java
@@ -42,6 +42,6 @@ public class MicrometerHistogram implements Histogram {
@Override
public org.apache.iotdb.metrics.type.HistogramSnapshot takeSnapshot() {
- return new MicrometerHistogramSnapshot(distributionSummary.takeSnapshot());
+ return new MicrometerHistogramSnapshot(distributionSummary);
}
}
diff --git a/metrics/micrometer-metrics/src/main/java/org/apache/iotdb/metrics/micrometer/type/MicrometerHistogramSnapshot.java b/metrics/micrometer-metrics/src/main/java/org/apache/iotdb/metrics/micrometer/type/MicrometerHistogramSnapshot.java
index de36d7e633e..6626b11c662 100644
--- a/metrics/micrometer-metrics/src/main/java/org/apache/iotdb/metrics/micrometer/type/MicrometerHistogramSnapshot.java
+++ b/metrics/micrometer-metrics/src/main/java/org/apache/iotdb/metrics/micrometer/type/MicrometerHistogramSnapshot.java
@@ -21,17 +21,15 @@ package org.apache.iotdb.metrics.micrometer.type;
import org.apache.iotdb.metrics.type.HistogramSnapshot;
-import io.micrometer.core.instrument.distribution.ValueAtPercentile;
-
-import java.util.Arrays;
-
public class MicrometerHistogramSnapshot implements HistogramSnapshot {
+ io.micrometer.core.instrument.DistributionSummary distributionSummary;
io.micrometer.core.instrument.distribution.HistogramSnapshot histogramSnapshot;
public MicrometerHistogramSnapshot(
- io.micrometer.core.instrument.distribution.HistogramSnapshot histogramSnapshot) {
- this.histogramSnapshot = histogramSnapshot;
+ io.micrometer.core.instrument.DistributionSummary distributionSummary) {
+ this.distributionSummary = distributionSummary;
+ this.histogramSnapshot = distributionSummary.takeSnapshot();
}
@Override
@@ -51,10 +49,8 @@ public class MicrometerHistogramSnapshot implements HistogramSnapshot {
}
@Override
- public double[] getValues() {
- return Arrays.stream(this.histogramSnapshot.percentileValues())
- .mapToDouble(ValueAtPercentile::value)
- .toArray();
+ public double getSum() {
+ return this.distributionSummary.totalAmount();
}
@Override
@@ -62,11 +58,6 @@ public class MicrometerHistogramSnapshot implements HistogramSnapshot {
return this.histogramSnapshot.percentileValues().length;
}
- @Override
- public double getMedian() {
- return getValue(0.5);
- }
-
@Override
public double getMax() {
return this.histogramSnapshot.max();
@@ -76,10 +67,4 @@ public class MicrometerHistogramSnapshot implements HistogramSnapshot {
public double getMean() {
return this.histogramSnapshot.mean();
}
-
- @Override
- public double getMin() {
- // need distributionSummary to push 0 percentiles
- return getValue(0.0);
- }
}
diff --git a/metrics/micrometer-metrics/src/main/java/org/apache/iotdb/metrics/micrometer/type/MicrometerTimer.java b/metrics/micrometer-metrics/src/main/java/org/apache/iotdb/metrics/micrometer/type/MicrometerTimer.java
index c9fa79045de..9f011d94081 100644
--- a/metrics/micrometer-metrics/src/main/java/org/apache/iotdb/metrics/micrometer/type/MicrometerTimer.java
+++ b/metrics/micrometer-metrics/src/main/java/org/apache/iotdb/metrics/micrometer/type/MicrometerTimer.java
@@ -20,35 +20,30 @@
package org.apache.iotdb.metrics.micrometer.type;
import org.apache.iotdb.metrics.type.HistogramSnapshot;
-import org.apache.iotdb.metrics.type.Rate;
import org.apache.iotdb.metrics.type.Timer;
import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicLong;
public class MicrometerTimer implements Timer {
io.micrometer.core.instrument.Timer timer;
- MicrometerRate micrometerRate;
public MicrometerTimer(io.micrometer.core.instrument.Timer timer) {
this.timer = timer;
- micrometerRate = new MicrometerRate(new AtomicLong(0));
}
@Override
public void update(long duration, TimeUnit unit) {
timer.record(duration, unit);
- micrometerRate.mark();
}
@Override
public HistogramSnapshot takeSnapshot() {
- return new MicrometerTimerHistogramSnapshot(timer.takeSnapshot(), timer.baseTimeUnit());
+ return new MicrometerTimerHistogramSnapshot(timer);
}
@Override
- public Rate getImmutableRate() {
- return micrometerRate;
+ public long getCount() {
+ return timer.count();
}
}
diff --git a/metrics/micrometer-metrics/src/main/java/org/apache/iotdb/metrics/micrometer/type/MicrometerTimerHistogramSnapshot.java b/metrics/micrometer-metrics/src/main/java/org/apache/iotdb/metrics/micrometer/type/MicrometerTimerHistogramSnapshot.java
index 574de1b167e..cf80737fdb3 100644
--- a/metrics/micrometer-metrics/src/main/java/org/apache/iotdb/metrics/micrometer/type/MicrometerTimerHistogramSnapshot.java
+++ b/metrics/micrometer-metrics/src/main/java/org/apache/iotdb/metrics/micrometer/type/MicrometerTimerHistogramSnapshot.java
@@ -20,20 +20,19 @@ package org.apache.iotdb.metrics.micrometer.type;
import org.apache.iotdb.metrics.type.HistogramSnapshot;
-import java.util.Arrays;
import java.util.concurrent.TimeUnit;
/** This implementation is just for a timer as it needs the TimeUnit to convert from nanoseconds. */
public class MicrometerTimerHistogramSnapshot implements HistogramSnapshot {
+ io.micrometer.core.instrument.Timer timer;
io.micrometer.core.instrument.distribution.HistogramSnapshot histogramSnapshot;
private final TimeUnit baseTimeUnit;
- public MicrometerTimerHistogramSnapshot(
- io.micrometer.core.instrument.distribution.HistogramSnapshot histogramSnapshot,
- TimeUnit baseTimeUnit) {
- this.histogramSnapshot = histogramSnapshot;
- this.baseTimeUnit = baseTimeUnit;
+ public MicrometerTimerHistogramSnapshot(io.micrometer.core.instrument.Timer timer) {
+ this.timer = timer;
+ this.histogramSnapshot = timer.takeSnapshot();
+ this.baseTimeUnit = timer.baseTimeUnit();
}
@Override
@@ -53,10 +52,8 @@ public class MicrometerTimerHistogramSnapshot implements HistogramSnapshot {
}
@Override
- public double[] getValues() {
- return Arrays.stream(this.histogramSnapshot.percentileValues())
- .mapToDouble(k -> k.value(baseTimeUnit))
- .toArray();
+ public double getSum() {
+ return this.timer.totalTime(baseTimeUnit);
}
@Override
@@ -64,11 +61,6 @@ public class MicrometerTimerHistogramSnapshot implements HistogramSnapshot {
return this.histogramSnapshot.percentileValues().length;
}
- @Override
- public double getMedian() {
- return getValue(0.5);
- }
-
@Override
public double getMax() {
return this.histogramSnapshot.max(baseTimeUnit);
@@ -78,10 +70,4 @@ public class MicrometerTimerHistogramSnapshot implements HistogramSnapshot {
public double getMean() {
return this.histogramSnapshot.mean(baseTimeUnit);
}
-
- @Override
- public double getMin() {
- // need distributionSummary to push 0 percentiles
- return getValue(0.0);
- }
}
diff --git a/server/src/test/java/org/apache/iotdb/db/metric/MetricServiceTest.java b/server/src/test/java/org/apache/iotdb/db/metric/MetricServiceTest.java
index 18dfa7df4fd..a8cda7a619c 100644
--- a/server/src/test/java/org/apache/iotdb/db/metric/MetricServiceTest.java
+++ b/server/src/test/java/org/apache/iotdb/db/metric/MetricServiceTest.java
@@ -193,8 +193,7 @@ public class MetricServiceTest {
metricService.histogram(40, "histogram1", MetricLevel.IMPORTANT, "tag", "value");
metricService.histogram(50, "histogram1", MetricLevel.IMPORTANT, "tag", "value");
assertEquals(5, histogram1.count());
- assertEquals(5, histogram1.takeSnapshot().size());
- assertEquals(10.0D, histogram1.takeSnapshot().getMin(), 0.00001);
+ assertEquals(150.0D, histogram1.takeSnapshot().getSum(), 0.00001);
assertEquals(50.0D, histogram1.takeSnapshot().getMax(), 0.00001);
Histogram histogram2 =
metricService.getOrCreateHistogram("histogram1", MetricLevel.IMPORTANT, "tag", "value");
@@ -228,8 +227,7 @@ public class MetricServiceTest {
metricService.timer(6, TimeUnit.MILLISECONDS, "timer1", MetricLevel.IMPORTANT, "tag", "value");
metricService.timer(8, TimeUnit.MILLISECONDS, "timer1", MetricLevel.IMPORTANT, "tag", "value");
metricService.timer(10, TimeUnit.MILLISECONDS, "timer1", MetricLevel.IMPORTANT, "tag", "value");
- assertEquals(5, timer1.getImmutableRate().getCount());
- assertEquals(5, timer1.takeSnapshot().size());
+ assertEquals(5, timer1.getCount());
Timer timer2 = metricService.getOrCreateTimer("timer1", MetricLevel.IMPORTANT, "tag", "value");
assertEquals(timer1, timer2);
timer2 = metricService.getOrCreateTimer("timer2", MetricLevel.IMPORTANT);