This is an automated email from the ASF dual-hosted git repository.
albumenj pushed a commit to branch 3.2
in repository https://gitbox.apache.org/repos/asf/dubbo.git
The following commit(s) were added to refs/heads/3.2 by this push:
new e74c6381fb :recycle:refact metrics key and meter unit (#11661)
e74c6381fb is described below
commit e74c6381fb9ac676607d8495e4e3d98c828344d1
Author: songxiaosheng <[email protected]>
AuthorDate: Mon Feb 27 19:32:53 2023 +0800
:recycle:refact metrics key and meter unit (#11661)
---
.../org/apache/dubbo/metrics/model/MetricsKey.java | 29 +++++++---------------
.../collector/stat/MetadataStatComposite.java | 12 ++++-----
.../collector/MetadataMetricsCollectorTest.java | 22 ++++++++--------
.../collector/stat/RegistryStatComposite.java | 12 ++++-----
.../collector/RegistryMetricsCollectorTest.java | 10 ++++----
.../collector/RegistryMetricsSampleTest.java | 10 ++++----
6 files changed, 41 insertions(+), 54 deletions(-)
diff --git
a/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/model/MetricsKey.java
b/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/model/MetricsKey.java
index 39cecbfe49..0e3e160a1b 100644
---
a/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/model/MetricsKey.java
+++
b/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/model/MetricsKey.java
@@ -38,26 +38,15 @@ public enum MetricsKey {
METRIC_REQUESTS_LIMIT_AGG("dubbo.%s.requests.limit.aggregate", "Aggregated
limit Requests"),
METRIC_REQUESTS_TOTAL_FAILED_AGG("dubbo.%s.requests.failed.total.aggregate",
"Aggregated failed total Requests"),
- METRIC_QPS("dubbo.%s.qps.seconds", "Query Per Seconds"),
- METRIC_RT_LAST("dubbo.%s.rt.seconds.last", "Last Response Time"),
- METRIC_RT_MIN("dubbo.%s.rt.seconds.min", "Min Response Time"),
- METRIC_RT_MAX("dubbo.%s.rt.seconds.max", "Max Response Time"),
- METRIC_RT_SUM("dubbo.%s.rt.seconds.sum", "Sum Response Time"),
- METRIC_RT_AVG("dubbo.%s.rt.seconds.avg", "Average Response Time"),
- METRIC_RT_P99("dubbo.%s.rt.seconds.p99", "Response Time P99"),
- METRIC_RT_P95("dubbo.%s.rt.seconds.p95", "Response Time P95"),
-
- GENERIC_METRIC_REQUESTS("dubbo.%s.requests.total", "Total %s Requests"),
- GENERIC_METRIC_REQUESTS_SUCCEED("dubbo.%s.requests.succeed.total",
"Succeed %s Requests"),
- GENERIC_METRIC_REQUESTS_FAILED("dubbo.%s.requests.failed.total", "Failed
%s Requests"),
-
- GENERIC_METRIC_RT_LAST("dubbo.%s.rt.seconds.last", "Last Response Time"),
- GENERIC_METRIC_RT_MIN("dubbo.%s.rt.seconds.min", "Min Response Time"),
- GENERIC_METRIC_RT_MAX("dubbo.%s.rt.seconds.max", "Max Response Time"),
- GENERIC_METRIC_RT_SUM("dubbo.%s.rt.seconds.sum", "Sum Response Time"),
- GENERIC_METRIC_RT_AVG("dubbo.%s.rt.seconds.avg", "Average Response Time"),
- GENERIC_METRIC_RT_P99("dubbo.%s.rt.seconds.p99", "Response Time P99"),
- GENERIC_METRIC_RT_P95("dubbo.%s.rt.seconds.p95", "Response Time P95"),
+ METRIC_QPS("dubbo.%s.qps.total", "Query Per Seconds"),
+ METRIC_RT_LAST("dubbo.%s.rt.milliseconds.last", "Last Response Time"),
+ METRIC_RT_MIN("dubbo.%s.rt.milliseconds.min", "Min Response Time"),
+ METRIC_RT_MAX("dubbo.%s.rt.milliseconds.max", "Max Response Time"),
+ METRIC_RT_SUM("dubbo.%s.rt.milliseconds.sum", "Sum Response Time"),
+ METRIC_RT_AVG("dubbo.%s.rt.milliseconds.avg", "Average Response Time"),
+ METRIC_RT_P99("dubbo.%s.rt.milliseconds.p99", "Response Time P99"),
+ METRIC_RT_P95("dubbo.%s.rt.milliseconds.p95", "Response Time P95"),
+
// register metrics key
REGISTER_METRIC_REQUESTS("dubbo.registry.register.requests.total", "Total
Register Requests"),
diff --git
a/dubbo-metrics/dubbo-metrics-metadata/src/main/java/org/apache/dubbo/metrics/metadata/collector/stat/MetadataStatComposite.java
b/dubbo-metrics/dubbo-metrics-metadata/src/main/java/org/apache/dubbo/metrics/metadata/collector/stat/MetadataStatComposite.java
index 83cdbb855c..c017565158 100644
---
a/dubbo-metrics/dubbo-metrics-metadata/src/main/java/org/apache/dubbo/metrics/metadata/collector/stat/MetadataStatComposite.java
+++
b/dubbo-metrics/dubbo-metrics-metadata/src/main/java/org/apache/dubbo/metrics/metadata/collector/stat/MetadataStatComposite.java
@@ -62,14 +62,14 @@ public class MetadataStatComposite implements MetricsExport
{
private List<LongContainer<? extends Number>> initStats(String
registryOpType) {
List<LongContainer<? extends Number>> singleRtStats = new
ArrayList<>();
- singleRtStats.add(new AtomicLongContainer(new
MetricsKeyWrapper(registryOpType, MetricsKey.GENERIC_METRIC_RT_LAST)));
- singleRtStats.add(new LongAccumulatorContainer(new
MetricsKeyWrapper(registryOpType, MetricsKey.GENERIC_METRIC_RT_MIN), new
LongAccumulator(Long::min, Long.MAX_VALUE)));
- singleRtStats.add(new LongAccumulatorContainer(new
MetricsKeyWrapper(registryOpType, MetricsKey.GENERIC_METRIC_RT_MAX), new
LongAccumulator(Long::max, Long.MIN_VALUE)));
- singleRtStats.add(new AtomicLongContainer(new
MetricsKeyWrapper(registryOpType, MetricsKey.GENERIC_METRIC_RT_SUM),
(responseTime, longAccumulator) -> longAccumulator.addAndGet(responseTime)));
+ singleRtStats.add(new AtomicLongContainer(new
MetricsKeyWrapper(registryOpType, MetricsKey.METRIC_RT_LAST)));
+ singleRtStats.add(new LongAccumulatorContainer(new
MetricsKeyWrapper(registryOpType, MetricsKey.METRIC_RT_MIN), new
LongAccumulator(Long::min, Long.MAX_VALUE)));
+ singleRtStats.add(new LongAccumulatorContainer(new
MetricsKeyWrapper(registryOpType, MetricsKey.METRIC_RT_MAX), new
LongAccumulator(Long::max, Long.MIN_VALUE)));
+ singleRtStats.add(new AtomicLongContainer(new
MetricsKeyWrapper(registryOpType, MetricsKey.METRIC_RT_SUM), (responseTime,
longAccumulator) -> longAccumulator.addAndGet(responseTime)));
// AvgContainer is a special counter that stores the number of times
but outputs function of sum/times
- AtomicLongContainer avgContainer = new AtomicLongContainer(new
MetricsKeyWrapper(registryOpType, MetricsKey.GENERIC_METRIC_RT_AVG), (k, v) ->
v.incrementAndGet());
+ AtomicLongContainer avgContainer = new AtomicLongContainer(new
MetricsKeyWrapper(registryOpType, MetricsKey.METRIC_RT_AVG), (k, v) ->
v.incrementAndGet());
avgContainer.setValueSupplier(applicationName -> {
- LongContainer<? extends Number> totalContainer =
rtStats.stream().filter(longContainer ->
longContainer.isKeyWrapper(MetricsKey.GENERIC_METRIC_RT_SUM,
registryOpType)).findFirst().get();
+ LongContainer<? extends Number> totalContainer =
rtStats.stream().filter(longContainer ->
longContainer.isKeyWrapper(MetricsKey.METRIC_RT_SUM,
registryOpType)).findFirst().get();
AtomicLong totalRtTimes = avgContainer.get(applicationName);
AtomicLong totalRtSum = (AtomicLong)
totalContainer.get(applicationName);
return totalRtSum.get() / totalRtTimes.get();
diff --git
a/dubbo-metrics/dubbo-metrics-metadata/src/test/java/metrics/metrics/collector/MetadataMetricsCollectorTest.java
b/dubbo-metrics/dubbo-metrics-metadata/src/test/java/metrics/metrics/collector/MetadataMetricsCollectorTest.java
index a07712bccd..bf4cfcbdb6 100644
---
a/dubbo-metrics/dubbo-metrics-metadata/src/test/java/metrics/metrics/collector/MetadataMetricsCollectorTest.java
+++
b/dubbo-metrics/dubbo-metrics-metadata/src/test/java/metrics/metrics/collector/MetadataMetricsCollectorTest.java
@@ -17,8 +17,6 @@
package metrics.metrics.collector;
-import org.apache.dubbo.common.logger.ErrorTypeAwareLogger;
-import org.apache.dubbo.common.logger.LoggerFactory;
import org.apache.dubbo.config.ApplicationConfig;
import org.apache.dubbo.metrics.event.GlobalMetricsEventMulticaster;
import org.apache.dubbo.metrics.metadata.collector.MetadataMetricsCollector;
@@ -107,11 +105,11 @@ class MetadataMetricsCollectorTest {
return number.longValue();
}));
- Assertions.assertEquals(sampleMap.get(new
MetricsKeyWrapper(OP_TYPE_PUSH,
MetricsKey.GENERIC_METRIC_RT_LAST).targetKey()), lastTimePair.calc());
- Assertions.assertEquals(sampleMap.get(new
MetricsKeyWrapper(OP_TYPE_PUSH, MetricsKey.GENERIC_METRIC_RT_MIN).targetKey()),
Math.min(c1, c2));
- Assertions.assertEquals(sampleMap.get(new
MetricsKeyWrapper(OP_TYPE_PUSH, MetricsKey.GENERIC_METRIC_RT_MAX).targetKey()),
Math.max(c1, c2));
- Assertions.assertEquals(sampleMap.get(new
MetricsKeyWrapper(OP_TYPE_PUSH, MetricsKey.GENERIC_METRIC_RT_AVG).targetKey()),
(c1 + c2) / 2);
- Assertions.assertEquals(sampleMap.get(new
MetricsKeyWrapper(OP_TYPE_PUSH, MetricsKey.GENERIC_METRIC_RT_SUM).targetKey()),
c1 + c2);
+ Assertions.assertEquals(sampleMap.get(new
MetricsKeyWrapper(OP_TYPE_PUSH, MetricsKey.METRIC_RT_LAST).targetKey()),
lastTimePair.calc());
+ Assertions.assertEquals(sampleMap.get(new
MetricsKeyWrapper(OP_TYPE_PUSH, MetricsKey.METRIC_RT_MIN).targetKey()),
Math.min(c1, c2));
+ Assertions.assertEquals(sampleMap.get(new
MetricsKeyWrapper(OP_TYPE_PUSH, MetricsKey.METRIC_RT_MAX).targetKey()),
Math.max(c1, c2));
+ Assertions.assertEquals(sampleMap.get(new
MetricsKeyWrapper(OP_TYPE_PUSH, MetricsKey.METRIC_RT_AVG).targetKey()), (c1 +
c2) / 2);
+ Assertions.assertEquals(sampleMap.get(new
MetricsKeyWrapper(OP_TYPE_PUSH, MetricsKey.METRIC_RT_SUM).targetKey()), c1 +
c2);
}
@Test
@@ -157,11 +155,11 @@ class MetadataMetricsCollectorTest {
return number.longValue();
}));
- Assertions.assertEquals(sampleMap.get(new
MetricsKeyWrapper(OP_TYPE_SUBSCRIBE,
MetricsKey.GENERIC_METRIC_RT_LAST).targetKey()), lastTimePair.calc());
- Assertions.assertEquals(sampleMap.get(new
MetricsKeyWrapper(OP_TYPE_SUBSCRIBE,
MetricsKey.GENERIC_METRIC_RT_MIN).targetKey()), Math.min(c1, c2));
- Assertions.assertEquals(sampleMap.get(new
MetricsKeyWrapper(OP_TYPE_SUBSCRIBE,
MetricsKey.GENERIC_METRIC_RT_MAX).targetKey()), Math.max(c1, c2));
- Assertions.assertEquals(sampleMap.get(new
MetricsKeyWrapper(OP_TYPE_SUBSCRIBE,
MetricsKey.GENERIC_METRIC_RT_AVG).targetKey()), (c1 + c2) / 2);
- Assertions.assertEquals(sampleMap.get(new
MetricsKeyWrapper(OP_TYPE_SUBSCRIBE,
MetricsKey.GENERIC_METRIC_RT_SUM).targetKey()), c1 + c2);
+ Assertions.assertEquals(sampleMap.get(new
MetricsKeyWrapper(OP_TYPE_SUBSCRIBE, MetricsKey.METRIC_RT_LAST).targetKey()),
lastTimePair.calc());
+ Assertions.assertEquals(sampleMap.get(new
MetricsKeyWrapper(OP_TYPE_SUBSCRIBE, MetricsKey.METRIC_RT_MIN).targetKey()),
Math.min(c1, c2));
+ Assertions.assertEquals(sampleMap.get(new
MetricsKeyWrapper(OP_TYPE_SUBSCRIBE, MetricsKey.METRIC_RT_MAX).targetKey()),
Math.max(c1, c2));
+ Assertions.assertEquals(sampleMap.get(new
MetricsKeyWrapper(OP_TYPE_SUBSCRIBE, MetricsKey.METRIC_RT_AVG).targetKey()),
(c1 + c2) / 2);
+ Assertions.assertEquals(sampleMap.get(new
MetricsKeyWrapper(OP_TYPE_SUBSCRIBE, MetricsKey.METRIC_RT_SUM).targetKey()), c1
+ c2);
}
diff --git
a/dubbo-metrics/dubbo-metrics-registry/src/main/java/org/apache/dubbo/metrics/registry/collector/stat/RegistryStatComposite.java
b/dubbo-metrics/dubbo-metrics-registry/src/main/java/org/apache/dubbo/metrics/registry/collector/stat/RegistryStatComposite.java
index 1d955cd7a7..16ad947a92 100644
---
a/dubbo-metrics/dubbo-metrics-registry/src/main/java/org/apache/dubbo/metrics/registry/collector/stat/RegistryStatComposite.java
+++
b/dubbo-metrics/dubbo-metrics-registry/src/main/java/org/apache/dubbo/metrics/registry/collector/stat/RegistryStatComposite.java
@@ -65,14 +65,14 @@ public class RegistryStatComposite implements MetricsExport
{
private List<LongContainer<? extends Number>> initStats(String
registryOpType) {
List<LongContainer<? extends Number>> singleRtStats = new
ArrayList<>();
- singleRtStats.add(new AtomicLongContainer(new
MetricsKeyWrapper(registryOpType, MetricsKey.GENERIC_METRIC_RT_LAST)));
- singleRtStats.add(new LongAccumulatorContainer(new
MetricsKeyWrapper(registryOpType, MetricsKey.GENERIC_METRIC_RT_MIN), new
LongAccumulator(Long::min, Long.MAX_VALUE)));
- singleRtStats.add(new LongAccumulatorContainer(new
MetricsKeyWrapper(registryOpType, MetricsKey.GENERIC_METRIC_RT_MAX), new
LongAccumulator(Long::max, Long.MIN_VALUE)));
- singleRtStats.add(new AtomicLongContainer(new
MetricsKeyWrapper(registryOpType, MetricsKey.GENERIC_METRIC_RT_SUM),
(responseTime, longAccumulator) -> longAccumulator.addAndGet(responseTime)));
+ singleRtStats.add(new AtomicLongContainer(new
MetricsKeyWrapper(registryOpType, MetricsKey.METRIC_RT_LAST)));
+ singleRtStats.add(new LongAccumulatorContainer(new
MetricsKeyWrapper(registryOpType, MetricsKey.METRIC_RT_MIN), new
LongAccumulator(Long::min, Long.MAX_VALUE)));
+ singleRtStats.add(new LongAccumulatorContainer(new
MetricsKeyWrapper(registryOpType, MetricsKey.METRIC_RT_MAX), new
LongAccumulator(Long::max, Long.MIN_VALUE)));
+ singleRtStats.add(new AtomicLongContainer(new
MetricsKeyWrapper(registryOpType, MetricsKey.METRIC_RT_SUM), (responseTime,
longAccumulator) -> longAccumulator.addAndGet(responseTime)));
// AvgContainer is a special counter that stores the number of times
but outputs function of sum/times
- AtomicLongContainer avgContainer = new AtomicLongContainer(new
MetricsKeyWrapper(registryOpType, MetricsKey.GENERIC_METRIC_RT_AVG), (k, v) ->
v.incrementAndGet());
+ AtomicLongContainer avgContainer = new AtomicLongContainer(new
MetricsKeyWrapper(registryOpType, MetricsKey.METRIC_RT_AVG), (k, v) ->
v.incrementAndGet());
avgContainer.setValueSupplier(applicationName -> {
- LongContainer<? extends Number> totalContainer =
rtStats.stream().filter(longContainer ->
longContainer.isKeyWrapper(MetricsKey.GENERIC_METRIC_RT_SUM,
registryOpType)).findFirst().get();
+ LongContainer<? extends Number> totalContainer =
rtStats.stream().filter(longContainer ->
longContainer.isKeyWrapper(MetricsKey.METRIC_RT_SUM,
registryOpType)).findFirst().get();
AtomicLong totalRtTimes = avgContainer.get(applicationName);
AtomicLong totalRtSum = (AtomicLong)
totalContainer.get(applicationName);
return totalRtSum.get() / totalRtTimes.get();
diff --git
a/dubbo-metrics/dubbo-metrics-registry/src/test/java/org/apache/dubbo/metrics/registry/metrics/collector/RegistryMetricsCollectorTest.java
b/dubbo-metrics/dubbo-metrics-registry/src/test/java/org/apache/dubbo/metrics/registry/metrics/collector/RegistryMetricsCollectorTest.java
index d4e8f34cec..2789758812 100644
---
a/dubbo-metrics/dubbo-metrics-registry/src/test/java/org/apache/dubbo/metrics/registry/metrics/collector/RegistryMetricsCollectorTest.java
+++
b/dubbo-metrics/dubbo-metrics-registry/src/test/java/org/apache/dubbo/metrics/registry/metrics/collector/RegistryMetricsCollectorTest.java
@@ -103,11 +103,11 @@ class RegistryMetricsCollectorTest {
return number.longValue();
}));
- Assertions.assertEquals(sampleMap.get(new
MetricsKeyWrapper(OP_TYPE_REGISTER,
MetricsKey.GENERIC_METRIC_RT_LAST).targetKey()), lastTimePair.calc());
- Assertions.assertEquals(sampleMap.get(new
MetricsKeyWrapper(OP_TYPE_REGISTER,
MetricsKey.GENERIC_METRIC_RT_MIN).targetKey()), Math.min(c1, c2));
- Assertions.assertEquals(sampleMap.get(new
MetricsKeyWrapper(OP_TYPE_REGISTER,
MetricsKey.GENERIC_METRIC_RT_MAX).targetKey()), Math.max(c1, c2));
- Assertions.assertEquals(sampleMap.get(new
MetricsKeyWrapper(OP_TYPE_REGISTER,
MetricsKey.GENERIC_METRIC_RT_AVG).targetKey()), (c1 + c2) / 2);
- Assertions.assertEquals(sampleMap.get(new
MetricsKeyWrapper(OP_TYPE_REGISTER,
MetricsKey.GENERIC_METRIC_RT_SUM).targetKey()), c1 + c2);
+ Assertions.assertEquals(sampleMap.get(new
MetricsKeyWrapper(OP_TYPE_REGISTER, MetricsKey.METRIC_RT_LAST).targetKey()),
lastTimePair.calc());
+ Assertions.assertEquals(sampleMap.get(new
MetricsKeyWrapper(OP_TYPE_REGISTER, MetricsKey.METRIC_RT_MIN).targetKey()),
Math.min(c1, c2));
+ Assertions.assertEquals(sampleMap.get(new
MetricsKeyWrapper(OP_TYPE_REGISTER, MetricsKey.METRIC_RT_MAX).targetKey()),
Math.max(c1, c2));
+ Assertions.assertEquals(sampleMap.get(new
MetricsKeyWrapper(OP_TYPE_REGISTER, MetricsKey.METRIC_RT_AVG).targetKey()), (c1
+ c2) / 2);
+ Assertions.assertEquals(sampleMap.get(new
MetricsKeyWrapper(OP_TYPE_REGISTER, MetricsKey.METRIC_RT_SUM).targetKey()), c1
+ c2);
}
diff --git
a/dubbo-metrics/dubbo-metrics-registry/src/test/java/org/apache/dubbo/metrics/registry/metrics/collector/RegistryMetricsSampleTest.java
b/dubbo-metrics/dubbo-metrics-registry/src/test/java/org/apache/dubbo/metrics/registry/metrics/collector/RegistryMetricsSampleTest.java
index 92025d71c9..87c89ec4f2 100644
---
a/dubbo-metrics/dubbo-metrics-registry/src/test/java/org/apache/dubbo/metrics/registry/metrics/collector/RegistryMetricsSampleTest.java
+++
b/dubbo-metrics/dubbo-metrics-registry/src/test/java/org/apache/dubbo/metrics/registry/metrics/collector/RegistryMetricsSampleTest.java
@@ -79,11 +79,11 @@ class RegistryMetricsSampleTest {
return number.longValue();
}));
- Assertions.assertEquals(sampleMap.get(new
MetricsKeyWrapper(RegistryStatComposite.OP_TYPE_REGISTER,
MetricsKey.GENERIC_METRIC_RT_LAST).targetKey()), 0L);
- Assertions.assertEquals(sampleMap.get(new
MetricsKeyWrapper(RegistryStatComposite.OP_TYPE_REGISTER,
MetricsKey.GENERIC_METRIC_RT_MIN).targetKey()), 0L);
- Assertions.assertEquals(sampleMap.get(new
MetricsKeyWrapper(RegistryStatComposite.OP_TYPE_REGISTER,
MetricsKey.GENERIC_METRIC_RT_MAX).targetKey()), 10L);
- Assertions.assertEquals(sampleMap.get(new
MetricsKeyWrapper(RegistryStatComposite.OP_TYPE_REGISTER,
MetricsKey.GENERIC_METRIC_RT_AVG).targetKey()), 5L);
- Assertions.assertEquals(sampleMap.get(new
MetricsKeyWrapper(RegistryStatComposite.OP_TYPE_REGISTER,
MetricsKey.GENERIC_METRIC_RT_SUM).targetKey()), 10L);
+ Assertions.assertEquals(sampleMap.get(new
MetricsKeyWrapper(RegistryStatComposite.OP_TYPE_REGISTER,
MetricsKey.METRIC_RT_LAST).targetKey()), 0L);
+ Assertions.assertEquals(sampleMap.get(new
MetricsKeyWrapper(RegistryStatComposite.OP_TYPE_REGISTER,
MetricsKey.METRIC_RT_MIN).targetKey()), 0L);
+ Assertions.assertEquals(sampleMap.get(new
MetricsKeyWrapper(RegistryStatComposite.OP_TYPE_REGISTER,
MetricsKey.METRIC_RT_MAX).targetKey()), 10L);
+ Assertions.assertEquals(sampleMap.get(new
MetricsKeyWrapper(RegistryStatComposite.OP_TYPE_REGISTER,
MetricsKey.METRIC_RT_AVG).targetKey()), 5L);
+ Assertions.assertEquals(sampleMap.get(new
MetricsKeyWrapper(RegistryStatComposite.OP_TYPE_REGISTER,
MetricsKey.METRIC_RT_SUM).targetKey()), 10L);
}
@Test