LINGLUOJUN commented on code in PR #13275:
URL: https://github.com/apache/dubbo/pull/13275#discussion_r1398600902
##########
dubbo-metrics/dubbo-metrics-default/src/main/java/org/apache/dubbo/metrics/collector/sample/ThreadPoolMetricsSampler.java:
##########
@@ -72,13 +73,12 @@ public void addExecutors(String name, ExecutorService
executorService) {
@Override
public List<MetricSample> sample() {
- List<MetricSample> metricSamples = new ArrayList<>();
-
- sampleThreadPoolExecutor.forEach((name, executor) -> {
- metricSamples.addAll(createMetricsSample(name, executor));
- });
+ return sampleThreadPoolExecutor.entrySet()
+ .stream()
+ .map(ele -> createMetricsSample(ele.getKey(), ele.getValue()))
+ .flatMap(Collection::stream)
+ .collect(Collectors.toList());
Review Comment:
ok, and it already fixed
##########
dubbo-metrics/dubbo-metrics-default/src/main/java/org/apache/dubbo/metrics/collector/sample/ThreadRejectMetricsCountSampler.java:
##########
@@ -47,28 +48,23 @@ public
ThreadRejectMetricsCountSampler(DefaultMetricsCollector collector) {
this.collector.addSampler(this);
}
- public void addMetricName(String name){
+ public void addMetricName(String name) {
this.metricNames.add(name);
- this.initMetricsCounter(name,name);
+ this.initMetricsCounter(name, name);
samplesChanged.set(true);
}
@Override
public List<MetricSample> sample() {
- List<MetricSample> metricSamples = new ArrayList<>();
- metricNames.stream().forEach(name->collect(metricSamples,name));
- return metricSamples;
- }
-
-
- private void collect(List<MetricSample> list, String metricName) {
- count(list, metricName, MetricsKey.THREAD_POOL_THREAD_REJECT_COUNT);
- }
-
- private <T extends Metric> void count(List<MetricSample> list, String
metricName, MetricsKey metricsKey) {
- getCount(metricName).filter(e -> !e.isEmpty())
- .ifPresent(map -> map.forEach((k, v) ->
- list.add(getGaugeMetricSample(metricsKey, k, THREAD_POOL, v,
AtomicLong::get))));
+ return metricNames
+ .stream()
+ .map(metricName -> getCount(metricName)
+ .entrySet()
+ .stream()
+ .map(ele ->
getGaugeMetricSample(MetricsKey.THREAD_POOL_THREAD_REJECT_COUNT, ele.getKey(),
THREAD_POOL, ele.getValue(), AtomicLong::get))
+ .collect(Collectors.toList()))
+ .filter(CollectionUtils::isNotEmpty)
+ .flatMap(Collection::stream).collect(Collectors.toList());
Review Comment:
fixed
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]