Skip to content

Commit

Permalink
Merge branch 'apache-3.2' into 3.2.5-release
Browse files Browse the repository at this point in the history
  • Loading branch information
AlbumenJ committed Jul 31, 2023
2 parents 30be465 + 1b8688c commit aa54350
Show file tree
Hide file tree
Showing 85 changed files with 952 additions and 691 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ public void checkConnectivity() {
}
}, reconnectTaskPeriod, TimeUnit.MILLISECONDS);
}
MetricsEventBus.publish(RegistryEvent.refreshDirectoryEvent(applicationModel, getSummary()));
MetricsEventBus.publish(RegistryEvent.refreshDirectoryEvent(applicationModel, getSummary(), getDirectoryMeta()));
}

/**
Expand All @@ -366,7 +366,11 @@ public void refreshInvoker() {
if (invokersInitialized) {
refreshInvokerInternal();
}
MetricsEventBus.publish(RegistryEvent.refreshDirectoryEvent(applicationModel, getSummary()));
MetricsEventBus.publish(RegistryEvent.refreshDirectoryEvent(applicationModel, getSummary(), getDirectoryMeta()));
}

protected Map<String, String> getDirectoryMeta() {
return Collections.emptyMap();
}

private synchronized void refreshInvokerInternal() {
Expand Down Expand Up @@ -395,7 +399,7 @@ public void addDisabledInvoker(Invoker<T> invoker) {
removeValidInvoker(invoker);
logger.info("Disable service address: " + invoker.getUrl() + ".");
}
MetricsEventBus.publish(RegistryEvent.refreshDirectoryEvent(applicationModel, getSummary()));
MetricsEventBus.publish(RegistryEvent.refreshDirectoryEvent(applicationModel, getSummary(), getDirectoryMeta()));
}

@Override
Expand All @@ -408,7 +412,7 @@ public void recoverDisabledInvoker(Invoker<T> invoker) {

}
}
MetricsEventBus.publish(RegistryEvent.refreshDirectoryEvent(applicationModel, getSummary()));
MetricsEventBus.publish(RegistryEvent.refreshDirectoryEvent(applicationModel, getSummary(), getDirectoryMeta()));
}

protected final void refreshRouter(BitList<Invoker<T>> newlyInvokers, Runnable switchAction) {
Expand Down Expand Up @@ -465,7 +469,7 @@ protected void setInvokers(BitList<Invoker<T>> invokers) {
refreshInvokerInternal();
this.invokersInitialized = true;

MetricsEventBus.publish(RegistryEvent.refreshDirectoryEvent(applicationModel, getSummary()));
MetricsEventBus.publish(RegistryEvent.refreshDirectoryEvent(applicationModel, getSummary(), getDirectoryMeta()));
}

protected void destroyInvokers() {
Expand All @@ -480,7 +484,7 @@ private boolean addValidInvoker(Invoker<T> invoker) {
synchronized (this.validInvokers) {
result = this.validInvokers.add(invoker);
}
MetricsEventBus.publish(RegistryEvent.refreshDirectoryEvent(applicationModel, getSummary()));
MetricsEventBus.publish(RegistryEvent.refreshDirectoryEvent(applicationModel, getSummary(), getDirectoryMeta()));
return result;
}

Expand All @@ -489,7 +493,7 @@ private boolean removeValidInvoker(Invoker<T> invoker) {
synchronized (this.validInvokers) {
result = this.validInvokers.remove(invoker);
}
MetricsEventBus.publish(RegistryEvent.refreshDirectoryEvent(applicationModel, getSummary()));
MetricsEventBus.publish(RegistryEvent.refreshDirectoryEvent(applicationModel, getSummary(), getDirectoryMeta()));
return result;
}

Expand Down Expand Up @@ -519,18 +523,7 @@ private Map<MetricsKey, Map<String, Integer>> getSummary() {
}

private Map<String, Integer> groupByServiceKey(Collection<Invoker<T>> invokers) {

Map<String, Integer> serviceNumMap = new HashMap<>();
for (Invoker<T> invoker : invokers) {
if (invoker.getClass().getSimpleName().contains("Mockito")) {
return serviceNumMap;
}
}
if (invokers.size() > 0) {
serviceNumMap = invokers.stream().filter(invoker -> invoker.getInterface() != null).collect(Collectors.groupingBy(invoker -> invoker.getInterface().getName(), Collectors.reducing(0, e -> 1, Integer::sum)));
}

return serviceNumMap;
return Collections.singletonMap(getConsumerUrl().getServiceKey(), invokers.size());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,12 @@
import org.apache.dubbo.rpc.cluster.SingleRouterChain;
import org.apache.dubbo.rpc.cluster.router.state.BitList;

import java.util.Collections;
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.REGISTRY_KEY;

/**
* StaticDirectory
Expand Down Expand Up @@ -125,4 +128,8 @@ protected List<Invoker<T>> doList(SingleRouterChain<T> singleRouterChain, BitLis
return invokers;
}

@Override
protected Map<String, String> getDirectoryMeta() {
return Collections.singletonMap(REGISTRY_KEY, "static");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import org.apache.dubbo.metrics.collector.DefaultMetricsCollector;
import org.apache.dubbo.metrics.event.MetricsDispatcher;
import org.apache.dubbo.metrics.event.MetricsEventBus;
import org.apache.dubbo.metrics.event.RequestBeforeEvent;
import org.apache.dubbo.metrics.event.RequestEvent;
import org.apache.dubbo.rpc.BaseFilter;
import org.apache.dubbo.rpc.Invocation;
import org.apache.dubbo.rpc.Invoker;
Expand Down Expand Up @@ -73,7 +73,7 @@ private void handleMethodException(Throwable t, Invocation invocation) {
if (t instanceof RpcException) {
RpcException e = (RpcException) t;
if (e.isForbidden()) {
MetricsEventBus.publish(RequestBeforeEvent.toEvent(applicationModel, appName, metricsDispatcher, invocation, CONSUMER_SIDE));
MetricsEventBus.publish(RequestEvent.toRequestErrorEvent(applicationModel, appName, metricsDispatcher, invocation, CONSUMER_SIDE, e.getCode()));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,8 @@ public interface CommonConstants {

String INTERFACE_REGISTER_MODE = "interface";

String INSTANCE_REGISTER_MODE = "instance";

String DEFAULT_REGISTER_MODE = "all";

String GENERIC_KEY = "generic";
Expand Down Expand Up @@ -642,4 +644,5 @@ public interface CommonConstants {
String SERVICE_DEPLOYER_ATTRIBUTE_KEY = "serviceDeployer";
String RESTEASY_NETTY_HTTP_REQUEST_ATTRIBUTE_KEY = "resteasyNettyHttpRequest";

String DUBBO_MANUAL_REGISTER_KEY = "dubbo.application.manual-register";
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.apache.dubbo.common.logger.LoggerAdapter;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.core.config.Configurator;

import java.io.File;

Expand All @@ -30,6 +31,12 @@ public class Log4j2LoggerAdapter implements LoggerAdapter {
private Level level;

public Log4j2LoggerAdapter() {
try {
org.apache.logging.log4j.Logger logger = LogManager.getRootLogger();
this.level = fromLog4j2Level(logger.getLevel());
} catch (Exception t) {
// ignore
}
}

private static org.apache.logging.log4j.Level toLog4j2Level(Level level) {
Expand Down Expand Up @@ -94,6 +101,7 @@ public Level getLevel() {
@Override
public void setLevel(Level level) {
this.level = level;
Configurator.setLevel(LogManager.getRootLogger(), toLog4j2Level(level));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
package org.apache.dubbo.common.logger.slf4j;

import org.apache.dubbo.common.logger.Level;
import org.apache.dubbo.common.logger.Logger;
import org.apache.dubbo.common.logger.support.FailsafeLogger;

Expand Down Expand Up @@ -198,4 +199,27 @@ public boolean isErrorEnabled() {
return logger.isErrorEnabled();
}

public static Level getLevel(org.slf4j.Logger logger) {
if (logger.isTraceEnabled()) {
return Level.TRACE;
}
if (logger.isDebugEnabled()) {
return Level.DEBUG;
}
if (logger.isInfoEnabled()) {
return Level.INFO;
}
if (logger.isWarnEnabled()) {
return Level.WARN;
}
if (logger.isErrorEnabled()) {
return Level.ERROR;
}
return Level.OFF;
}

public Level getLevel() {
return getLevel(logger);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,21 @@
import org.apache.dubbo.common.logger.Logger;
import org.apache.dubbo.common.logger.LoggerAdapter;
import org.apache.dubbo.common.utils.ClassUtils;

import org.slf4j.LoggerFactory;
import java.io.File;

public class Slf4jLoggerAdapter implements LoggerAdapter {
public static final String NAME = "slf4j";

private Level level;
private File file;

private static final org.slf4j.Logger ROOT_LOGGER = LoggerFactory.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME);

public Slf4jLoggerAdapter() {
this.level = Slf4jLogger.getLevel(ROOT_LOGGER);
}

@Override
public Logger getLogger(String key) {
return new Slf4jLogger(org.slf4j.LoggerFactory.getLogger(key));
Expand All @@ -45,6 +52,7 @@ public Level getLevel() {

@Override
public void setLevel(Level level) {
System.err.printf("The level of slf4j logger current can not be set, using the default level: %s \n", Slf4jLogger.getLevel(ROOT_LOGGER));
this.level = level;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@
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.registry.event.RegistryEvent;
import org.apache.dubbo.registry.client.metadata.MetadataUtils;
import org.apache.dubbo.rpc.Exporter;
import org.apache.dubbo.rpc.Invoker;
Expand Down Expand Up @@ -310,7 +308,9 @@ public void export(RegisterTypeEnum registerType) {
if (shouldDelay()) {
// should register if delay export
doDelayExport();
} else if (Integer.valueOf(-1).equals(getDelay())) {
} else if (Integer.valueOf(-1).equals(getDelay()) &&
Boolean.parseBoolean(ConfigurationUtils.getProperty(
getScopeModel(), CommonConstants.DUBBO_MANUAL_REGISTER_KEY, "false"))) {
// should not register by default
doExport(RegisterTypeEnum.MANUAL_REGISTER);
} else {
Expand Down Expand Up @@ -514,21 +514,17 @@ private void doExportUrls(RegisterTypeEnum registerType) {

List<URL> registryURLs = ConfigValidationUtils.loadRegistries(this, true);

MetricsEventBus.post(RegistryEvent.toRsEvent(getApplicationModel(), getUniqueServiceName(), protocols.size() * registryURLs.size()), () -> {
for (ProtocolConfig protocolConfig : protocols) {
String pathKey = URL.buildKey(getContextPath(protocolConfig)
.map(p -> p + "/" + path)
.orElse(path), group, version);
// stub service will use generated service name
if (!serverService) {
// In case user specified path, registerImmediately service one more time to map it to path.
repository.registerService(pathKey, interfaceClass);
}
doExportUrlsFor1Protocol(protocolConfig, registryURLs, registerType);
}
return null;
for (ProtocolConfig protocolConfig : protocols) {
String pathKey = URL.buildKey(getContextPath(protocolConfig)
.map(p -> p + "/" + path)
.orElse(path), group, version);
// stub service will use generated service name
if (!serverService) {
// In case user specified path, register service one more time to map it to path.
repository.registerService(pathKey, interfaceClass);
}
);
doExportUrlsFor1Protocol(protocolConfig, registryURLs, registerType);
}

providerModel.setServiceUrls(urls);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
import org.apache.dubbo.metrics.collector.DefaultMetricsCollector;
import org.apache.dubbo.metrics.config.event.ConfigCenterEvent;
import org.apache.dubbo.metrics.event.MetricsEventBus;
import org.apache.dubbo.metrics.registry.event.RegistryEvent;
import org.apache.dubbo.metrics.report.DefaultMetricsReporterFactory;
import org.apache.dubbo.metrics.report.MetricsReporter;
import org.apache.dubbo.metrics.report.MetricsReporterFactory;
Expand Down Expand Up @@ -899,16 +898,10 @@ private DynamicConfiguration getDynamicConfiguration(URL connectionURL) {
private void registerServiceInstance() {
try {
registered = true;
MetricsEventBus.post(RegistryEvent.toRegisterEvent(applicationModel),
() -> {
ServiceInstanceMetadataUtils.registerMetadataAndInstance(applicationModel);
return null;
}
);
ServiceInstanceMetadataUtils.registerMetadataAndInstance(applicationModel);
} catch (Exception e) {
logger.error(CONFIG_REGISTER_INSTANCE_ERROR, "configuration server disconnected", "", "Register instance error.", e);
}

if (registered) {
// scheduled task for updating Metadata and ServiceInstance
asyncMetadataFuture = frameworkExecutorRepository.getSharedScheduledExecutor().scheduleWithFixedDelay(() -> {
Expand Down
2 changes: 1 addition & 1 deletion dubbo-config/dubbo-config-spring/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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.13</spring-boot.version>
<spring-boot.version>2.7.14</spring-boot.version>
<!-- Uncomment spring_version property to check Spring 4.x compatibility -->
<!-- <spring_version>4.3.30.RELEASE</spring_version> -->
</properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory)
// Extract dubbo props from Spring env and put them to app config
ConfigurableEnvironment environment = (ConfigurableEnvironment) applicationContext.getEnvironment();
SortedMap<String, String> dubboProperties = EnvironmentUtils.filterDubboProperties(environment);
applicationModel.modelEnvironment().setAppConfigMap(dubboProperties);
applicationModel.modelEnvironment().getAppConfigMap().putAll(dubboProperties);

// register ConfigManager singleton
beanFactory.registerSingleton(ConfigManager.BEAN_NAME, applicationModel.getApplicationConfigManager());
Expand Down
2 changes: 1 addition & 1 deletion dubbo-demo/dubbo-demo-annotation/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

<properties>
<skip_maven_deploy>true</skip_maven_deploy>
<spring-boot-maven-plugin.version>2.7.13</spring-boot-maven-plugin.version>
<spring-boot-maven-plugin.version>2.7.14</spring-boot-maven-plugin.version>
</properties>

<modules>
Expand Down
2 changes: 1 addition & 1 deletion dubbo-demo/dubbo-demo-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

<properties>
<skip_maven_deploy>true</skip_maven_deploy>
<spring-boot-maven-plugin.version>2.7.13</spring-boot-maven-plugin.version>
<spring-boot-maven-plugin.version>2.7.14</spring-boot-maven-plugin.version>
</properties>

<artifactId>dubbo-demo-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.13</spring-boot.version>
<spring-boot.version>2.7.14</spring-boot.version>
<skip_maven_deploy>true</skip_maven_deploy>
</properties>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.13</spring-boot.version>
<spring-boot.version>2.7.14</spring-boot.version>
<skip_maven_deploy>true</skip_maven_deploy>
</properties>

Expand Down
6 changes: 3 additions & 3 deletions dubbo-demo/dubbo-demo-spring-boot/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@
<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.13</spring-boot.version>
<spring-boot-maven-plugin.version>2.7.13</spring-boot-maven-plugin.version>
<micrometer-core.version>1.11.1</micrometer-core.version>
<spring-boot.version>2.7.14</spring-boot.version>
<spring-boot-maven-plugin.version>2.7.14</spring-boot-maven-plugin.version>
<micrometer-core.version>1.11.2</micrometer-core.version>
</properties>
<dependencyManagement>
<dependencies>
Expand Down
2 changes: 1 addition & 1 deletion dubbo-demo/dubbo-demo-xml/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

<properties>
<skip_maven_deploy>true</skip_maven_deploy>
<spring-boot-maven-plugin.version>2.7.13</spring-boot-maven-plugin.version>
<spring-boot-maven-plugin.version>2.7.14</spring-boot-maven-plugin.version>
</properties>

<modules>
Expand Down

0 comments on commit aa54350

Please sign in to comment.