This is an automated email from the ASF dual-hosted git repository.
songxiaosheng 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 d2391d2abd Metrics default val set 0 (#12379)
d2391d2abd is described below
commit d2391d2abde386dbf6387d02667ed8f2cb23939c
Author: wxbty <38374721+wx...@users.noreply.github.com>
AuthorDate: Wed May 24 13:48:43 2023 +0800
Metrics default val set 0 (#12379)
* add comment
* use dubbo nullable
* fill default 0
* add licence
* fix ci
* fix ci
* fix ci
* add comment
* fix ci
* fix ci
* modify warn
-
Co-authored-by: x-shadow-man <1494445...@qq.com>
Co-authored-by: songxiaosheng
---
.../dubbo/metrics/data/MethodStatComposite.java| 16 --
.../dubbo/metrics/data/ServiceStatComposite.java | 3 ++
.../apache/dubbo/metrics/model/MetricsSupport.java | 27 --
.../dubbo/metrics/model/key/CategoryOverall.java | 3 +-
.../apache/dubbo/metrics/model/key/MetricsCat.java | 13 -
.../apache/dubbo/metrics/model/key/MetricsKey.java | 6 ---
.../dubbo/metrics/model/key/MetricsKeyWrapper.java | 15 ++
.../apache/dubbo/metrics/MetricsSupportTest.java | 59 ++
.../org/apache/dubbo/metrics/DefaultConstants.java | 6 ++-
.../dubbo/metrics/event/DefaultSubDispatcher.java | 12 +
.../metrics/collector/DefaultCollectorTest.java| 7 +--
.../dubbo/metrics/filter/MetricsFilterTest.java| 22
.../metadata/event/MetadataSubDispatcher.java | 7 +++
.../metadata/MetadataMetricsCollectorTest.java | 4 +-
.../registry/event/RegistrySubDispatcher.java | 7 +++
.../collector/RegistryMetricsCollectorTest.java| 22
16 files changed, 177 insertions(+), 52 deletions(-)
diff --git
a/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/data/MethodStatComposite.java
b/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/data/MethodStatComposite.java
index 7b029e8f95..a4c6bba709 100644
---
a/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/data/MethodStatComposite.java
+++
b/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/data/MethodStatComposite.java
@@ -17,9 +17,13 @@
package org.apache.dubbo.metrics.data;
+import org.apache.dubbo.common.logger.Logger;
+import org.apache.dubbo.common.logger.LoggerFactory;
import org.apache.dubbo.common.utils.CollectionUtils;
+import org.apache.dubbo.metrics.exception.MetricsNeverHappenException;
import org.apache.dubbo.metrics.model.MethodMetric;
import org.apache.dubbo.metrics.model.MetricsCategory;
+import org.apache.dubbo.metrics.model.MetricsSupport;
import org.apache.dubbo.metrics.model.key.MetricsKeyWrapper;
import org.apache.dubbo.metrics.model.sample.CounterMetricSample;
import org.apache.dubbo.metrics.model.sample.GaugeMetricSample;
@@ -41,9 +45,12 @@ import java.util.concurrent.atomic.AtomicLong;
*/
public class MethodStatComposite extends AbstractMetricsExport {
+private static final Logger logger =
LoggerFactory.getLogger(MethodStatComposite.class);
+
public MethodStatComposite(ApplicationModel applicationModel) {
super(applicationModel);
}
+
private final Map>
methodNumStats = new ConcurrentHashMap<>();
public void initWrapper(List metricsKeyWrappers) {
@@ -58,6 +65,7 @@ public class MethodStatComposite extends
AbstractMetricsExport {
return;
}
methodNumStats.get(wrapper).computeIfAbsent(new
MethodMetric(getApplicationModel(), invocation), k -> new
AtomicLong(0L)).getAndAdd(size);
+MetricsSupport.fillZero(methodNumStats);
}
public List export(MetricsCategory category) {
@@ -65,11 +73,13 @@ public class MethodStatComposite extends
AbstractMetricsExport {
for (MetricsKeyWrapper wrapper : methodNumStats.keySet()) {
Map stringAtomicLongMap =
methodNumStats.get(wrapper);
for (MethodMetric methodMetric : stringAtomicLongMap.keySet()) {
-if (methodMetric.getSampleType() == MetricSample.Type.GAUGE) {
+if (wrapper.getSampleType() == MetricSample.Type.COUNTER) {
list.add(new CounterMetricSample<>(wrapper,
-methodMetric.getTags(), category,
stringAtomicLongMap.get(methodMetric)));
-} else {
+methodMetric.getTags(), category,
stringAtomicLongMap.get(methodMetric)));
+} else if (wrapper.getSampleType() == MetricSample.Type.GAUGE)
{
list.add(new GaugeMetricSample<>(wrapper,
methodMetric.getTags(), category, stringAtomicLongMap, value ->
value.get(methodMetric).get()));
+} else {
+throw new MetricsNeverHappenExcepti