This is an automated email from the ASF dual-hosted git repository. albumenj pushed a commit to branch 3.3 in repository https://gitbox.apache.org/repos/asf/dubbo.git
commit 3ed2dacbef79dae8f13a3c50f5ffb39bfe386bbc Merge: 8009c72030 031da7b8ed Author: Albumen Kevin <[email protected]> AuthorDate: Mon Sep 11 17:16:07 2023 +0800 Merge branch 'apache-3.2' into apache-3.3 # Conflicts: # dubbo-common/src/main/java/org/apache/dubbo/common/constants/CommonConstants.java # dubbo-common/src/main/java/org/apache/dubbo/config/MetricsConfig.java # dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/ReferenceBean.java # dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/beans/factory/annotation/ServiceAnnotationPostProcessor.java # dubbo-dependencies-bom/pom.xml # dubbo-dependencies/dubbo-dependencies-zookeeper-curator5/pom.xml # dubbo-dependencies/dubbo-dependencies-zookeeper/pom.xml # dubbo-metrics/dubbo-metrics-default/src/main/java/org/apache/dubbo/metrics/collector/DefaultMetricsCollector.java # dubbo-remoting/dubbo-remoting-netty4/src/main/java/org/apache/dubbo/remoting/transport/netty4/NettyServer.java # pom.xml .../rpc/cluster/directory/AbstractDirectory.java | 1 + .../dubbo/common/constants/CommonConstants.java | 2 +- .../dubbo/common/constants/MetricsConstants.java | 8 ++-- .../dubbo/common/logger/ErrorTypeAwareLogger.java | 15 +++++++ .../org/apache/dubbo/config/AbstractConfig.java | 36 ++++++++++++----- .../org/apache/dubbo/config/MetricsConfig.java | 26 ++++++++++++ .../org/apache/dubbo/config/ReferenceConfig.java | 9 ++++- .../org/apache/dubbo/config/ServiceConfig.java | 9 ++++- .../config/deploy/DefaultApplicationDeployer.java | 1 + dubbo-config/dubbo-config-spring/pom.xml | 2 +- .../apache/dubbo/config/spring/ReferenceBean.java | 11 ++++- .../annotation/ServiceAnnotationPostProcessor.java | 2 +- .../context/DubboConfigApplicationListener.java | 25 +++++++----- .../spring/reference/ReferenceBeanManager.java | 2 +- .../META-INF/isolation/dubbo-provider.xml | 2 +- dubbo-dependencies-bom/pom.xml | 6 +-- .../collector/AggregateMetricsCollector.java | 14 +++++-- .../metrics/collector/DefaultMetricsCollector.java | 13 ++++++ .../metrics/report/AbstractMetricsReporter.java | 18 +++++---- .../dubbo/qos/protocol/QosProtocolWrapper.java | 12 ++++-- .../apache/dubbo/qos/server/QosBindException.java | 28 ++++--------- .../java/org/apache/dubbo/qos/server/Server.java | 20 +++++---- .../java/org/apache/dubbo/remoting/Constants.java | 4 ++ .../http/restclient/HttpClientRestClient.java | 3 +- .../netty4/NettyPortUnificationServer.java | 47 +++++++++++++--------- .../remoting/transport/netty4/NettyServer.java | 29 ++++++++----- .../remoting/transport/netty4/ConnectionTest.java | 6 +-- .../netty4/PortUnificationServerTest.java | 5 +-- .../MultiplexProtocolConnectionManagerTest.java | 7 ++-- .../api/SingleProtocolConnectionManagerTest.java | 3 +- .../rest/extension/resteasy/ResteasyContext.java | 4 +- .../ResteasyRequestContainerFilterAdapter.java | 5 +-- .../ResteasyResponseContainerFilterAdapter.java | 2 +- .../ResteasyWriterInterceptorAdapter.java | 5 +-- .../rest/filter/ServiceInvokeRestFilter.java | 24 ++++++----- .../rest/filter/context/FilterContext.java | 4 ++ .../rest/filter/context/RestFilterContext.java | 23 +++++++++++ .../protocol/rest/handler/NettyHttpHandler.java | 14 +++---- .../rpc/protocol/rest/JaxrsRestProtocolTest.java | 23 ++++++++++- .../rest/filter/TraceRequestAndResponseFilter.java | 47 ++++++++++++++++++++++ .../dubbo/rpc/protocol/tri/TripleInvoker.java | 3 +- dubbo-spring-boot/pom.xml | 2 +- pom.xml | 2 +- 43 files changed, 369 insertions(+), 155 deletions(-) diff --cc dubbo-common/src/main/java/org/apache/dubbo/common/constants/CommonConstants.java index 3380621774,03b93bbce3..c3aea739ee --- a/dubbo-common/src/main/java/org/apache/dubbo/common/constants/CommonConstants.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/constants/CommonConstants.java @@@ -639,11 -643,5 +639,11 @@@ public interface CommonConstants String DUBBO_PACKABLE_METHOD_FACTORY = "dubbo.application.parameters." + PACKABLE_METHOD_FACTORY_KEY; + String DUBBO_TAG_HEADER = "dubbo-tag"; + + String REST_SERVICE_DEPLOYER_URL_ATTRIBUTE_KEY = "restServiceDeployerAttributeKey"; + - String SERVICE_DEPLOYER_ATTRIBUTE_KEY = "serviceDeployer"; String RESTEASY_NETTY_HTTP_REQUEST_ATTRIBUTE_KEY = "resteasyNettyHttpRequest"; ++ String SERVICE_DEPLOYER_ATTRIBUTE_KEY = "serviceDeployer"; + String DUBBO_MANUAL_REGISTER_KEY = "dubbo.application.manual-register"; } diff --cc dubbo-common/src/main/java/org/apache/dubbo/common/constants/MetricsConstants.java index 49bd9665c7,4c4437d427..53e377f9f9 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/constants/MetricsConstants.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/constants/MetricsConstants.java @@@ -40,17 -40,17 +40,19 @@@ public interface MetricsConstants String TAG_VERSION_KEY = "version"; String TAG_APPLICATION_VERSION_KEY = "application.version"; - + String TAG_KEY_KEY = "key"; - + String TAG_CONFIG_CENTER = "config.center"; - + String TAG_CHANGE_TYPE = "change.type"; + String TAG_ERROR_CODE = "error"; + String ENABLE_JVM_METRICS_KEY = "enable.jvm"; + String ENABLE_COLLECTOR_SYNC_KEY = "enable.collector.sync"; + String AGGREGATION_COLLECTOR_KEY = "aggregation"; String AGGREGATION_ENABLED_KEY = "aggregation.enabled"; diff --cc dubbo-common/src/main/java/org/apache/dubbo/config/MetricsConfig.java index 37cd727f4c,129391af72..3faa74f012 --- a/dubbo-common/src/main/java/org/apache/dubbo/config/MetricsConfig.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/config/MetricsConfig.java @@@ -61,11 -61,16 +61,21 @@@ public class MetricsConfig extends Abst */ private Boolean exportMetricsService; + /** + * Enable netty metrics. + */ + private Boolean enableNetty; + + /** + * Enable metrics init. + */ + private Boolean enableMetricsInit; + + /** + * Enable collector sync. + */ + private Boolean enableCollectorSync; + /** * @deprecated After metrics config is refactored. * This parameter should no longer use and will be deleted in the future. diff --cc dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/ReferenceBean.java index edad8afd0e,30790d3fd8..28d0ef0973 --- a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/ReferenceBean.java +++ b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/ReferenceBean.java @@@ -24,7 -24,7 +24,8 @@@ import org.apache.dubbo.common.utils.As import org.apache.dubbo.common.utils.ClassUtils; import org.apache.dubbo.common.utils.StringUtils; import org.apache.dubbo.config.ReferenceConfig; +import org.apache.dubbo.config.spring.aot.AotWithSpringDetector; + import org.apache.dubbo.config.spring.context.DubboConfigApplicationListener; import org.apache.dubbo.config.spring.context.DubboConfigBeanInitializer; import org.apache.dubbo.config.spring.reference.ReferenceAttributes; import org.apache.dubbo.config.spring.reference.ReferenceBeanManager; @@@ -143,8 -145,11 +145,11 @@@ public class ReferenceBean<T> implement //actual reference config private ReferenceConfig referenceConfig; + // ReferenceBeanManager + private ReferenceBeanManager referenceBeanManager; + // Registration sources of this reference, may be xml file or annotation location - private List<Map<String,Object>> sources = new ArrayList<>(); + private List<Map<String, Object>> sources = new ArrayList<>(); public ReferenceBean() { super(); diff --cc dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/beans/factory/annotation/ServiceAnnotationPostProcessor.java index 43f1ae5a19,279e1c1903..87f1e74f1f --- a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/beans/factory/annotation/ServiceAnnotationPostProcessor.java +++ b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/beans/factory/annotation/ServiceAnnotationPostProcessor.java @@@ -238,8 -239,8 +238,8 @@@ public class ServiceAnnotationPostProce } } else { if (logger.isWarnEnabled()) { - logger.warn(CONFIG_NO_ANNOTATIONS_FOUND, "No annotations were found on the class", "", "No class annotated by Dubbo @Service was found under package [" - logger.warn(CONFIG_NO_ANNOTATIONS_FOUND,"No annotations were found on the class","","No class annotated by Dubbo @DubboService or @Service was found under package [" - + packageToScan + "], ignore re-scanned classes: " + scanExcludeFilter.getExcludedCount()); ++ logger.warn(CONFIG_NO_ANNOTATIONS_FOUND, "No annotations were found on the class", "", "No class annotated by Dubbo @DubboService or @Service was found under package [" + + packageToScan + "], ignore re-scanned classes: " + scanExcludeFilter.getExcludedCount()); } } diff --cc dubbo-metrics/dubbo-metrics-default/src/main/java/org/apache/dubbo/metrics/collector/DefaultMetricsCollector.java index 65f40b5185,9d04633260..7f2d502a86 --- a/dubbo-metrics/dubbo-metrics-default/src/main/java/org/apache/dubbo/metrics/collector/DefaultMetricsCollector.java +++ b/dubbo-metrics/dubbo-metrics-default/src/main/java/org/apache/dubbo/metrics/collector/DefaultMetricsCollector.java @@@ -62,14 -61,11 +62,16 @@@ public class DefaultMetricsCollector ex private volatile boolean threadpoolCollectEnabled = false; + private volatile boolean metricsInitEnabled = true; + private final ThreadPoolMetricsSampler threadPoolSampler = new ThreadPoolMetricsSampler(this); + + private final ErrorCodeSampler errorCodeSampler; + private String applicationName; + private final ApplicationModel applicationModel; + private final List<MetricsSampler> samplers = new ArrayList<>(); private final List<MetricsCollector> collectors = new ArrayList<>(); diff --cc dubbo-remoting/dubbo-remoting-netty4/src/main/java/org/apache/dubbo/remoting/transport/netty4/NettyServer.java index 6acf226391,1c0c7da3a9..d165651858 --- a/dubbo-remoting/dubbo-remoting-netty4/src/main/java/org/apache/dubbo/remoting/transport/netty4/NettyServer.java +++ b/dubbo-remoting/dubbo-remoting-netty4/src/main/java/org/apache/dubbo/remoting/transport/netty4/NettyServer.java @@@ -111,30 -105,14 +111,35 @@@ public class NettyServer extends Abstra initServerBootstrap(nettyServerHandler); // bind - ChannelFuture channelFuture = bootstrap.bind(getBindAddress()); - channelFuture.syncUninterruptibly(); - channel = channelFuture.channel(); + try { + ChannelFuture channelFuture = bootstrap.bind(getBindAddress()); + channelFuture.syncUninterruptibly(); + channel = channelFuture.channel(); + } catch (Throwable t) { + closeBootstrap(); + throw t; + } + + // metrics + if (isSupportMetrics()) { + ApplicationModel applicationModel = ApplicationModel.defaultModel(); + MetricsEventBus.post(NettyEvent.toNettyEvent(applicationModel), () -> { + Map<String, Long> dataMap = new HashMap<>(); + dataMap.put(MetricsKey.NETTY_ALLOCATOR_HEAP_MEMORY_USED.getName(), PooledByteBufAllocator.DEFAULT.metric().usedHeapMemory()); + dataMap.put(MetricsKey.NETTY_ALLOCATOR_DIRECT_MEMORY_USED.getName(), PooledByteBufAllocator.DEFAULT.metric().usedDirectMemory()); + dataMap.put(MetricsKey.NETTY_ALLOCATOR_HEAP_ARENAS_NUM.getName(), (long) PooledByteBufAllocator.DEFAULT.numHeapArenas()); + dataMap.put(MetricsKey.NETTY_ALLOCATOR_DIRECT_ARENAS_NUM.getName(), (long) PooledByteBufAllocator.DEFAULT.numDirectArenas()); + dataMap.put(MetricsKey.NETTY_ALLOCATOR_NORMAL_CACHE_SIZE.getName(), (long) PooledByteBufAllocator.DEFAULT.normalCacheSize()); + dataMap.put(MetricsKey.NETTY_ALLOCATOR_SMALL_CACHE_SIZE.getName(), (long) PooledByteBufAllocator.DEFAULT.smallCacheSize()); + dataMap.put(MetricsKey.NETTY_ALLOCATOR_THREAD_LOCAL_CACHES_NUM.getName(), (long) PooledByteBufAllocator.DEFAULT.numThreadLocalCaches()); + dataMap.put(MetricsKey.NETTY_ALLOCATOR_CHUNK_SIZE.getName(), (long) PooledByteBufAllocator.DEFAULT.chunkSize()); + return dataMap; + }); + } + } + + private boolean isSupportMetrics() { + return ClassUtils.isPresent("io.netty.buffer.PooledByteBufAllocatorMetric", NettyServer.class.getClassLoader()); } protected EventLoopGroup createBossGroup() {
