Merge branch 'apache-3.2' into apache-3.3

# Conflicts:
#	dubbo-metrics/dubbo-metrics-default/src/main/java/org/apache/dubbo/metrics/collector/DefaultMetricsCollector.java
#	dubbo-metrics/dubbo-metrics-default/src/main/java/org/apache/dubbo/metrics/collector/sample/ThreadRejectMetricsCountSampler.java
#	dubbo-metrics/dubbo-metrics-event/src/main/java/org/apache/dubbo/metrics/model/key/MetricsKey.java
This commit is contained in:
Albumen Kevin 2023-08-31 18:59:20 +08:00
commit 36a80e4db7
46 changed files with 554 additions and 133 deletions

View File

@ -101,7 +101,7 @@ check 2.7.5 milestone for details.
* In consumer side the app cannot catch the exception from provider that is configured serialization="kryo". #4238
* fix StringUtils#isBlank #4725
* when the interfaceName of the Reference annotation has duplicated,the exception is puzzled #4160
* when anonymity bean is defined in spirng contextdubbo throw npe #
* when anonymity bean is defined in spring contextdubbo throw npe #
* add Thread ContextClassLoader #4712
* Fix judgment ipv4 address #4729
* The compilation of static methods should be excluded when generating the proxy. #4647

View File

@ -224,10 +224,8 @@ public abstract class AbstractDirectory<T> implements Directory<T> {
logger.warn(CLUSTER_NO_VALID_PROVIDER, "provider server or registry center crashed", "",
"No provider available after connectivity filter for the service " + getConsumerUrl().getServiceKey()
+ " All validInvokers' size: " + validInvokers.size()
+ " All routed invokers' size: " + routedResult.size()
+ " All invokers' size: " + invokers.size()
+ " from registry " + getUrl().getAddress()
+ " from registry " + this
+ " on the consumer " + NetUtils.getLocalHost()
+ " using the dubbo version " + Version.getVersion() + ".");
}

View File

