diff --git a/dubbo-metrics/dubbo-metrics-default/src/main/java/org/apache/dubbo/metrics/collector/sample/MetricThreadPoolExhaustedListener.java b/dubbo-metrics/dubbo-metrics-default/src/main/java/org/apache/dubbo/metrics/collector/sample/MetricThreadPoolExhaustedListener.java index 2a77b70542f..07b7fc5360e 100644 --- a/dubbo-metrics/dubbo-metrics-default/src/main/java/org/apache/dubbo/metrics/collector/sample/MetricThreadPoolExhaustedListener.java +++ b/dubbo-metrics/dubbo-metrics-default/src/main/java/org/apache/dubbo/metrics/collector/sample/MetricThreadPoolExhaustedListener.java @@ -38,6 +38,6 @@ public MetricThreadPoolExhaustedListener(String threadPoolExecutorName,ThreadRej @Override public void onEvent(ThreadPoolExhaustedEvent event) { threadRejectMetricsCountSampler.addMetricName(threadPoolExecutorName); - threadRejectMetricsCountSampler.incOnEvent(threadPoolExecutorName,threadPoolExecutorName); + threadRejectMetricsCountSampler.inc(threadPoolExecutorName,threadPoolExecutorName); } } diff --git a/dubbo-metrics/dubbo-metrics-default/src/main/java/org/apache/dubbo/metrics/collector/sample/MetricsCountSampleConfigurer.java b/dubbo-metrics/dubbo-metrics-default/src/main/java/org/apache/dubbo/metrics/collector/sample/MetricsCountSampleConfigurer.java index d66ba6021ee..0bb41f0a03d 100644 --- a/dubbo-metrics/dubbo-metrics-default/src/main/java/org/apache/dubbo/metrics/collector/sample/MetricsCountSampleConfigurer.java +++ b/dubbo-metrics/dubbo-metrics-default/src/main/java/org/apache/dubbo/metrics/collector/sample/MetricsCountSampleConfigurer.java @@ -18,7 +18,7 @@ package org.apache.dubbo.metrics.collector.sample; import org.apache.dubbo.metrics.model.Metric; -import java.util.function.Consumer; + import java.util.function.Function; public class MetricsCountSampleConfigurer { @@ -29,15 +29,6 @@ public class MetricsCountSampleConfigurer { public M metric; - public Long rt; - - public Consumer> fireEventHandler = new Consumer>() { - @Override - public void accept(MetricsCountSampleConfigurer skMetricsCountSampleConfigure) { - - } - }; - public void setSource(S source){ this.source = source; } @@ -60,15 +51,4 @@ public M getMetric() { return metric; } - public void setRt(Long rt) { - this.rt = rt; - } - - public Long getRt(){ - return this.rt; - } - - public Consumer> getFireEventHandler() { - return fireEventHandler; - } } diff --git a/dubbo-metrics/dubbo-metrics-default/src/main/java/org/apache/dubbo/metrics/collector/sample/MetricsCountSampler.java b/dubbo-metrics/dubbo-metrics-default/src/main/java/org/apache/dubbo/metrics/collector/sample/MetricsCountSampler.java index 0b561f54c0b..fe746a941b0 100644 --- a/dubbo-metrics/dubbo-metrics-default/src/main/java/org/apache/dubbo/metrics/collector/sample/MetricsCountSampler.java +++ b/dubbo-metrics/dubbo-metrics-default/src/main/java/org/apache/dubbo/metrics/collector/sample/MetricsCountSampler.java @@ -27,8 +27,6 @@ public interface MetricsCountSampler extends MetricsSamp void inc(S source, K metricName); - void incOnEvent(S source, K metricName); - Optional> getCount(K metricName); } diff --git a/dubbo-metrics/dubbo-metrics-default/src/main/java/org/apache/dubbo/metrics/collector/sample/SimpleMetricsCountSampler.java b/dubbo-metrics/dubbo-metrics-default/src/main/java/org/apache/dubbo/metrics/collector/sample/SimpleMetricsCountSampler.java index 7f01dcd222d..9c319737409 100644 --- a/dubbo-metrics/dubbo-metrics-default/src/main/java/org/apache/dubbo/metrics/collector/sample/SimpleMetricsCountSampler.java +++ b/dubbo-metrics/dubbo-metrics-default/src/main/java/org/apache/dubbo/metrics/collector/sample/SimpleMetricsCountSampler.java @@ -25,7 +25,6 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import java.util.concurrent.atomic.AtomicLong; -import java.util.function.Function; /** * @param request source @@ -41,18 +40,7 @@ public abstract class SimpleMetricsCountSampler @Override public void inc(S source, K metricName) { - doExecute(source, metricName, counter -> { - counter.incrementAndGet(); - return false; - }); - } - - @Override - public void incOnEvent(S source, K metricName) { - doExecute(source, metricName, counter -> { - counter.incrementAndGet(); - return true; - }); + getAtomicCounter(source, metricName).incrementAndGet(); } @Override @@ -64,7 +52,7 @@ public Optional> getCount(K metricName) { protected abstract void countConfigure(MetricsCountSampleConfigurer sampleConfigure); - private void doExecute(S source, K metricsName, Function counter) { + private AtomicLong getAtomicCounter(S source, K metricsName) { MetricsCountSampleConfigurer sampleConfigure = new MetricsCountSampleConfigurer<>(); sampleConfigure.setSource(source); sampleConfigure.setMetricsName(metricsName); @@ -84,11 +72,8 @@ private void doExecute(S source, K metricsName, Function co if (atomicCounter == null) { atomicCounter = metricAtomic.computeIfAbsent(sampleConfigure.getMetric(), k -> new AtomicLong()); } - Boolean isEvent = counter.apply(atomicCounter); + return atomicCounter; - if (isEvent) { - sampleConfigure.getFireEventHandler().accept(sampleConfigure); - } } } diff --git a/dubbo-metrics/dubbo-metrics-prometheus/src/test/java/org/apache/dubbo/metrics/prometheus/PrometheusMetricsThreadPoolTest.java b/dubbo-metrics/dubbo-metrics-prometheus/src/test/java/org/apache/dubbo/metrics/prometheus/PrometheusMetricsThreadPoolTest.java index 6c73838ef14..107c09ea976 100644 --- a/dubbo-metrics/dubbo-metrics-prometheus/src/test/java/org/apache/dubbo/metrics/prometheus/PrometheusMetricsThreadPoolTest.java +++ b/dubbo-metrics/dubbo-metrics-prometheus/src/test/java/org/apache/dubbo/metrics/prometheus/PrometheusMetricsThreadPoolTest.java @@ -146,7 +146,7 @@ void testThreadPoolRejectMetrics() { collector.setApplicationName(applicationModel.getApplicationName()); String threadPoolExecutorName="DubboServerHandler-20816"; ThreadRejectMetricsCountSampler threadRejectMetricsCountSampler=new ThreadRejectMetricsCountSampler(collector); - threadRejectMetricsCountSampler.incOnEvent(threadPoolExecutorName,threadPoolExecutorName); + threadRejectMetricsCountSampler.inc(threadPoolExecutorName,threadPoolExecutorName); threadRejectMetricsCountSampler.addMetricName(threadPoolExecutorName); List samples = collector.collect(); for (MetricSample sample : samples) {