🐛 fix metrics servce level config bug (#13449)

* 🐛 fix metrics servce level config bug

* 🐛 fix metrics servce level config bug

* 🐛 fix metrics servce level config bug

* 🐛 fix metrics servce level config bug
This commit is contained in:
xiaosheng 2023-12-04 09:34:47 +08:00 committed by GitHub
parent 6e9f337098
commit 58fa120795
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 6 deletions

View File

@ -41,13 +41,11 @@ import java.util.concurrent.atomic.AtomicLong;
* the key will not be displayed when exporting (to be optimized)
*/
public class MethodStatComposite extends AbstractMetricsExport {
private boolean serviceLevel;
private final AtomicBoolean samplesChanged = new AtomicBoolean(true);
public MethodStatComposite(ApplicationModel applicationModel) {
super(applicationModel);
this.serviceLevel = MethodMetric.isServiceLevel(getApplicationModel());
}
private final Map<MetricsKeyWrapper, Map<MethodMetric, AtomicLong>> methodNumStats = new ConcurrentHashMap<>();
@ -70,7 +68,8 @@ public class MethodStatComposite extends AbstractMetricsExport {
methodNumStats
.get(wrapper)
.computeIfAbsent(
new MethodMetric(getApplicationModel(), invocation, serviceLevel), k -> new AtomicLong(0L));
new MethodMetric(getApplicationModel(), invocation, getServiceLevel()),
k -> new AtomicLong(0L));
samplesChanged.set(true);
}

View File

@ -50,13 +50,11 @@ import java.util.stream.Collectors;
*/
@SuppressWarnings({"rawtypes", "unchecked"})
public class RtStatComposite extends AbstractMetricsExport {
private boolean serviceLevel;
private final AtomicBoolean samplesChanged = new AtomicBoolean(true);
public RtStatComposite(ApplicationModel applicationModel) {
super(applicationModel);
this.serviceLevel = MethodMetric.isServiceLevel(getApplicationModel());
}
private final Map<String, List<LongContainer<? extends Number>>> rtStats = new ConcurrentHashMap<>();
@ -190,7 +188,7 @@ public class RtStatComposite extends AbstractMetricsExport {
List<Action> actions;
actions = new LinkedList<>();
for (LongContainer container : rtStats.get(registryOpType)) {
MethodMetric key = new MethodMetric(getApplicationModel(), invocation, serviceLevel);
MethodMetric key = new MethodMetric(getApplicationModel(), invocation, getServiceLevel());
Number current = (Number) container.get(key);
if (current == null) {
container.putIfAbsent(key, container.getInitFunc().apply(key));

View File

@ -16,6 +16,7 @@
*/
package org.apache.dubbo.metrics.report;
import org.apache.dubbo.metrics.model.MethodMetric;
import org.apache.dubbo.rpc.model.ApplicationModel;
/**
@ -23,6 +24,8 @@ import org.apache.dubbo.rpc.model.ApplicationModel;
*/
public abstract class AbstractMetricsExport implements MetricsExport {
private volatile Boolean serviceLevel;
private final ApplicationModel applicationModel;
public AbstractMetricsExport(ApplicationModel applicationModel) {
@ -36,4 +39,19 @@ public abstract class AbstractMetricsExport implements MetricsExport {
public String getAppName() {
return getApplicationModel().getApplicationName();
}
protected boolean getServiceLevel() {
initServiceLevelConfig();
return this.serviceLevel;
}
private void initServiceLevelConfig() {
if (serviceLevel == null) {
synchronized (this) {
if (serviceLevel == null) {
this.serviceLevel = MethodMetric.isServiceLevel(getApplicationModel());
}
}
}
}
}