@ -27,11 +27,12 @@ import org.apache.dubbo.rpc.cluster.RouterChain;
import org.apache.dubbo.rpc.cluster.SingleRouterChain;
import org.apache.dubbo.rpc.cluster.router.state.BitList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static org.apache.dubbo.common.constants.LoggerCodeConstants.CLUSTER_FAILED_SITE_SELECTION;
import static org.apache.dubbo.common.constants.RegistryConstants.REGISTER_MODE_KEY;
import static org.apache.dubbo.common.constants.RegistryConstants.REGISTRY_KEY;
/**
@ -130,6 +131,9 @@ public class StaticDirectory<T> extends AbstractDirectory<T> {
@Override
protected Map<String, String> getDirectoryMeta() {
return Collections.singletonMap(REGISTRY_KEY, "static");
Map<String, String> metas = new HashMap<>();
metas.put(REGISTRY_KEY, "static");
metas.put(REGISTER_MODE_KEY, "static");
return metas;
}
}

View File

@ -24,6 +24,8 @@ public interface QosConstants {
String QOS_ENABLE = "qos.enable";
String QOS_CHECK = "qos.check";
String QOS_HOST = "qos.host";
String QOS_PORT = "qos.port";

View File

@ -59,6 +59,7 @@ import static org.apache.dubbo.common.constants.QosConstants.ACCEPT_FOREIGN_IP_W
import static org.apache.dubbo.common.constants.QosConstants.ANONYMOUS_ACCESS_ALLOW_COMMANDS;
import static org.apache.dubbo.common.constants.QosConstants.ANONYMOUS_ACCESS_PERMISSION_LEVEL;
import static org.apache.dubbo.common.constants.QosConstants.ANONYMOUS_ACCESS_PERMISSION_LEVEL_COMPATIBLE;
import static org.apache.dubbo.common.constants.QosConstants.QOS_CHECK;
import static org.apache.dubbo.common.constants.QosConstants.QOS_ENABLE;
import static org.apache.dubbo.common.constants.QosConstants.QOS_ENABLE_COMPATIBLE;
import static org.apache.dubbo.common.constants.QosConstants.QOS_HOST;
@ -148,6 +149,11 @@ public class ApplicationConfig extends AbstractConfig {
*/
private Boolean qosEnable;
/**
* Whether qos should start success or not, will check qosEnable first
*/
private Boolean qosCheck;
/**
* The qos host to listen
*/
@ -445,6 +451,15 @@ public class ApplicationConfig extends AbstractConfig {
this.qosEnable = qosEnable;
}
@Parameter(key = QOS_CHECK)
public Boolean getQosCheck() {
return qosCheck;
}
public void setQosCheck(Boolean qosCheck) {
this.qosCheck = qosCheck;
}
@Parameter(key = QOS_HOST)
public String getQosHost() {
return qosHost;

View File

@ -83,6 +83,7 @@ java.util.Collections$EmptyList
java.util.Collections$EmptyMap
java.util.Collections$SingletonSet
java.util.Collections$SingletonList
java.util.Collections$SingletonMap
java.util.Collections$UnmodifiableCollection
java.util.Collections$UnmodifiableList
java.util.Collections$UnmodifiableMap

View File

@ -249,7 +249,7 @@
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
<version>1.18.3</version>
<version>1.19.0</version>
<scope>test</scope>
</dependency>

View File

@ -38,11 +38,14 @@ import org.apache.dubbo.config.invoker.DelegateProviderMetaDataInvoker;
import org.apache.dubbo.config.support.Parameter;
import org.apache.dubbo.config.utils.ConfigValidationUtils;
import org.apache.dubbo.metadata.ServiceNameMapping;
import org.apache.dubbo.metrics.event.MetricsEventBus;
import org.apache.dubbo.metrics.event.MetricsInitEvent;
import org.apache.dubbo.registry.client.metadata.MetadataUtils;
import org.apache.dubbo.rpc.Exporter;
import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.Protocol;
import org.apache.dubbo.rpc.ProxyFactory;
import org.apache.dubbo.rpc.RpcInvocation;
import org.apache.dubbo.rpc.ServerService;
import org.apache.dubbo.rpc.cluster.ConfiguratorFactory;
import org.apache.dubbo.rpc.model.ModuleModel;
@ -61,6 +64,7 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.TreeSet;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
@ -546,6 +550,16 @@ public class ServiceConfig<T> extends ServiceConfigBase<T> {
registerType = RegisterTypeEnum.NEVER_REGISTER;
}
exportUrl(url, registryURLs, registerType);
initServiceMethodMetrics(url);
}
private void initServiceMethodMetrics(URL url) {
String [] methods = Optional.ofNullable(url.getParameter(METHODS_KEY)).map(i->i.split(",")).orElse( new String[]{});
Arrays.stream(methods).forEach( method-> {
RpcInvocation invocation = new RpcInvocation(url.getServiceKey(),url.getServiceModel(),method,interfaceName, url.getProtocolServiceKey(), null, null,null,null,null,null);
MetricsEventBus.publish(MetricsInitEvent.toMetricsInitEvent(application.getApplicationModel(),invocation));
});
}
private void processServiceExecutor(URL url) {

View File

@ -27,7 +27,7 @@
<description>The spring config module of dubbo project</description>
<properties>
<skip_maven_deploy>false</skip_maven_deploy>
<spring-boot.version>2.7.14</spring-boot.version>
<spring-boot.version>2.7.15</spring-boot.version>
<!-- Uncomment spring_version property to check Spring 4.x compatibility -->
<!-- <spring_version>4.3.30.RELEASE</spring_version> -->
</properties>

View File

@ -520,6 +520,11 @@
<xsd:documentation><![CDATA[ Whether to enable qos or not. ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="qos-check" type="xsd:boolean">
<xsd:annotation>
<xsd:documentation><![CDATA[ Whether qos should start success or not, will check qosEnable first. ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="qos-host" type="xsd:string">
<xsd:annotation>
<xsd:documentation><![CDATA[ The qos host to listen. ]]></xsd:documentation>

View File

@ -30,7 +30,7 @@
<properties>
<skip_maven_deploy>true</skip_maven_deploy>
<spring-boot-maven-plugin.version>2.7.14</spring-boot-maven-plugin.version>
<spring-boot-maven-plugin.version>2.7.15</spring-boot-maven-plugin.version>
</properties>
<modules>

View File

@ -36,7 +36,7 @@
<properties>
<skip_maven_deploy>true</skip_maven_deploy>
<spring-boot-maven-plugin.version>2.7.14</spring-boot-maven-plugin.version>
<spring-boot-maven-plugin.version>2.7.15</spring-boot-maven-plugin.version>
</properties>
<artifactId>dubbo-demo-api</artifactId>

View File

@ -224,7 +224,7 @@
<plugin>
<groupId>org.graalvm.buildtools</groupId>
<artifactId>native-maven-plugin</artifactId>
<version>0.9.24</version>
<version>0.9.25</version>
<configuration>
<classesDirectory>${project.build.outputDirectory}</classesDirectory>
<metadataRepository>

View File

@ -222,7 +222,7 @@
<plugin>
<groupId>org.graalvm.buildtools</groupId>
<artifactId>native-maven-plugin</artifactId>
<version>0.9.24</version>
<version>0.9.25</version>
<configuration>
<classesDirectory>${project.build.outputDirectory}</classesDirectory>
<metadataRepository>

View File

@ -31,7 +31,7 @@
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<slf4j-log4j12.version>1.7.33</slf4j-log4j12.version>
<spring-boot.version>2.7.14</spring-boot.version>
<spring-boot.version>2.7.15</spring-boot.version>
<skip_maven_deploy>true</skip_maven_deploy>
</properties>

View File

@ -31,7 +31,7 @@
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<slf4j-log4j12.version>1.7.33</slf4j-log4j12.version>
<spring-boot.version>2.7.14</spring-boot.version>
<spring-boot.version>2.7.15</spring-boot.version>
<skip_maven_deploy>true</skip_maven_deploy>
</properties>

View File

@ -36,8 +36,8 @@
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<skip_maven_deploy>true</skip_maven_deploy>
<spring-boot.version>2.7.14</spring-boot.version>
<spring-boot-maven-plugin.version>2.7.14</spring-boot-maven-plugin.version>
<spring-boot.version>2.7.15</spring-boot.version>
<spring-boot-maven-plugin.version>2.7.15</spring-boot-maven-plugin.version>
<micrometer-core.version>1.11.3</micrometer-core.version>
</properties>
<dependencyManagement>

View File

@ -32,7 +32,7 @@
<properties>
<skip_maven_deploy>true</skip_maven_deploy>
<spring-boot-maven-plugin.version>2.7.14</spring-boot-maven-plugin.version>
<spring-boot-maven-plugin.version>2.7.15</spring-boot-maven-plugin.version>
</properties>
<modules>

View File

@ -92,11 +92,11 @@
<!-- Common libs -->
<!-- <spring_version>4.3.30.RELEASE</spring_version> -->
<spring_version>5.3.25</spring_version>
<spring_security_version>5.8.5</spring_security_version>
<spring_security_version>5.8.6</spring_security_version>
<javassist_version>3.29.2-GA</javassist_version>
<bytebuddy.version>1.14.6</bytebuddy.version>
<bytebuddy.version>1.14.7</bytebuddy.version>
<netty_version>3.2.10.Final</netty_version>
<netty4_version>4.1.95.Final</netty4_version>
<netty4_version>4.1.97.Final</netty4_version>
<mina_version>2.2.1</mina_version>
<grizzly_version>2.4.4</grizzly_version>
<httpclient_version>4.5.14</httpclient_version>
@ -114,7 +114,7 @@
<cxf_version>3.5.5</cxf_version>
<thrift_version>0.18.1</thrift_version>
<hessian_version>4.0.66</hessian_version>
<protobuf-java_version>3.24.1</protobuf-java_version>
<protobuf-java_version>3.24.2</protobuf-java_version>
<javax_annotation-api_version>1.3.2</javax_annotation-api_version>
<servlet_version>3.1.0</servlet_version>
<jetty_version>9.4.51.v20230217</jetty_version>
@ -129,7 +129,7 @@
<fst_version>2.57</fst_version>
<avro_version>1.11.1</avro_version>
<apollo_client_version>2.1.0</apollo_client_version>
<snakeyaml_version>2.1</snakeyaml_version>
<snakeyaml_version>2.2</snakeyaml_version>
<commons_lang3_version>3.12.0</commons_lang3_version>
<protostuff_version>1.8.0</protostuff_version>
<envoy_api_version>0.1.35</envoy_api_version>
@ -177,7 +177,7 @@
<jaxb_version>2.2.7</jaxb_version>
<activation_version>1.2.0</activation_version>
<test_container_version>1.18.3</test_container_version>
<test_container_version>1.19.0</test_container_version>
<etcd_launcher_version>0.7.6</etcd_launcher_version>
<hessian_lite_version>3.2.13</hessian_lite_version>
<swagger_version>1.6.11</swagger_version>

View File

@ -89,6 +89,12 @@ public abstract class CombMetricsCollector<E extends TimeCounterEvent> extends A
this.stats.incrementMethodKey(wrapper, methodMetric, size);
}
@Override
public void init(Invocation invocation, MetricsKeyWrapper wrapper) {
this.stats.initMethodKey(wrapper, invocation);
}
protected List<MetricSample> export(MetricsCategory category) {
return stats.export(category);
}

View File

@ -30,5 +30,7 @@ public interface MethodMetricsCollector<E extends TimeCounterEvent> extends Metr
void increment(MethodMetric methodMetric, MetricsKeyWrapper wrapper, int size);
void addMethodRt(Invocation invocation, String registryOpType, Long responseTime);
void init(Invocation invocation, MetricsKeyWrapper wrapper);
}

View File

@ -18,6 +18,7 @@
package org.apache.dubbo.metrics.collector;
import org.apache.dubbo.common.extension.SPI;
import org.apache.dubbo.metrics.event.MetricsEvent;
import org.apache.dubbo.metrics.event.TimeCounterEvent;
import org.apache.dubbo.metrics.listener.MetricsLifeListener;
import org.apache.dubbo.metrics.model.sample.MetricSample;
@ -42,4 +43,6 @@ public interface MetricsCollector<E extends TimeCounterEvent> extends MetricsLif
*/
List<MetricSample> collect();
default void initMetrics(MetricsEvent event) {};
}

View File

@ -112,6 +112,10 @@ public abstract class BaseStatComposite implements MetricsExport {
methodStatComposite.incrementMethodKey(metricsKeyWrapper, methodMetric, size);
}
public void initMethodKey(MetricsKeyWrapper metricsKeyWrapper, Invocation invocation) {
methodStatComposite.initMethodKey(metricsKeyWrapper, invocation);
}
@Override
public List<MetricSample> export(MetricsCategory category) {
List<MetricSample> list = new ArrayList<>();

View File

@ -26,6 +26,7 @@ import org.apache.dubbo.metrics.model.sample.CounterMetricSample;
import org.apache.dubbo.metrics.model.sample.GaugeMetricSample;
import org.apache.dubbo.metrics.model.sample.MetricSample;
import org.apache.dubbo.metrics.report.AbstractMetricsExport;
import org.apache.dubbo.rpc.Invocation;
import org.apache.dubbo.rpc.model.ApplicationModel;
import java.util.ArrayList;
@ -54,6 +55,13 @@ public class MethodStatComposite extends AbstractMetricsExport {
metricsKeyWrappers.forEach(appKey -> methodNumStats.put(appKey, new ConcurrentHashMap<>()));
}
public void initMethodKey(MetricsKeyWrapper wrapper, Invocation invocation) {
if (!methodNumStats.containsKey(wrapper)) {
return;
}
methodNumStats.get(wrapper).computeIfAbsent(new MethodMetric(getApplicationModel(), invocation), k -> new AtomicLong(0L));
}
public void incrementMethodKey(MetricsKeyWrapper wrapper, MethodMetric methodMetric, int size) {
if (!methodNumStats.containsKey(wrapper)) {
return;

View File

@ -0,0 +1,48 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.metrics.event;
import org.apache.dubbo.metrics.MetricsConstants;
import org.apache.dubbo.metrics.model.MethodMetric;
import org.apache.dubbo.metrics.model.MetricsSupport;
import org.apache.dubbo.metrics.model.key.MetricsLevel;
import org.apache.dubbo.metrics.model.key.TypeWrapper;
import org.apache.dubbo.rpc.Invocation;
import org.apache.dubbo.rpc.model.ApplicationModel;
import static org.apache.dubbo.metrics.MetricsConstants.ATTACHMENT_KEY_SERVICE;
import static org.apache.dubbo.metrics.model.key.MetricsKey.METRIC_REQUESTS;
public class MetricsInitEvent extends TimeCounterEvent {
private static final TypeWrapper METRIC_EVENT = new TypeWrapper(MetricsLevel.SERVICE, METRIC_REQUESTS);
public MetricsInitEvent(ApplicationModel source,TypeWrapper typeWrapper) {
super(source,typeWrapper);
}
public static MetricsInitEvent toMetricsInitEvent(ApplicationModel applicationModel, Invocation invocation) {
MethodMetric methodMetric = new MethodMetric(applicationModel, invocation);
MetricsInitEvent initEvent = new MetricsInitEvent(applicationModel, METRIC_EVENT);
initEvent.putAttachment(MetricsConstants.INVOCATION, invocation);
initEvent.putAttachment(MetricsConstants.METHOD_METRICS, methodMetric);
initEvent.putAttachment(ATTACHMENT_KEY_SERVICE, MetricsSupport.getInterfaceName(invocation));
initEvent.putAttachment(MetricsConstants.INVOCATION_SIDE, MetricsSupport.getSide(invocation));
return initEvent;
}
}

View File

@ -43,6 +43,7 @@ public class SimpleMetricsEventMulticaster implements MetricsEventMulticaster {
if (event instanceof EmptyEvent) {
return;
}
if (validateIfApplicationConfigExist(event)) return;
for (MetricsListener listener : listeners) {
if (listener.isSupport(event)) {

View File

@ -222,6 +222,11 @@ public class MetricsSupport {
collector.increment(event.getAttachmentValue(METHOD_METRICS), new MetricsKeyWrapper(metricsKey, placeType), SELF_INCREMENT_SIZE);
}
public static void init(MetricsKey metricsKey, MetricsPlaceValue placeType, MethodMetricsCollector<TimeCounterEvent> collector, MetricsEvent event) {
collector.init(event.getAttachmentValue(INVOCATION), new MetricsKeyWrapper(metricsKey, placeType));
}
/**
* Dec method num
*/

View File

@ -85,7 +85,7 @@ public class MetricsKeyWrapper {
return metricsKey.getName();
}
try {
return metricsKey.getNameByType(getType());
return String.format(metricsKey.getName(), getType());
} catch (Exception ignore) {
return metricsKey.getName();
}

View File

@ -18,6 +18,7 @@
package org.apache.dubbo.metrics;
import org.apache.dubbo.common.constants.CommonConstants;
import org.apache.dubbo.metrics.model.key.MetricsKey;
import org.apache.dubbo.metrics.model.key.MetricsKeyWrapper;
import org.apache.dubbo.metrics.model.key.MetricsLevel;
import org.apache.dubbo.metrics.model.key.MetricsPlaceValue;
@ -69,4 +70,28 @@ public interface DefaultConstants {
new MetricsKeyWrapper(METRIC_REQUESTS_CODEC_FAILED, MetricsPlaceValue.of(CommonConstants.PROVIDER, MetricsLevel.METHOD)),
new MetricsKeyWrapper(METRIC_REQUESTS_CODEC_FAILED, MetricsPlaceValue.of(CommonConstants.CONSUMER, MetricsLevel.METHOD))
);
List<MetricsKey> INIT_AGG_METHOD_KEYS = Arrays.asList(
MetricsKey.METRIC_REQUESTS_TOTAL_AGG,
MetricsKey.METRIC_REQUESTS_SUCCEED_AGG,
MetricsKey.METRIC_REQUESTS_FAILED_AGG,
MetricsKey.METRIC_REQUEST_BUSINESS_FAILED_AGG,
MetricsKey.METRIC_REQUESTS_TIMEOUT_AGG,
MetricsKey.METRIC_REQUESTS_LIMIT_AGG,
MetricsKey.METRIC_REQUESTS_TOTAL_FAILED_AGG,
MetricsKey.METRIC_REQUESTS_NETWORK_FAILED_AGG,
MetricsKey.METRIC_REQUESTS_CODEC_FAILED_AGG,
MetricsKey.METRIC_REQUESTS_TOTAL_SERVICE_UNAVAILABLE_FAILED_AGG
);
List<MetricsKey> INIT_DEFAULT_METHOD_KEYS = Arrays.asList(
MetricsKey.METRIC_REQUESTS,
MetricsKey.METRIC_REQUESTS_PROCESSING,
MetricsKey.METRIC_REQUESTS_FAILED_AGG,
MetricsKey.METRIC_REQUESTS_SUCCEED,
MetricsKey.METRIC_REQUESTS_TOTAL_FAILED,
MetricsKey.METRIC_REQUEST_BUSINESS_FAILED
);
}

View File

@ -46,6 +46,7 @@ import java.util.concurrent.ConcurrentMap;
import static org.apache.dubbo.common.constants.CommonConstants.CONSUMER_SIDE;
import static org.apache.dubbo.common.constants.CommonConstants.PROVIDER_SIDE;
import static org.apache.dubbo.metrics.DefaultConstants.INIT_AGG_METHOD_KEYS;
import static org.apache.dubbo.metrics.DefaultConstants.METRIC_THROWABLE;
import static org.apache.dubbo.metrics.model.MetricsCategory.QPS;
import static org.apache.dubbo.metrics.model.MetricsCategory.REQUESTS;
@ -55,7 +56,7 @@ import static org.apache.dubbo.metrics.model.MetricsCategory.RT;
* Aggregation metrics collector implementation of {@link MetricsCollector}.
* This collector only enabled when metrics aggregation config is enabled.
*/
public class AggregateMetricsCollector implements MetricsCollector<RequestEvent> {
public class AggregateMetricsCollector implements MetricsCollector<RequestEvent>{
private int bucketNum = DEFAULT_BUCKET_NUM;
private int timeWindowSeconds = DEFAULT_TIME_WINDOW_SECONDS;
private int qpsTimeWindowMillSeconds = DEFAULT_QPS_TIME_WINDOW_MILL_SECONDS;
@ -262,4 +263,41 @@ public class AggregateMetricsCollector implements MetricsCollector<RequestEvent>
applicationModel.getBeanFactory().getBean(DefaultMetricsCollector.class).getEventMulticaster().addListener(this);
}
@Override
public void initMetrics(MetricsEvent event) {
MethodMetric metric = new MethodMetric(applicationModel, event.getAttachmentValue(MetricsConstants.INVOCATION));
initMethodMetric(event);
initQpsMetric(metric);
initRtMetric(metric);
initRtAgrMetric(metric);
}
public void initMethodMetric(MetricsEvent event){
INIT_AGG_METHOD_KEYS.stream().forEach(key->initWindowCounter(event,key));
}
public void initQpsMetric(MethodMetric metric){
ConcurrentHashMapUtils.computeIfAbsent(qps, metric, methodMetric -> new TimeWindowCounter(bucketNum, timeWindowSeconds));
}
public void initRtMetric(MethodMetric metric){
ConcurrentHashMapUtils.computeIfAbsent(rt, metric, k -> new TimeWindowQuantile(DEFAULT_COMPRESSION, bucketNum, timeWindowSeconds));
}
public void initRtAgrMetric(MethodMetric metric){
ConcurrentHashMapUtils.computeIfAbsent(rtAgr, metric, k -> new TimeWindowAggregator(bucketNum, timeWindowSeconds));
}
public void initWindowCounter(MetricsEvent event, MetricsKey targetKey){
MetricsKeyWrapper metricsKeyWrapper = new MetricsKeyWrapper(targetKey, MetricsPlaceValue.of(event.getAttachmentValue(MetricsConstants.INVOCATION_SIDE), MetricsLevel.SERVICE));
MethodMetric metric = new MethodMetric(applicationModel, event.getAttachmentValue(MetricsConstants.INVOCATION));
ConcurrentMap<MethodMetric, TimeWindowCounter> counter = methodTypeCounter.computeIfAbsent(metricsKeyWrapper, k -> new ConcurrentHashMap<>());
ConcurrentHashMapUtils.computeIfAbsent(counter, metric, methodMetric -> new TimeWindowCounter(bucketNum, timeWindowSeconds));
}
}

View File

@ -20,6 +20,7 @@ package org.apache.dubbo.metrics.collector;
import org.apache.dubbo.common.constants.CommonConstants;
import org.apache.dubbo.common.extension.Activate;
import org.apache.dubbo.metrics.DefaultConstants;
import org.apache.dubbo.metrics.MetricsConstants;
import org.apache.dubbo.metrics.collector.sample.ErrorCodeSampler;
import org.apache.dubbo.metrics.collector.sample.MetricsSampler;
import org.apache.dubbo.metrics.collector.sample.SimpleMetricsCountSampler;
@ -30,9 +31,12 @@ import org.apache.dubbo.metrics.data.MethodStatComposite;
import org.apache.dubbo.metrics.data.RtStatComposite;
import org.apache.dubbo.metrics.event.DefaultSubDispatcher;
import org.apache.dubbo.metrics.event.MetricsEvent;
import org.apache.dubbo.metrics.event.MetricsInitEvent;
import org.apache.dubbo.metrics.event.RequestEvent;
import org.apache.dubbo.metrics.event.TimeCounterEvent;
import org.apache.dubbo.metrics.model.ApplicationMetric;
import org.apache.dubbo.metrics.model.MetricsCategory;
import org.apache.dubbo.metrics.model.MetricsSupport;
import org.apache.dubbo.metrics.model.key.MetricsLevel;
import org.apache.dubbo.metrics.model.key.MetricsPlaceValue;
import org.apache.dubbo.metrics.model.sample.CounterMetricSample;
@ -41,9 +45,12 @@ import org.apache.dubbo.rpc.model.ApplicationModel;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
import static org.apache.dubbo.metrics.DefaultConstants.INIT_DEFAULT_METHOD_KEYS;
import static org.apache.dubbo.metrics.model.MetricsCategory.APPLICATION;
import static org.apache.dubbo.metrics.model.key.MetricsKey.APPLICATION_METRIC_INFO;
import static org.apache.dubbo.metrics.model.key.MetricsKey.METRIC_REQUESTS_SERVICE_UNAVAILABLE_FAILED;
/**
* Default implementation of {@link MetricsCollector}
@ -65,6 +72,11 @@ public class DefaultMetricsCollector extends CombMetricsCollector<RequestEvent>
private final List<MetricsSampler> samplers = new ArrayList<>();
private final List<MetricsCollector> collectors = new ArrayList<>();
private final AtomicBoolean initialized = new AtomicBoolean();
public DefaultMetricsCollector(ApplicationModel applicationModel) {
super(new BaseStatComposite(applicationModel) {
@Override
@ -146,7 +158,26 @@ public class DefaultMetricsCollector extends CombMetricsCollector<RequestEvent>
@Override
public boolean isSupport(MetricsEvent event) {
return event instanceof RequestEvent;
return event instanceof RequestEvent || event instanceof MetricsInitEvent;
}
@Override
public void onEvent(TimeCounterEvent event) {
if(event instanceof MetricsInitEvent){
if(initialized.compareAndSet(false,true)) {
collectors.addAll(applicationModel.getBeanFactory().getBeansOfType(MetricsCollector.class));
}
collectors.stream().forEach(collector->collector.initMetrics(event));
return;
}
super.onEvent(event);
}
@Override
public void initMetrics(MetricsEvent event) {
MetricsPlaceValue dynamicPlaceType = MetricsPlaceValue.of(event.getAttachmentValue(MetricsConstants.INVOCATION_SIDE), MetricsLevel.METHOD);
INIT_DEFAULT_METHOD_KEYS.stream().forEach(key->MetricsSupport.init(key, dynamicPlaceType, (MethodMetricsCollector) this, event));
MetricsSupport.init(METRIC_REQUESTS_SERVICE_UNAVAILABLE_FAILED, MetricsPlaceValue.of(CommonConstants.CONSUMER, MetricsLevel.METHOD), (MethodMetricsCollector) this, event);
}
public SimpleMetricsCountSampler<String, MetricsEvent.Type, ApplicationMetric> applicationSampler = new SimpleMetricsCountSampler<String, MetricsEvent.Type, ApplicationMetric>() {

View File

@ -34,10 +34,10 @@ public class MetricThreadPoolExhaustedListener implements ThreadPoolExhaustedLis
public MetricThreadPoolExhaustedListener(String threadPoolExecutorName,ThreadRejectMetricsCountSampler sampler) {
this.threadPoolExecutorName=threadPoolExecutorName;
this.threadRejectMetricsCountSampler=sampler;
this.threadRejectMetricsCountSampler.addMetricName(threadPoolExecutorName);
}
@Override
public void onEvent(ThreadPoolExhaustedEvent event) {
threadRejectMetricsCountSampler.addMetricName(threadPoolExecutorName);
threadRejectMetricsCountSampler.inc(threadPoolExecutorName,threadPoolExecutorName);
}
}

View File

@ -51,6 +51,10 @@ public abstract class SimpleMetricsCountSampler<S, K, M extends Metric>
metricCounter.get(metricName));
}
protected void initMetricsCounter(S source, K metricsName){
getAtomicCounter(source,metricsName);
}
protected abstract void countConfigure(MetricsCountSampleConfigurer<S, K, M> sampleConfigure);
private AtomicLong getAtomicCounter(S source, K metricsName) {

View File

@ -32,6 +32,7 @@ public class ThreadRejectMetricsCountSampler extends MetricsNameCountSampler<Str
public ThreadRejectMetricsCountSampler(DefaultMetricsCollector collector) {
super(collector, THREAD_POOL,MetricsKey.THREAD_POOL_THREAD_REJECT_COUNT);
this.initMetricsCounter(name,name);
}
@Override

View File

@ -0,0 +1,152 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.metrics.collector;
import org.apache.dubbo.common.constants.CommonConstants;
import org.apache.dubbo.config.ApplicationConfig;
import org.apache.dubbo.config.MetricsConfig;
import org.apache.dubbo.config.nested.AggregationConfig;
import org.apache.dubbo.metrics.aggregate.TimeWindowCounter;
import org.apache.dubbo.metrics.event.MetricsEventBus;
import org.apache.dubbo.metrics.event.MetricsInitEvent;
import org.apache.dubbo.metrics.model.ServiceKeyMetric;
import org.apache.dubbo.metrics.model.key.MetricsKeyWrapper;
import org.apache.dubbo.metrics.model.key.MetricsLevel;
import org.apache.dubbo.metrics.model.key.MetricsPlaceValue;
import org.apache.dubbo.metrics.model.sample.CounterMetricSample;
import org.apache.dubbo.metrics.model.sample.GaugeMetricSample;
import org.apache.dubbo.metrics.model.sample.MetricSample;
import org.apache.dubbo.rpc.RpcInvocation;
import org.apache.dubbo.rpc.model.ApplicationModel;
import org.apache.dubbo.rpc.model.FrameworkModel;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicLong;
import java.util.stream.Collectors;
import static org.apache.dubbo.metrics.DefaultConstants.INIT_AGG_METHOD_KEYS;
import static org.apache.dubbo.metrics.DefaultConstants.INIT_DEFAULT_METHOD_KEYS;
import static org.apache.dubbo.metrics.model.key.MetricsKey.METRIC_REQUESTS;
import static org.apache.dubbo.metrics.model.key.MetricsKey.METRIC_REQUESTS_PROCESSING;
class InitServiceMetricsTest {
private ApplicationModel applicationModel;
private String interfaceName;
private String methodName;
private String group;
private String version;
private String side;
private DefaultMetricsCollector defaultCollector;
private AggregateMetricsCollector aggregateMetricsCollector;
@BeforeEach
public void setup() {
FrameworkModel frameworkModel = FrameworkModel.defaultModel();
applicationModel = frameworkModel.newApplication();
ApplicationConfig config = new ApplicationConfig();
config.setName("MockMetrics");
MetricsConfig metricsConfig = new MetricsConfig();
AggregationConfig aggregationConfig = new AggregationConfig();
aggregationConfig.setEnabled(true);
aggregationConfig.setBucketNum(12);
aggregationConfig.setTimeWindowSeconds(120);
metricsConfig.setAggregation(aggregationConfig);
applicationModel.getApplicationConfigManager().setMetrics(metricsConfig);
applicationModel.getApplicationConfigManager().setApplication(config);
defaultCollector = applicationModel.getBeanFactory().getBean(DefaultMetricsCollector.class);
defaultCollector.setCollectEnabled(true);
aggregateMetricsCollector = applicationModel.getBeanFactory().getOrRegisterBean(AggregateMetricsCollector.class);
aggregateMetricsCollector.setCollectEnabled(true);
interfaceName = "org.apache.dubbo.MockInterface";
methodName = "mockMethod";
group = "mockGroup";
version = "1.0.0";
side = CommonConstants.PROVIDER_SIDE;
String serviceKey=group+"/"+interfaceName+":"+version;
String protocolServiceKey=serviceKey+":dubbo";
RpcInvocation invocation = new RpcInvocation(serviceKey,null,methodName,interfaceName, protocolServiceKey, null, null,null,null,null,null);
MetricsEventBus.publish(MetricsInitEvent.toMetricsInitEvent(applicationModel,invocation));
}
@AfterEach
public void teardown() {
applicationModel.destroy();
}
@Test
void testMetricsInitEvent() {
List<MetricSample> metricSamples = defaultCollector.collect();
//INIT_DEFAULT_METHOD_KEYS.size() = 6
Assertions.assertEquals(INIT_DEFAULT_METHOD_KEYS.size(), metricSamples.size());
List<String> metricsNames = metricSamples.stream().map(MetricSample::getName).collect(Collectors.toList());
String REQUESTS = new MetricsKeyWrapper(METRIC_REQUESTS, MetricsPlaceValue.of(side, MetricsLevel.SERVICE)).targetKey();
String PROCESSING = new MetricsKeyWrapper(METRIC_REQUESTS_PROCESSING, MetricsPlaceValue.of(side, MetricsLevel.SERVICE)).targetKey();
Assertions.assertTrue(metricsNames.contains(REQUESTS));
Assertions.assertTrue(metricsNames.contains(PROCESSING));
for (MetricSample metricSample : metricSamples) {
if (metricSample instanceof GaugeMetricSample) {
GaugeMetricSample<?> gaugeMetricSample = (GaugeMetricSample<?>) metricSample;
Object objVal = gaugeMetricSample.getValue();
if (objVal instanceof Map) {
Map<ServiceKeyMetric, AtomicLong> value = (Map<ServiceKeyMetric, AtomicLong>) objVal;
Assertions.assertTrue(value.values().stream().allMatch(atomicLong -> atomicLong.intValue() == 0));
}
} else {
AtomicLong value = (AtomicLong) ((CounterMetricSample<?>) metricSample).getValue();
Assertions.assertEquals(0, value.intValue());
}
}
List<MetricSample> samples = aggregateMetricsCollector.collect();
//INIT_AGG_METHOD_KEYS.size(10) + qps(1) + rt(4) +rtAgr(3)= 18
Assertions.assertEquals(INIT_AGG_METHOD_KEYS.size()+ 1+ 4+ 3, samples.size());
for (MetricSample metricSample : samples) {
if (metricSample instanceof GaugeMetricSample) {
GaugeMetricSample<?> gaugeMetricSample = (GaugeMetricSample<?>) metricSample;
Object objVal = gaugeMetricSample.getValue();
if (objVal instanceof TimeWindowCounter) {
Assertions.assertEquals(0.0,((TimeWindowCounter) objVal).get());
}
}
}
}
}

View File

@ -35,5 +35,4 @@ public interface MetricsListener<E extends MetricsEvent> {
*/
void onEvent(E event);
}

View File

@ -17,116 +17,112 @@
package org.apache.dubbo.metrics.model.key;
/**
* Please follow a unified naming format as follows:
* dubbo_type_action_unit_otherfun
*/
public enum MetricsKey {
APPLICATION_METRIC_INFO("application.info.total", "Total Application Info"),
APPLICATION_METRIC_INFO("dubbo.application.info.total", "Total Application Info"),
CONFIGCENTER_METRIC_TOTAL("configcenter.total", "Config Changed Total"),
CONFIGCENTER_METRIC_TOTAL("dubbo.configcenter.total", "Config Changed Total"),
// provider metrics key
METRIC_REQUESTS("requests.total", "Total Requests"),
METRIC_REQUESTS_SUCCEED("requests.succeed.total", "Total Succeed Requests"),
METRIC_REQUEST_BUSINESS_FAILED("requests.business.failed.total", "Total Failed Business Requests"),
METRIC_REQUESTS("dubbo.%s.requests.total", "Total Requests"),
METRIC_REQUESTS_SUCCEED("dubbo.%s.requests.succeed.total", "Total Succeed Requests"),
METRIC_REQUEST_BUSINESS_FAILED("dubbo.%s.requests.business.failed.total", "Total Failed Business Requests"),
METRIC_REQUESTS_PROCESSING("requests.processing.total", "Processing Requests"),
METRIC_REQUESTS_TIMEOUT("requests.timeout.total", "Total Timeout Failed Requests"),
METRIC_REQUESTS_LIMIT("requests.limit.total", "Total Limit Failed Requests"),
METRIC_REQUESTS_FAILED("requests.unknown.failed.total", "Total Unknown Failed Requests"),
METRIC_REQUESTS_TOTAL_FAILED("requests.failed.total", "Total Failed Requests"),
METRIC_REQUESTS_NETWORK_FAILED("requests.failed.network.total", "Total network Failed Requests"),
METRIC_REQUESTS_SERVICE_UNAVAILABLE_FAILED("requests.failed.service.unavailable.total", "Total Service Unavailable Failed Requests"),
METRIC_REQUESTS_CODEC_FAILED("requests.failed.codec.total", "Total Codec Failed Requests"),
METRIC_REQUESTS_PROCESSING("dubbo.%s.requests.processing.total", "Processing Requests"),
METRIC_REQUESTS_TIMEOUT("dubbo.%s.requests.timeout.total", "Total Timeout Failed Requests"),
METRIC_REQUESTS_LIMIT("dubbo.%s.requests.limit.total", "Total Limit Failed Requests"),
METRIC_REQUESTS_FAILED("dubbo.%s.requests.unknown.failed.total", "Total Unknown Failed Requests"),
METRIC_REQUESTS_TOTAL_FAILED("dubbo.%s.requests.failed.total", "Total Failed Requests"),
METRIC_REQUESTS_NETWORK_FAILED("dubbo.%s.requests.failed.network.total", "Total network Failed Requests"),
METRIC_REQUESTS_SERVICE_UNAVAILABLE_FAILED("dubbo.%s.requests.failed.service.unavailable.total", "Total Service Unavailable Failed Requests"),
METRIC_REQUESTS_CODEC_FAILED("dubbo.%s.requests.failed.codec.total", "Total Codec Failed Requests"),
METRIC_REQUESTS_TOTAL_AGG("requests.total.aggregate", "Aggregated Total Requests"),
METRIC_REQUESTS_SUCCEED_AGG("requests.succeed.aggregate", "Aggregated Succeed Requests"),
METRIC_REQUESTS_FAILED_AGG("requests.failed.aggregate", "Aggregated Failed Requests"),
METRIC_REQUEST_BUSINESS_FAILED_AGG("requests.business.failed.aggregate", "Aggregated Business Failed Requests"),
METRIC_REQUESTS_TIMEOUT_AGG("requests.timeout.failed.aggregate", "Aggregated timeout Failed Requests"),
METRIC_REQUESTS_LIMIT_AGG("requests.limit.aggregate", "Aggregated limit Requests"),
METRIC_REQUESTS_TOTAL_FAILED_AGG("requests.failed.total.aggregate", "Aggregated failed total Requests"),
METRIC_REQUESTS_NETWORK_FAILED_AGG("requests.failed.network.total.aggregate", "Aggregated failed network total Requests"),
METRIC_REQUESTS_CODEC_FAILED_AGG("requests.failed.codec.total.aggregate", "Aggregated failed codec total Requests"),
METRIC_REQUESTS_TOTAL_SERVICE_UNAVAILABLE_FAILED_AGG("requests.failed.service.unavailable.total.aggregate", "Aggregated failed codec total Requests"),
METRIC_REQUESTS_TOTAL_AGG("dubbo.%s.requests.total.aggregate", "Aggregated Total Requests"),
METRIC_REQUESTS_SUCCEED_AGG("dubbo.%s.requests.succeed.aggregate", "Aggregated Succeed Requests"),
METRIC_REQUESTS_FAILED_AGG("dubbo.%s.requests.failed.aggregate", "Aggregated Failed Requests"),
METRIC_REQUEST_BUSINESS_FAILED_AGG("dubbo.%s.requests.business.failed.aggregate", "Aggregated Business Failed Requests"),
METRIC_REQUESTS_TIMEOUT_AGG("dubbo.%s.requests.timeout.failed.aggregate", "Aggregated timeout Failed Requests"),
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_REQUESTS_NETWORK_FAILED_AGG("dubbo.%s.requests.failed.network.total.aggregate", "Aggregated failed network total Requests"),
METRIC_REQUESTS_CODEC_FAILED_AGG("dubbo.%s.requests.failed.codec.total.aggregate", "Aggregated failed codec total Requests"),
METRIC_REQUESTS_TOTAL_SERVICE_UNAVAILABLE_FAILED_AGG("dubbo.%s.requests.failed.service.unavailable.total.aggregate", "Aggregated failed codec total Requests"),
METRIC_QPS("qps.total", "Query Per Seconds"),
METRIC_RT_LAST("rt.milliseconds.last", "Last Response Time"),
METRIC_RT_MIN("rt.milliseconds.min", "Min Response Time"),
METRIC_RT_MAX("rt.milliseconds.max", "Max Response Time"),
METRIC_RT_SUM("rt.milliseconds.sum", "Sum Response Time"),
METRIC_RT_AVG("rt.milliseconds.avg", "Average Response Time"),
METRIC_RT_P99("rt.milliseconds.p99", "Response Time P99"),
METRIC_RT_P95("rt.milliseconds.p95", "Response Time P95"),
METRIC_RT_P90("rt.milliseconds.p90", "Response Time P90"),
METRIC_RT_P50("rt.milliseconds.p50", "Response Time P50"),
METRIC_RT_MIN_AGG("rt.milliseconds.min.aggregate", "Aggregated Min Response"),
METRIC_RT_MAX_AGG("rt.milliseconds.max.aggregate", "Aggregated Max Response"),
METRIC_RT_AVG_AGG("rt.milliseconds.avg.aggregate", "Aggregated Avg Response"),
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"),
METRIC_RT_P90("dubbo.%s.rt.milliseconds.p90", "Response Time P90"),
METRIC_RT_P50("dubbo.%s.rt.milliseconds.p50", "Response Time P50"),
METRIC_RT_MIN_AGG("dubbo.%s.rt.min.milliseconds.aggregate", "Aggregated Min Response"),
METRIC_RT_MAX_AGG("dubbo.%s.rt.max.milliseconds.aggregate", "Aggregated Max Response"),
METRIC_RT_AVG_AGG("dubbo.%s.rt.avg.milliseconds.aggregate", "Aggregated Avg Response"),
// register metrics key
REGISTER_METRIC_REQUESTS("registry.register.requests.total", "Total Register Requests"),
REGISTER_METRIC_REQUESTS_SUCCEED("registry.register.requests.succeed.total", "Succeed Register Requests"),
REGISTER_METRIC_REQUESTS_FAILED("registry.register.requests.failed.total", "Failed Register Requests"),
METRIC_RT_HISTOGRAM("rt.milliseconds.histogram", "Response Time Histogram"),
REGISTER_METRIC_REQUESTS("dubbo.registry.register.requests.total", "Total Register Requests"),
REGISTER_METRIC_REQUESTS_SUCCEED("dubbo.registry.register.requests.succeed.total", "Succeed Register Requests"),
REGISTER_METRIC_REQUESTS_FAILED("dubbo.registry.register.requests.failed.total", "Failed Register Requests"),
METRIC_RT_HISTOGRAM("dubbo.%s.rt.milliseconds.histogram", "Response Time Histogram"),
GENERIC_METRIC_REQUESTS("requests.total", "Total %s Requests"),
GENERIC_METRIC_REQUESTS_SUCCEED("requests.succeed.total", "Succeed %s Requests"),
GENERIC_METRIC_REQUESTS_FAILED("requests.failed.total", "Failed %s Requests"),
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"),
// subscribe metrics key
SUBSCRIBE_METRIC_NUM("registry.subscribe.num.total", "Total Subscribe Num"),
SUBSCRIBE_METRIC_NUM_SUCCEED("registry.subscribe.num.succeed.total", "Succeed Subscribe Num"),
SUBSCRIBE_METRIC_NUM_FAILED("registry.subscribe.num.failed.total", "Failed Subscribe Num"),
SUBSCRIBE_METRIC_NUM("dubbo.registry.subscribe.num.total", "Total Subscribe Num"),
SUBSCRIBE_METRIC_NUM_SUCCEED("dubbo.registry.subscribe.num.succeed.total", "Succeed Subscribe Num"),
SUBSCRIBE_METRIC_NUM_FAILED("dubbo.registry.subscribe.num.failed.total", "Failed Subscribe Num"),
// directory metrics key
DIRECTORY_METRIC_NUM_ALL("registry.directory.num.all", "All Directory Urls"),
DIRECTORY_METRIC_NUM_VALID("registry.directory.num.valid.total", "Valid Directory Urls"),
DIRECTORY_METRIC_NUM_TO_RECONNECT("registry.directory.num.to_reconnect.total", "ToReconnect Directory Urls"),
DIRECTORY_METRIC_NUM_DISABLE("registry.directory.num.disable.total", "Disable Directory Urls"),
DIRECTORY_METRIC_NUM_ALL("dubbo.registry.directory.num.all", "All Directory Urls"),
DIRECTORY_METRIC_NUM_VALID("dubbo.registry.directory.num.valid.total", "Valid Directory Urls"),
DIRECTORY_METRIC_NUM_TO_RECONNECT("dubbo.registry.directory.num.to_reconnect.total", "ToReconnect Directory Urls"),
DIRECTORY_METRIC_NUM_DISABLE("dubbo.registry.directory.num.disable.total", "Disable Directory Urls"),
NOTIFY_METRIC_REQUESTS("registry.notify.requests.total", "Total Notify Requests"),
NOTIFY_METRIC_NUM_LAST("registry.notify.num.last", "Last Notify Nums"),
NOTIFY_METRIC_REQUESTS("dubbo.registry.notify.requests.total", "Total Notify Requests"),
NOTIFY_METRIC_NUM_LAST("dubbo.registry.notify.num.last", "Last Notify Nums"),
THREAD_POOL_CORE_SIZE("thread.pool.core.size", "Thread Pool Core Size"),
THREAD_POOL_LARGEST_SIZE("thread.pool.largest.size", "Thread Pool Largest Size"),
THREAD_POOL_MAX_SIZE("thread.pool.max.size", "Thread Pool Max Size"),
THREAD_POOL_ACTIVE_SIZE("thread.pool.active.size", "Thread Pool Active Size"),
THREAD_POOL_THREAD_COUNT("thread.pool.thread.count", "Thread Pool Thread Count"),
THREAD_POOL_QUEUE_SIZE("thread.pool.queue.size", "Thread Pool Queue Size"),
THREAD_POOL_THREAD_REJECT_COUNT("thread.pool.reject.thread.count", "Thread Pool Reject Thread Count"),
THREAD_POOL_CORE_SIZE("dubbo.thread.pool.core.size", "Thread Pool Core Size"),
THREAD_POOL_LARGEST_SIZE("dubbo.thread.pool.largest.size", "Thread Pool Largest Size"),
THREAD_POOL_MAX_SIZE("dubbo.thread.pool.max.size", "Thread Pool Max Size"),
THREAD_POOL_ACTIVE_SIZE("dubbo.thread.pool.active.size", "Thread Pool Active Size"),
THREAD_POOL_THREAD_COUNT("dubbo.thread.pool.thread.count", "Thread Pool Thread Count"),
THREAD_POOL_QUEUE_SIZE("dubbo.thread.pool.queue.size", "Thread Pool Queue Size"),
THREAD_POOL_THREAD_REJECT_COUNT("dubbo.thread.pool.reject.thread.count", "Thread Pool Reject Thread Count"),
// metadata push metrics key
METADATA_PUSH_METRIC_NUM("metadata.push.num.total", "Total Push Num"),
METADATA_PUSH_METRIC_NUM_SUCCEED("metadata.push.num.succeed.total", "Succeed Push Num"),
METADATA_PUSH_METRIC_NUM_FAILED("metadata.push.num.failed.total", "Failed Push Num"),
METADATA_PUSH_METRIC_NUM("dubbo.metadata.push.num.total", "Total Push Num"),
METADATA_PUSH_METRIC_NUM_SUCCEED("dubbo.metadata.push.num.succeed.total", "Succeed Push Num"),
METADATA_PUSH_METRIC_NUM_FAILED("dubbo.metadata.push.num.failed.total", "Failed Push Num"),
// metadata subscribe metrics key
METADATA_SUBSCRIBE_METRIC_NUM("metadata.subscribe.num.total", "Total Metadata Subscribe Num"),
METADATA_SUBSCRIBE_METRIC_NUM_SUCCEED("metadata.subscribe.num.succeed.total", "Succeed Metadata Subscribe Num"),
METADATA_SUBSCRIBE_METRIC_NUM_FAILED("metadata.subscribe.num.failed.total", "Failed Metadata Subscribe Num"),
METADATA_SUBSCRIBE_METRIC_NUM("dubbo.metadata.subscribe.num.total", "Total Metadata Subscribe Num"),
METADATA_SUBSCRIBE_METRIC_NUM_SUCCEED("dubbo.metadata.subscribe.num.succeed.total", "Succeed Metadata Subscribe Num"),
METADATA_SUBSCRIBE_METRIC_NUM_FAILED("dubbo.metadata.subscribe.num.failed.total", "Failed Metadata Subscribe Num"),
// register service metrics key
SERVICE_REGISTER_METRIC_REQUESTS("registry.total", "Total Service-Level Register Requests"),
SERVICE_REGISTER_METRIC_REQUESTS_SUCCEED("registry.succeed.total", "Succeed Service-Level Register Requests"),
SERVICE_REGISTER_METRIC_REQUESTS_FAILED("registry.failed.total", "Failed Service-Level Register Requests"),
SERVICE_REGISTER_METRIC_REQUESTS("dubbo.registry.register.service.total", "Total Service-Level Register Requests"),
SERVICE_REGISTER_METRIC_REQUESTS_SUCCEED("dubbo.registry.register.service.succeed.total", "Succeed Service-Level Register Requests"),
SERVICE_REGISTER_METRIC_REQUESTS_FAILED("dubbo.registry.register.service.failed.total", "Failed Service-Level Register Requests"),
// subscribe metrics key
SERVICE_SUBSCRIBE_METRIC_NUM("registry.subscribe.service.num.total", "Total Service-Level Subscribe Num"),
SERVICE_SUBSCRIBE_METRIC_NUM_SUCCEED("registry.subscribe.service.num.succeed.total", "Succeed Service-Level Num"),
SERVICE_SUBSCRIBE_METRIC_NUM_FAILED("registry.subscribe.service.num.failed.total", "Failed Service-Level Num"),
SERVICE_SUBSCRIBE_METRIC_NUM("dubbo.registry.subscribe.service.num.total", "Total Service-Level Subscribe Num"),
SERVICE_SUBSCRIBE_METRIC_NUM_SUCCEED("dubbo.registry.subscribe.service.num.succeed.total", "Succeed Service-Level Num"),
SERVICE_SUBSCRIBE_METRIC_NUM_FAILED("dubbo.registry.subscribe.service.num.failed.total", "Failed Service-Level Num"),
// store provider metadata service key
STORE_PROVIDER_METADATA("metadata.store.provider.total", "Store Provider Metadata"),
STORE_PROVIDER_METADATA("dubbo.metadata.store.provider.total", "Store Provider Metadata"),
STORE_PROVIDER_METADATA_SUCCEED("metadata.store.provider.succeed.total", "Succeed Store Provider Metadata"),
STORE_PROVIDER_METADATA_SUCCEED("dubbo.metadata.store.provider.succeed.total", "Succeed Store Provider Metadata"),
STORE_PROVIDER_METADATA_FAILED("metadata.store.provider.failed.total", "Failed Store Provider Metadata"),
STORE_PROVIDER_METADATA_FAILED("dubbo.metadata.store.provider.failed.total", "Failed Store Provider Metadata"),
METADATA_GIT_COMMITID_METRIC("git.commit.id", "Git Commit Id Metrics"),
// consumer metrics key
INVOKER_NO_AVAILABLE_COUNT("consumer.invoker.no.available.count", "Request Throw No Invoker Available Exception Count"),
INVOKER_NO_AVAILABLE_COUNT("dubbo.consumer.invoker.no.available.count", "Request Throw No Invoker Available Exception Count"),
// count the number of occurrences of each error code
ERROR_CODE_COUNT("dubbo.error.code.count","The Count Of Occurrences for Each Error Code"),
@ -144,15 +140,15 @@ public enum MetricsKey {
NETTY_ALLOCATOR_CHUNK_SIZE("netty.allocator.chunk.size", "Netty Allocator Chunk Size"),
;
private String nameSuffix;
private String name;
private String description;
public final String getName() {
return "dubbo." + nameSuffix;
return this.name;
}
public final String getNameByType(String type) {
return "dubbo." + type + "." + nameSuffix;
return String.format(name, type);
}
public static MetricsKey getMetricsByName(String name){
@ -168,9 +164,8 @@ public enum MetricsKey {
return this.description;
}
MetricsKey(String nameSuffix, String description) {
this.nameSuffix = nameSuffix;
MetricsKey(String name, String description) {
this.name = name;
this.description = description;
}
}

View File

@ -25,7 +25,6 @@ import org.apache.dubbo.config.nested.AggregationConfig;
import org.apache.dubbo.metrics.model.key.MetricsKey;
import org.apache.dubbo.metrics.model.sample.GaugeMetricSample;
import org.apache.dubbo.metrics.model.sample.MetricSample;
import org.apache.dubbo.metrics.registry.RegistryMetricsConstants;
import org.apache.dubbo.metrics.registry.collector.RegistryMetricsCollector;
import org.apache.dubbo.metrics.registry.event.RegistryEvent;
import org.apache.dubbo.rpc.model.ApplicationModel;
@ -222,9 +221,9 @@ public class RegistryMetricsTest {
}
List<MetricSample> samples = collector.collect();
GaugeMetricSample<?> succeedRequests = getSample(MetricsKey.SERVICE_REGISTER_METRIC_REQUESTS_SUCCEED.getNameByType(RegistryMetricsConstants.OP_TYPE_REGISTER_SERVICE.getType()), samples);
GaugeMetricSample<?> failedRequests = getSample(MetricsKey.SERVICE_REGISTER_METRIC_REQUESTS_FAILED.getNameByType(RegistryMetricsConstants.OP_TYPE_REGISTER_SERVICE.getType()), samples);
GaugeMetricSample<?> totalRequests = getSample(MetricsKey.SERVICE_REGISTER_METRIC_REQUESTS.getNameByType(RegistryMetricsConstants.OP_TYPE_REGISTER_SERVICE.getType()), samples);
GaugeMetricSample<?> succeedRequests = getSample(MetricsKey.SERVICE_REGISTER_METRIC_REQUESTS_SUCCEED.getName(), samples);
GaugeMetricSample<?> failedRequests = getSample(MetricsKey.SERVICE_REGISTER_METRIC_REQUESTS_FAILED.getName(), samples);
GaugeMetricSample<?> totalRequests = getSample(MetricsKey.SERVICE_REGISTER_METRIC_REQUESTS.getName(), samples);
Assertions.assertEquals(5L, succeedRequests.applyAsLong());
Assertions.assertEquals(5L, failedRequests.applyAsLong());

View File

@ -40,6 +40,7 @@ import static org.apache.dubbo.common.constants.QosConstants.ACCEPT_FOREIGN_IP;
import static org.apache.dubbo.common.constants.QosConstants.ACCEPT_FOREIGN_IP_WHITELIST;
import static org.apache.dubbo.common.constants.QosConstants.ANONYMOUS_ACCESS_ALLOW_COMMANDS;
import static org.apache.dubbo.common.constants.QosConstants.ANONYMOUS_ACCESS_PERMISSION_LEVEL;
import static org.apache.dubbo.common.constants.QosConstants.QOS_CHECK;
import static org.apache.dubbo.common.constants.QosConstants.QOS_ENABLE;
import static org.apache.dubbo.common.constants.QosConstants.QOS_HOST;
import static org.apache.dubbo.common.constants.QosConstants.QOS_PORT;
@ -131,6 +132,10 @@ public class QosProtocolWrapper implements Protocol, ScopeModelAware {
} catch (Throwable throwable) {
logger.warn(QOS_FAILED_START_SERVER, "", "", "Fail to start qos server: ", throwable);
boolean qosCheck = url.getParameter(QOS_CHECK, false);
if (qosCheck) {
throw new IllegalStateException("Fail to start qos server: " + throwable.getMessage(), throwable);
}
}
}

View File

@ -133,10 +133,8 @@ public class ServiceDiscoveryRegistry extends FailbackRegistry {
boolean should = PROVIDER_SIDE.equals(side); // Only register the Provider.
if (!should) {
if (logger.isDebugEnabled()) {
logger.debug(String.format("The URL[%s] should not be registered.", providerURL));
}
if (!should && logger.isDebugEnabled()) {
logger.debug(String.format("The URL[%s] should not be registered.", providerURL));
}
if (!acceptable(providerURL)) {
@ -394,7 +392,7 @@ public class ServiceDiscoveryRegistry extends FailbackRegistry {
Lock mappingLock = serviceNameMapping.getMappingLock(event.getServiceKey());
try {
mappingLock.lock();
if (CollectionUtils.isEmpty(tempOldApps) && newApps.size() > 0) {
if (CollectionUtils.isEmpty(tempOldApps) && !newApps.isEmpty()) {
serviceNameMapping.putCachedMapping(ServiceNameMapping.buildMappingKey(url), newApps);
subscribeURLs(url, listener, newApps);
oldApps = newApps;

View File

@ -584,7 +584,7 @@ public class ServiceDiscoveryRegistryDirectory<T> extends DynamicDirectory<T> {
}
void addNotifyListener(ServiceDiscoveryRegistryDirectory<?> listener) {
if (listeners.size() == 0) {
if (listeners.isEmpty()) {
this.initWith(moduleModel.getApplicationModel().getApplicationName() + CONFIGURATORS_SUFFIX);
}
this.listeners.add(listener);
@ -592,7 +592,7 @@ public class ServiceDiscoveryRegistryDirectory<T> extends DynamicDirectory<T> {
void removeNotifyListener(ServiceDiscoveryRegistryDirectory<?> listener) {
this.listeners.remove(listener);
if (listeners.size() == 0) {
if (listeners.isEmpty()) {
this.stopListen(moduleModel.getApplicationModel().getApplicationName() + CONFIGURATORS_SUFFIX);
}
}
@ -693,4 +693,12 @@ public class ServiceDiscoveryRegistryDirectory<T> extends DynamicDirectory<T> {
}
}
@Override
public String toString() {
return "ServiceDiscoveryRegistryDirectory(" +
"registry: " + getUrl().getAddress() +
", subscribed key: " + (serviceListener == null || CollectionUtils.isEmpty(serviceListener.getServiceNames())
? getConsumerUrl().getServiceKey() : serviceListener.getServiceNames().toString()) +
")-" + super.toString();
}
}

View File

@ -195,7 +195,7 @@ public abstract class DynamicDirectory<T> extends AbstractDirectory<T> implement
if (forbidden && shouldFailFast) {
// 1. No service provider 2. Service providers are disabled
throw new RpcException(RpcException.FORBIDDEN_EXCEPTION, "No provider available from registry " +
getUrl().getAddress() + " for service " + getConsumerUrl().getServiceKey() + " on consumer " +
this + " for service " + getConsumerUrl().getServiceKey() + " on consumer " +
NetUtils.getLocalHost() + " use dubbo version " + Version.getVersion() +
", please check status of providers(disabled, not registered or in blacklist).");
}

View File

@ -248,8 +248,8 @@ public class HeaderExchangeClient implements ExchangeClient {
return Math.max(leastReconnectDuration, tick);
}
private boolean shouldReconnect(URL url) {
return url.getParameter(Constants.RECONNECT_KEY, true);
protected boolean shouldReconnect(URL url) {
return !Boolean.FALSE.toString().equalsIgnoreCase(url.getParameter(Constants.RECONNECT_KEY));
}
@Override

View File

@ -0,0 +1,40 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.remoting.exchange.support.header;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.remoting.Client;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
public class HeaderExchangeClientTest {
@Test
void testReconnect() {
HeaderExchangeClient headerExchangeClient = new HeaderExchangeClient(Mockito.mock(Client.class), false);
Assertions.assertTrue(headerExchangeClient.shouldReconnect(URL.valueOf("localhost")));
Assertions.assertTrue(headerExchangeClient.shouldReconnect(URL.valueOf("localhost?reconnect=true")));
Assertions.assertTrue(headerExchangeClient.shouldReconnect(URL.valueOf("localhost?reconnect=tRue")));
Assertions.assertTrue(headerExchangeClient.shouldReconnect(URL.valueOf("localhost?reconnect=30000")));
Assertions.assertTrue(headerExchangeClient.shouldReconnect(URL.valueOf("localhost?reconnect=0")));
Assertions.assertTrue(headerExchangeClient.shouldReconnect(URL.valueOf("localhost?reconnect=-1")));
Assertions.assertFalse(headerExchangeClient.shouldReconnect(URL.valueOf("localhost?reconnect=false")));
Assertions.assertFalse(headerExchangeClient.shouldReconnect(URL.valueOf("localhost?reconnect=FALSE")));
}
}

View File

@ -20,6 +20,7 @@ import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.constants.CommonConstants;
import org.apache.dubbo.common.threadlocal.InternalThreadLocalMap;
import org.apache.dubbo.common.threadpool.manager.ExecutorRepository;
import org.apache.dubbo.common.url.component.DubboServiceAddressURL;
import org.apache.dubbo.common.utils.ArrayUtils;
import org.apache.dubbo.common.utils.ExecutorUtil;
import org.apache.dubbo.common.utils.ReflectUtils;
@ -62,6 +63,9 @@ public class InjvmInvoker<T> extends AbstractInvoker<T> {
private final Map<String, Exporter<?>> exporterMap;
private volatile Exporter<?> exporter = null;
private volatile URL consumerUrl = null;
private final ExecutorRepository executorRepository;
private final ParamDeepCopyUtil paramDeepCopyUtil;
@ -92,9 +96,11 @@ public class InjvmInvoker<T> extends AbstractInvoker<T> {
@Override
public Result doInvoke(Invocation invocation) throws Throwable {
Exporter<?> exporter = InjvmProtocol.getExporter(exporterMap, getUrl());
if (exporter == null) {
throw new RpcException("Service [" + key + "] not found.");
exporter = InjvmProtocol.getExporter(exporterMap, getUrl());
if (exporter == null) {
throw new RpcException("Service [" + key + "] not found.");
}
}
// Solve local exposure, the server opens the token, and the client call fails.
Invoker<?> invoker = exporter.getInvoker();
@ -103,8 +109,12 @@ public class InjvmInvoker<T> extends AbstractInvoker<T> {
if (serverHasToken) {
invocation.setAttachment(Constants.TOKEN_KEY, serverURL.getParameter(Constants.TOKEN_KEY));
}
if (consumerUrl == null) {
// no need to sync, multi-objects is acceptable and will be gc-ed.
consumerUrl = new DubboServiceAddressURL(serverURL.getUrlAddress(), serverURL.getUrlParam(), getUrl(), null);
}
int timeout = RpcUtils.calculateTimeout(getUrl(), invocation, RpcUtils.getMethodName(invocation), DEFAULT_TIMEOUT);
int timeout = RpcUtils.calculateTimeout(consumerUrl, invocation, RpcUtils.getMethodName(invocation), DEFAULT_TIMEOUT);
if (timeout <= 0) {
return AsyncRpcResult.newDefaultAsyncResult(new RpcException(RpcException.TIMEOUT_TERMINATE,
"No time left for making the following call: " + invocation.getServiceName() + "."
@ -242,7 +252,7 @@ public class InjvmInvoker<T> extends AbstractInvoker<T> {
if (pts != null && args != null && pts.length == args.length) {
realArgument = new Object[pts.length];
for (int i = 0; i < pts.length; i++) {
realArgument[i] = paramDeepCopyUtil.copy(getUrl(), args[i], pts[i]);
realArgument[i] = paramDeepCopyUtil.copy(consumerUrl, args[i], pts[i]);
}
}
if (realArgument == null) {
@ -273,7 +283,7 @@ public class InjvmInvoker<T> extends AbstractInvoker<T> {
Class<?> returnType = getReturnType(consumerServiceModel, invocation.getMethodName(), desc);
if (returnType != null) {
Thread.currentThread().setContextClassLoader(consumerServiceModel.getClassLoader());
value = paramDeepCopyUtil.copy(getUrl(), originValue, returnType);
value = paramDeepCopyUtil.copy(consumerUrl, originValue, returnType);
}
}
return value;

View File

@ -41,7 +41,7 @@
</modules>
<properties>
<spring-boot.version>2.7.14</spring-boot.version>
<spring-boot.version>2.7.15</spring-boot.version>
<dubbo.version>${revision}</dubbo.version>
<!-- Fix the bug of log4j refer:https://github.com/apache/logging-log4j2/pull/608 -->
<log4j2_version>2.20.0</log4j2_version>