From ee87c8d5c2671a36a2af30d71040804f4a2c87f9 Mon Sep 17 00:00:00 2001 From: Albumen Kevin Date: Mon, 12 Jun 2023 22:27:07 +0800 Subject: [PATCH 01/32] Revert "Bump fabric8_kubernetes_version from 6.6.2 to 6.7.1 (#12500)" (#12510) This reverts commit a01ac38cbf24bbeef62fe3289fe1e40b4ac0e92f. --- dubbo-dependencies-bom/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dubbo-dependencies-bom/pom.xml b/dubbo-dependencies-bom/pom.xml index fe221c4865..446cbae787 100644 --- a/dubbo-dependencies-bom/pom.xml +++ b/dubbo-dependencies-bom/pom.xml @@ -167,7 +167,7 @@ 1.10.18 - 6.7.1 + 6.6.2 1.0.11 From 83b4114a9fc81bddaae6e120da33ebef29a6d44e Mon Sep 17 00:00:00 2001 From: Albumen Kevin Date: Tue, 13 Jun 2023 08:35:20 +0800 Subject: [PATCH 02/32] Fix ServiceConfig Ref unable to toString (#12511) --- .../dubbo/common/utils/ToStringUtils.java | 63 +++++++++++++++++++ .../apache/dubbo/config/AbstractConfig.java | 3 +- .../dubbo/config/ServiceConfigTest.java | 16 +++++ 3 files changed, 81 insertions(+), 1 deletion(-) diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/utils/ToStringUtils.java b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/ToStringUtils.java index d405703098..507146736a 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/utils/ToStringUtils.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/ToStringUtils.java @@ -16,7 +16,11 @@ */ package org.apache.dubbo.common.utils; +import org.apache.dubbo.config.AbstractConfig; + import java.util.Arrays; +import java.util.List; +import java.util.Map; public class ToStringUtils { @@ -36,4 +40,63 @@ public class ToStringUtils { return obj.toString(); } } + + public static String toString(Object obj) { + if (obj == null) { + return "null"; + } + if (ClassUtils.isSimpleType(obj.getClass())) { + return obj.toString(); + } + if (obj.getClass().isPrimitive()) { + return obj.toString(); + } + if (obj instanceof Object[]) { + StringBuilder stringBuilder = new StringBuilder(); + stringBuilder.append("["); + Object[] objects = (Object[]) obj; + for (int i = 0; i < objects.length; i++) { + stringBuilder.append(toString(objects[i])); + if (i != objects.length - 1) { + stringBuilder.append(", "); + } + } + stringBuilder.append("]"); + return stringBuilder.toString(); + } + if (obj instanceof List) { + StringBuilder stringBuilder = new StringBuilder(); + stringBuilder.append("["); + List list = (List) obj; + for (int i = 0; i < list.size(); i++) { + stringBuilder.append(toString(list.get(i))); + if (i != list.size() - 1) { + stringBuilder.append(", "); + } + } + stringBuilder.append("]"); + return stringBuilder.toString(); + } + if (obj instanceof Map) { + StringBuilder stringBuilder = new StringBuilder(); + stringBuilder.append("{"); + Map map = (Map) obj; + int i = 0; + for (Object key : map.keySet()) { + stringBuilder.append(toString(key)); + stringBuilder.append("="); + stringBuilder.append(toString(map.get(key))); + if (i != map.size() - 1) { + stringBuilder.append(", "); + } + i++; + } + stringBuilder.append("}"); + return stringBuilder.toString(); + } + if (obj instanceof AbstractConfig) { + return obj.toString(); + } + return obj.getClass() + "@" + Integer.toHexString(System.identityHashCode(obj)); + } } diff --git a/dubbo-common/src/main/java/org/apache/dubbo/config/AbstractConfig.java b/dubbo-common/src/main/java/org/apache/dubbo/config/AbstractConfig.java index 6247a02bd4..3e4daf34bc 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/config/AbstractConfig.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/config/AbstractConfig.java @@ -31,6 +31,7 @@ import org.apache.dubbo.common.utils.FieldUtils; import org.apache.dubbo.common.utils.MethodUtils; import org.apache.dubbo.common.utils.ReflectUtils; import org.apache.dubbo.common.utils.StringUtils; +import org.apache.dubbo.common.utils.ToStringUtils; import org.apache.dubbo.config.context.ConfigManager; import org.apache.dubbo.config.context.ConfigMode; import org.apache.dubbo.config.support.Nested; @@ -967,7 +968,7 @@ public abstract class AbstractConfig implements Serializable { buf.append(' '); buf.append(key); buf.append("=\""); - buf.append(key.equals("password") ? "******" : value); + buf.append(key.equals("password") ? "******" : ToStringUtils.toString(value)); buf.append('\"'); } } catch (Exception e) { diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/ServiceConfigTest.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/ServiceConfigTest.java index d65f110843..fe5a0ad643 100644 --- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/ServiceConfigTest.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/ServiceConfigTest.java @@ -683,4 +683,20 @@ class ServiceConfigTest { scheduledExecutorService.shutdown(); } + + @Test + void testToString() { + ServiceConfig serviceConfig = new ServiceConfig<>(); + service.setRef(new DemoServiceImpl() { + @Override + public String toString() { + throw new IllegalStateException(); + } + }); + try { + serviceConfig.toString(); + } catch (Throwable t) { + Assertions.fail(t); + } + } } From e6e68f6b8486ecc81973ad1a8b90b874c85086fe Mon Sep 17 00:00:00 2001 From: Albumen Kevin Date: Tue, 13 Jun 2023 10:27:38 +0800 Subject: [PATCH 03/32] Fix channel close event cause hanging thread (#12503) * Fix channel close event cause hanging thread * Fix check * fix npe * fix ut * fix check * fix uts * fix testing --- .../common/threadpool/ThreadlessExecutor.java | 39 +++++++++++-------- .../exchange/support/DefaultFuture.java | 12 +++++- .../exchange/support/DefaultFutureTest.java | 12 +++++- .../org/apache/dubbo/rpc/AsyncRpcResult.java | 4 +- 4 files changed, 47 insertions(+), 20 deletions(-) diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/threadpool/ThreadlessExecutor.java b/dubbo-common/src/main/java/org/apache/dubbo/common/threadpool/ThreadlessExecutor.java index 23ef3cf235..5ff664bc0b 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/threadpool/ThreadlessExecutor.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/threadpool/ThreadlessExecutor.java @@ -26,6 +26,7 @@ import java.util.concurrent.AbstractExecutorService; import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.RejectedExecutionException; import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.locks.LockSupport; /** @@ -46,7 +47,7 @@ public class ThreadlessExecutor extends AbstractExecutorService { /** * Wait thread. It must be visible to other threads and does not need to be thread-safe */ - private volatile Object waiter; + private final AtomicReference waiter = new AtomicReference<>(); /** * Waits until there is a task, executes the task and all queued tasks (if there're any). The task is either a normal @@ -56,22 +57,25 @@ public class ThreadlessExecutor extends AbstractExecutorService { throwIfInterrupted(); Runnable runnable = queue.poll(); if (runnable == null) { - waiter = Thread.currentThread(); - try { - while ((runnable = queue.poll()) == null) { - long restTime = deadline - System.nanoTime(); - if (restTime <= 0) { - return; + if (waiter.compareAndSet(null, Thread.currentThread())) { + try { + while ((runnable = queue.poll()) == null && waiter.get() == Thread.currentThread()) { + long restTime = deadline - System.nanoTime(); + if (restTime <= 0) { + return; + } + LockSupport.parkNanos(this, restTime); + throwIfInterrupted(); } - LockSupport.parkNanos(this, restTime); - throwIfInterrupted(); + } finally { + waiter.compareAndSet(Thread.currentThread(), null); } - } finally { - waiter = null; } } do { - runnable.run(); + if (runnable != null) { + runnable.run(); + } } while ((runnable = queue.poll()) != null); } @@ -91,8 +95,8 @@ public class ThreadlessExecutor extends AbstractExecutorService { public void execute(Runnable runnable) { RunnableWrapper run = new RunnableWrapper(runnable); queue.add(run); - if (waiter != SHUTDOWN) { - LockSupport.unpark((Thread) waiter); + if (waiter.get() != SHUTDOWN) { + LockSupport.unpark((Thread) waiter.get()); } else if (queue.remove(run)) { throw new RejectedExecutionException(); } @@ -109,7 +113,10 @@ public class ThreadlessExecutor extends AbstractExecutorService { @Override public List shutdownNow() { - waiter = SHUTDOWN; + if (waiter.get() != SHUTDOWN) { + LockSupport.unpark((Thread) waiter.get()); + } + waiter.set(SHUTDOWN); Runnable runnable; while ((runnable = queue.poll()) != null) { runnable.run(); @@ -119,7 +126,7 @@ public class ThreadlessExecutor extends AbstractExecutorService { @Override public boolean isShutdown() { - return waiter == SHUTDOWN; + return waiter.get() == SHUTDOWN; } @Override diff --git a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/exchange/support/DefaultFuture.java b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/exchange/support/DefaultFuture.java index 3539723adb..f49ef15867 100644 --- a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/exchange/support/DefaultFuture.java +++ b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/exchange/support/DefaultFuture.java @@ -20,6 +20,7 @@ import org.apache.dubbo.common.logger.ErrorTypeAwareLogger; import org.apache.dubbo.common.logger.LoggerFactory; import org.apache.dubbo.common.resource.GlobalResourceInitializer; import org.apache.dubbo.common.serialize.SerializationException; +import org.apache.dubbo.common.threadpool.ThreadlessExecutor; import org.apache.dubbo.common.timer.HashedWheelTimer; import org.apache.dubbo.common.timer.Timeout; import org.apache.dubbo.common.timer.Timer; @@ -197,6 +198,7 @@ public class DefaultFuture extends CompletableFuture { t.cancel(); } future.doReceived(response); + shutdownExecutorIfNeeded(future); } else { logger.warn(PROTOCOL_TIMEOUT_SERVER, "", "", "The timeout response finally returned at " + (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS").format(new Date())) @@ -215,12 +217,20 @@ public class DefaultFuture extends CompletableFuture { errorResult.setStatus(Response.CLIENT_ERROR); errorResult.setErrorMessage("request future has been canceled."); this.doReceived(errorResult); - FUTURES.remove(id); + DefaultFuture future = FUTURES.remove(id); + shutdownExecutorIfNeeded(future); CHANNELS.remove(id); timeoutCheckTask.cancel(); return true; } + private static void shutdownExecutorIfNeeded(DefaultFuture future) { + ExecutorService executor = future.getExecutor(); + if (executor instanceof ThreadlessExecutor && !executor.isShutdown()) { + executor.shutdownNow(); + } + } + public void cancel() { this.cancel(true); } diff --git a/dubbo-remoting/dubbo-remoting-api/src/test/java/org/apache/dubbo/remoting/exchange/support/DefaultFutureTest.java b/dubbo-remoting/dubbo-remoting-api/src/test/java/org/apache/dubbo/remoting/exchange/support/DefaultFutureTest.java index 1e28237370..8188720480 100644 --- a/dubbo-remoting/dubbo-remoting-api/src/test/java/org/apache/dubbo/remoting/exchange/support/DefaultFutureTest.java +++ b/dubbo-remoting/dubbo-remoting-api/src/test/java/org/apache/dubbo/remoting/exchange/support/DefaultFutureTest.java @@ -161,7 +161,7 @@ class DefaultFutureTest { } @Test - void testClose() { + void testClose1() { Channel channel = new MockedChannel(); Request request = new Request(123); ExecutorService executor = ExtensionLoader.getExtensionLoader(ExecutorRepository.class) @@ -171,6 +171,16 @@ class DefaultFutureTest { Assertions.assertFalse(executor.isTerminated()); } + @Test + void testClose2() { + Channel channel = new MockedChannel(); + Request request = new Request(123); + ThreadlessExecutor threadlessExecutor = new ThreadlessExecutor(); + DefaultFuture.newFuture(channel, request, 1000, threadlessExecutor); + DefaultFuture.closeChannel(channel, 0); + Assertions.assertTrue(threadlessExecutor.isTerminated()); + } + /** * mock a default future */ diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/AsyncRpcResult.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/AsyncRpcResult.java index 5e516c72a9..7244fa38fb 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/AsyncRpcResult.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/AsyncRpcResult.java @@ -183,7 +183,7 @@ public class AsyncRpcResult implements Result { if (executor != null && executor instanceof ThreadlessExecutor) { ThreadlessExecutor threadlessExecutor = (ThreadlessExecutor) executor; try { - while (!responseFuture.isDone()) { + while (!responseFuture.isDone() && !threadlessExecutor.isShutdown()) { threadlessExecutor.waitAndDrain(Long.MAX_VALUE); } } finally { @@ -199,7 +199,7 @@ public class AsyncRpcResult implements Result { if (executor != null && executor instanceof ThreadlessExecutor) { ThreadlessExecutor threadlessExecutor = (ThreadlessExecutor) executor; try { - while (!responseFuture.isDone()) { + while (!responseFuture.isDone() && !threadlessExecutor.isShutdown()) { long restTime = deadline - System.nanoTime(); if (restTime > 0) { threadlessExecutor.waitAndDrain(deadline); From e07e5e294b0bc96ada4ed868cfae1307b3872462 Mon Sep 17 00:00:00 2001 From: Albumen Kevin Date: Tue, 13 Jun 2023 20:25:25 +0800 Subject: [PATCH 04/32] Fix get method name from invocation (#12519) * Fix get method name from invocation * fix compile --- .../filter/support/ConsumerContextFilter.java | 2 +- .../loadbalance/AbstractLoadBalance.java | 3 ++- .../ConsistentHashLoadBalance.java | 6 +----- .../loadbalance/LeastActiveLoadBalance.java | 5 +++-- .../loadbalance/RandomLoadBalance.java | 3 ++- .../loadbalance/RoundRobinLoadBalance.java | 5 +++-- .../ShortestResponseLoadBalance.java | 3 ++- .../matcher/AbstractConditionMatcher.java | 3 ++- .../match/DubboMethodMatch.java | 3 ++- .../router/script/ScriptStateRouter.java | 3 ++- .../support/AbstractClusterInvoker.java | 4 ++-- .../support/FailbackClusterInvoker.java | 9 +++++--- .../support/FailfastClusterInvoker.java | 3 ++- .../support/wrapper/MockClusterInvoker.java | 8 +++---- .../support/wrapper/ScopeClusterInvoker.java | 9 ++++---- .../loadbalance/AbstractLoadBalance.java | 4 +++- .../dubbo/metrics/data/RtStatComposite.java | 3 ++- .../dubbo/metrics/model/MethodMetric.java | 3 ++- .../dubbo/metrics/model/MetricsSupport.java | 13 ------------ .../dubbo/monitor/support/MonitorFilter.java | 2 +- .../dubbo/auth/AccessKeyAuthenticator.java | 5 +++-- .../dubbo/rpc/filter/AccessLogFilter.java | 3 ++- .../dubbo/rpc/filter/ActiveLimitFilter.java | 13 ++++++------ .../dubbo/rpc/filter/DeprecatedFilter.java | 7 ++++--- .../dubbo/rpc/filter/ExceptionFilter.java | 18 ++++++++++++---- .../dubbo/rpc/filter/ExecuteLimitFilter.java | 7 ++++--- .../rpc/filter/ProfilerServerFilter.java | 4 ++-- .../dubbo/rpc/filter/TimeoutFilter.java | 3 ++- .../apache/dubbo/rpc/filter/TokenFilter.java | 3 ++- .../dubbo/rpc/filter/TokenHeaderFilter.java | 3 ++- .../dubbo/rpc/filter/TpsLimitFilter.java | 3 ++- .../rpc/filter/tps/DefaultTPSLimiter.java | 5 +++-- .../dubbo/rpc/support/AccessLogData.java | 2 +- .../protocol/dubbo/CallbackServiceCodec.java | 9 ++++---- .../protocol/dubbo/ChannelWrappedInvoker.java | 2 +- .../rpc/protocol/dubbo/DubboInvoker.java | 8 +++---- .../protocol/dubbo/filter/FutureFilter.java | 11 ++++------ .../protocol/dubbo/filter/TraceFilter.java | 5 +++-- .../rpc/protocol/injvm/InjvmInvoker.java | 4 ++-- .../dubbo/rpc/protocol/tri/TripleInvoker.java | 4 ++-- .../rpc/cluster/router/xds/XdsRouter.java | 21 ++++++++++--------- 41 files changed, 127 insertions(+), 107 deletions(-) diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/filter/support/ConsumerContextFilter.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/filter/support/ConsumerContextFilter.java index 4efa2ba9fe..582578b5e9 100644 --- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/filter/support/ConsumerContextFilter.java +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/filter/support/ConsumerContextFilter.java @@ -110,7 +110,7 @@ public class ConsumerContextFilter implements ClusterFilter, ClusterFilter.Liste if (timeoutCountDown.isExpired()) { return AsyncRpcResult.newDefaultAsyncResult(new RpcException(RpcException.TIMEOUT_TERMINATE, "No time left for making the following call: " + invocation.getServiceName() + "." - + invocation.getMethodName() + ", terminate directly."), invocation); + + RpcUtils.getMethodName(invocation) + ", terminate directly."), invocation); } } } diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/loadbalance/AbstractLoadBalance.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/loadbalance/AbstractLoadBalance.java index a4866e888b..59ecd9a305 100644 --- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/loadbalance/AbstractLoadBalance.java +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/loadbalance/AbstractLoadBalance.java @@ -22,6 +22,7 @@ import org.apache.dubbo.rpc.Invocation; import org.apache.dubbo.rpc.Invoker; import org.apache.dubbo.rpc.cluster.ClusterInvoker; import org.apache.dubbo.rpc.cluster.LoadBalance; +import org.apache.dubbo.rpc.support.RpcUtils; import java.util.List; @@ -83,7 +84,7 @@ public abstract class AbstractLoadBalance implements LoadBalance { if (REGISTRY_SERVICE_REFERENCE_PATH.equals(url.getServiceInterface())) { weight = url.getParameter(WEIGHT_KEY, DEFAULT_WEIGHT); } else { - weight = url.getMethodParameter(invocation.getMethodName(), WEIGHT_KEY, DEFAULT_WEIGHT); + weight = url.getMethodParameter(RpcUtils.getMethodName(invocation), WEIGHT_KEY, DEFAULT_WEIGHT); if (weight > 0) { long timestamp = invoker.getUrl().getParameter(TIMESTAMP_KEY, 0L); if (timestamp > 0L) { diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/loadbalance/ConsistentHashLoadBalance.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/loadbalance/ConsistentHashLoadBalance.java index 8604def436..37386ab186 100644 --- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/loadbalance/ConsistentHashLoadBalance.java +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/loadbalance/ConsistentHashLoadBalance.java @@ -28,7 +28,6 @@ import java.util.TreeMap; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; -import static org.apache.dubbo.common.constants.CommonConstants.$INVOKE; import static org.apache.dubbo.common.constants.CommonConstants.COMMA_SPLIT_PATTERN; /** @@ -97,10 +96,7 @@ public class ConsistentHashLoadBalance extends AbstractLoadBalance { } public Invoker select(Invocation invocation) { - boolean isGeneric = invocation.getMethodName().equals($INVOKE); - String key = toKey(invocation.getArguments(),isGeneric); - - byte[] digest = Bytes.getMD5(key); + byte[] digest = Bytes.getMD5(RpcUtils.getMethodName(invocation)); return selectForKey(hash(digest, 0)); } diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/loadbalance/LeastActiveLoadBalance.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/loadbalance/LeastActiveLoadBalance.java index 41c1bab569..9eb41f6fe9 100644 --- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/loadbalance/LeastActiveLoadBalance.java +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/loadbalance/LeastActiveLoadBalance.java @@ -20,6 +20,7 @@ import org.apache.dubbo.common.URL; import org.apache.dubbo.rpc.Invocation; import org.apache.dubbo.rpc.Invoker; import org.apache.dubbo.rpc.RpcStatus; +import org.apache.dubbo.rpc.support.RpcUtils; import java.util.List; import java.util.concurrent.ThreadLocalRandom; @@ -60,7 +61,7 @@ public class LeastActiveLoadBalance extends AbstractLoadBalance { for (int i = 0; i < length; i++) { Invoker invoker = invokers.get(i); // Get the active number of the invoker - int active = RpcStatus.getStatus(invoker.getUrl(), invocation.getMethodName()).getActive(); + int active = RpcStatus.getStatus(invoker.getUrl(), RpcUtils.getMethodName(invocation)).getActive(); // Get the weight of the invoker's configuration. The default value is 100. int afterWarmup = getWeight(invoker, invocation); // save for later use @@ -97,7 +98,7 @@ public class LeastActiveLoadBalance extends AbstractLoadBalance { return invokers.get(leastIndexes[0]); } if (!sameWeight && totalWeight > 0) { - // If (not every invoker has the same weight & at least one invoker's weight>0), select randomly based on + // If (not every invoker has the same weight & at least one invoker's weight>0), select randomly based on // totalWeight. int offsetWeight = ThreadLocalRandom.current().nextInt(totalWeight); // Return a invoker based on the random value. diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/loadbalance/RandomLoadBalance.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/loadbalance/RandomLoadBalance.java index ce5bdaa16c..1b0b9fce7e 100644 --- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/loadbalance/RandomLoadBalance.java +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/loadbalance/RandomLoadBalance.java @@ -21,6 +21,7 @@ import org.apache.dubbo.common.utils.StringUtils; import org.apache.dubbo.rpc.Invocation; import org.apache.dubbo.rpc.Invoker; import org.apache.dubbo.rpc.cluster.ClusterInvoker; +import org.apache.dubbo.rpc.support.RpcUtils; import java.util.Arrays; import java.util.List; @@ -115,7 +116,7 @@ public class RandomLoadBalance extends AbstractLoadBalance { String weight = invokerUrl.getParameter(WEIGHT_KEY); return StringUtils.isNotEmpty(weight); } else { - String weight = invokerUrl.getMethodParameter(invocation.getMethodName(), WEIGHT_KEY); + String weight = invokerUrl.getMethodParameter(RpcUtils.getMethodName(invocation), WEIGHT_KEY); if (StringUtils.isNotEmpty(weight)) { return true; } else { diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/loadbalance/RoundRobinLoadBalance.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/loadbalance/RoundRobinLoadBalance.java index 8a24a4af4a..0ee6a82c5d 100644 --- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/loadbalance/RoundRobinLoadBalance.java +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/loadbalance/RoundRobinLoadBalance.java @@ -20,6 +20,7 @@ import org.apache.dubbo.common.URL; import org.apache.dubbo.common.utils.ConcurrentHashMapUtils; import org.apache.dubbo.rpc.Invocation; import org.apache.dubbo.rpc.Invoker; +import org.apache.dubbo.rpc.support.RpcUtils; import java.util.Collection; import java.util.List; @@ -79,7 +80,7 @@ public class RoundRobinLoadBalance extends AbstractLoadBalance { * @return */ protected Collection getInvokerAddrList(List> invokers, Invocation invocation) { - String key = invokers.get(0).getUrl().getServiceKey() + "." + invocation.getMethodName(); + String key = invokers.get(0).getUrl().getServiceKey() + "." + RpcUtils.getMethodName(invocation); Map map = methodWeightMap.get(key); if (map != null) { return map.keySet(); @@ -89,7 +90,7 @@ public class RoundRobinLoadBalance extends AbstractLoadBalance { @Override protected Invoker doSelect(List> invokers, URL url, Invocation invocation) { - String key = invokers.get(0).getUrl().getServiceKey() + "." + invocation.getMethodName(); + String key = invokers.get(0).getUrl().getServiceKey() + "." + RpcUtils.getMethodName(invocation); ConcurrentMap map = ConcurrentHashMapUtils.computeIfAbsent(methodWeightMap, key, k -> new ConcurrentHashMap<>()); int totalWeight = 0; long maxCurrent = Long.MIN_VALUE; diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/loadbalance/ShortestResponseLoadBalance.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/loadbalance/ShortestResponseLoadBalance.java index 9b9eae5005..67df332e48 100644 --- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/loadbalance/ShortestResponseLoadBalance.java +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/loadbalance/ShortestResponseLoadBalance.java @@ -25,6 +25,7 @@ import org.apache.dubbo.rpc.RpcStatus; import org.apache.dubbo.rpc.cluster.Constants; import org.apache.dubbo.rpc.model.ApplicationModel; import org.apache.dubbo.rpc.model.ScopeModelAware; +import org.apache.dubbo.rpc.support.RpcUtils; import java.util.List; import java.util.concurrent.ConcurrentHashMap; @@ -116,7 +117,7 @@ public class ShortestResponseLoadBalance extends AbstractLoadBalance implements // Filter out all the shortest response invokers for (int i = 0; i < length; i++) { Invoker invoker = invokers.get(i); - RpcStatus rpcStatus = RpcStatus.getStatus(invoker.getUrl(), invocation.getMethodName()); + RpcStatus rpcStatus = RpcStatus.getStatus(invoker.getUrl(), RpcUtils.getMethodName(invocation)); SlideWindowData slideWindowData = ConcurrentHashMapUtils.computeIfAbsent(methodMap, rpcStatus, SlideWindowData::new); // Calculate the estimated response time from the product of active connections and succeeded average elapsed time. diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/condition/matcher/AbstractConditionMatcher.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/condition/matcher/AbstractConditionMatcher.java index 1dc8310700..db5cd94b95 100644 --- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/condition/matcher/AbstractConditionMatcher.java +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/condition/matcher/AbstractConditionMatcher.java @@ -22,6 +22,7 @@ import org.apache.dubbo.common.logger.LoggerFactory; import org.apache.dubbo.rpc.Invocation; import org.apache.dubbo.rpc.cluster.router.condition.matcher.pattern.ValuePattern; import org.apache.dubbo.rpc.model.ModuleModel; +import org.apache.dubbo.rpc.support.RpcUtils; import java.util.HashSet; import java.util.List; @@ -55,7 +56,7 @@ public abstract class AbstractConditionMatcher implements ConditionMatcher { String sampleValue; //get real invoked method name from invocation if (invocation != null && (METHOD_KEY.equals(conditionKey) || METHODS_KEY.equals(conditionKey))) { - sampleValue = invocation.getMethodName(); + sampleValue = RpcUtils.getMethodName(invocation); } else { sampleValue = sample.get(conditionKey); } diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/mesh/rule/virtualservice/match/DubboMethodMatch.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/mesh/rule/virtualservice/match/DubboMethodMatch.java index 32644cf526..f252410478 100644 --- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/mesh/rule/virtualservice/match/DubboMethodMatch.java +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/mesh/rule/virtualservice/match/DubboMethodMatch.java @@ -18,6 +18,7 @@ package org.apache.dubbo.rpc.cluster.router.mesh.rule.virtualservice.match; import org.apache.dubbo.rpc.Invocation; +import org.apache.dubbo.rpc.support.RpcUtils; import java.util.List; import java.util.Map; @@ -83,7 +84,7 @@ public class DubboMethodMatch { public boolean isMatch(Invocation invocation) { StringMatch nameMatch = getName_match(); - if (nameMatch != null && !nameMatch.isMatch(invocation.getMethodName())) { + if (nameMatch != null && !nameMatch.isMatch(RpcUtils.getMethodName(invocation))) { return false; } diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/script/ScriptStateRouter.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/script/ScriptStateRouter.java index ac01380be1..d0f918094a 100644 --- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/script/ScriptStateRouter.java +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/script/ScriptStateRouter.java @@ -29,6 +29,7 @@ import org.apache.dubbo.rpc.RpcException; import org.apache.dubbo.rpc.cluster.router.RouterSnapshotNode; import org.apache.dubbo.rpc.cluster.router.state.AbstractStateRouter; import org.apache.dubbo.rpc.cluster.router.state.BitList; +import org.apache.dubbo.rpc.support.RpcUtils; import javax.script.Bindings; import javax.script.Compilable; @@ -139,7 +140,7 @@ public class ScriptStateRouter extends AbstractStateRouter { return function.eval(bindings); } catch (ScriptException e) { logger.error(CLUSTER_SCRIPT_EXCEPTION, "Scriptrouter exec script error", "", "Script route error, rule has been ignored. rule: " + rule + ", method:" + - invocation.getMethodName() + ", url: " + RpcContext.getContext().getUrl(), e); + RpcUtils.getMethodName(invocation) + ", url: " + RpcContext.getContext().getUrl(), e); return invokers; } }, accessControlContext)); diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/AbstractClusterInvoker.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/AbstractClusterInvoker.java index 89c58a6dc9..f6325df43b 100644 --- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/AbstractClusterInvoker.java +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/AbstractClusterInvoker.java @@ -158,7 +158,7 @@ public abstract class AbstractClusterInvoker implements ClusterInvoker { if (CollectionUtils.isEmpty(invokers)) { return null; } - String methodName = invocation == null ? StringUtils.EMPTY_STRING : invocation.getMethodName(); + String methodName = invocation == null ? StringUtils.EMPTY_STRING : RpcUtils.getMethodName(invocation); boolean sticky = invokers.get(0).getUrl() .getMethodParameter(methodName, CLUSTER_STICKY_KEY, DEFAULT_CLUSTER_STICKY); @@ -363,7 +363,7 @@ public abstract class AbstractClusterInvoker implements ClusterInvoker { protected void checkInvokers(List> invokers, Invocation invocation) { if (CollectionUtils.isEmpty(invokers)) { throw new RpcException(RpcException.NO_INVOKER_AVAILABLE_AFTER_FILTER, "Failed to invoke the method " - + invocation.getMethodName() + " in the service " + getInterface().getName() + + RpcUtils.getMethodName(invocation) + " in the service " + getInterface().getName() + ". No provider available for the service " + getDirectory().getConsumerUrl().getServiceKey() + " from registry " + getDirectory().getUrl().getAddress() + " on the consumer " + NetUtils.getLocalHost() diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/FailbackClusterInvoker.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/FailbackClusterInvoker.java index 368244a1df..1a20839768 100644 --- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/FailbackClusterInvoker.java +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/FailbackClusterInvoker.java @@ -32,6 +32,7 @@ import org.apache.dubbo.rpc.RpcContext; import org.apache.dubbo.rpc.RpcException; import org.apache.dubbo.rpc.cluster.Directory; import org.apache.dubbo.rpc.cluster.LoadBalance; +import org.apache.dubbo.rpc.support.RpcUtils; import java.util.Collections; import java.util.List; @@ -109,7 +110,9 @@ public class FailbackClusterInvoker extends AbstractClusterInvoker { // Then the serviceContext will be cleared after the call is completed. return invokeWithContextAsync(invoker, invocation, consumerUrl); } catch (Throwable e) { - logger.error(CLUSTER_FAILED_INVOKE_SERVICE,"Failback to invoke method and start to retries","","Failback to invoke method " + invocation.getMethodName() + ", wait for retry in background. Ignored exception: " + logger.error(CLUSTER_FAILED_INVOKE_SERVICE,"Failback to invoke method and start to retries", + "","Failback to invoke method " + RpcUtils.getMethodName(invocation) + + ", wait for retry in background. Ignored exception: " + e.getMessage() + ", ",e); if (retries > 0) { addFailed(loadbalance, invocation, invokers, invoker, consumerUrl); @@ -161,13 +164,13 @@ public class FailbackClusterInvoker extends AbstractClusterInvoker { @Override public void run(Timeout timeout) { try { - logger.info("Attempt to retry to invoke method " + invocation.getMethodName() + + logger.info("Attempt to retry to invoke method " + RpcUtils.getMethodName(invocation) + ". The total will retry " + retries + " times, the current is the " + retriedTimes + " retry"); Invoker retryInvoker = select(loadbalance, invocation, invokers, Collections.singletonList(lastInvoker)); lastInvoker = retryInvoker; invokeWithContextAsync(retryInvoker, invocation, consumerUrl); } catch (Throwable e) { - logger.error(CLUSTER_FAILED_INVOKE_SERVICE,"Failed retry to invoke method","","Failed retry to invoke method " + invocation.getMethodName() + ", waiting again.",e); + logger.error(CLUSTER_FAILED_INVOKE_SERVICE,"Failed retry to invoke method","","Failed retry to invoke method " + RpcUtils.getMethodName(invocation) + ", waiting again.",e); if ((++retriedTimes) >= retries) { logger.error(CLUSTER_FAILED_INVOKE_SERVICE,"Failed retry to invoke method and retry times exceed threshold","","Failed retry times exceed threshold (" + retries + "), We have to abandon, invocation->" + invocation,e); } else { diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/FailfastClusterInvoker.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/FailfastClusterInvoker.java index 22c708f824..87b3b45c5a 100644 --- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/FailfastClusterInvoker.java +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/FailfastClusterInvoker.java @@ -24,6 +24,7 @@ import org.apache.dubbo.rpc.Result; import org.apache.dubbo.rpc.RpcException; import org.apache.dubbo.rpc.cluster.Directory; import org.apache.dubbo.rpc.cluster.LoadBalance; +import org.apache.dubbo.rpc.support.RpcUtils; import java.util.List; @@ -51,7 +52,7 @@ public class FailfastClusterInvoker extends AbstractClusterInvoker { throw new RpcException(e instanceof RpcException ? ((RpcException) e).getCode() : 0, "Failfast invoke providers " + invoker.getUrl() + " " + loadbalance.getClass().getSimpleName() + " for service " + getInterface().getName() - + " method " + invocation.getMethodName() + " on consumer " + NetUtils.getLocalHost() + + " method " + RpcUtils.getMethodName(invocation) + " on consumer " + NetUtils.getLocalHost() + " use dubbo version " + Version.getVersion() + ", but no luck to perform the invocation. Last error is: " + e.getMessage(), e.getCause() != null ? e.getCause() : e); diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/wrapper/MockClusterInvoker.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/wrapper/MockClusterInvoker.java index a935fd95ea..348c6e032d 100644 --- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/wrapper/MockClusterInvoker.java +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/wrapper/MockClusterInvoker.java @@ -97,13 +97,13 @@ public class MockClusterInvoker implements ClusterInvoker { public Result invoke(Invocation invocation) throws RpcException { Result result; - String value = getUrl().getMethodParameter(invocation.getMethodName(), MOCK_KEY, Boolean.FALSE.toString()).trim(); + String value = getUrl().getMethodParameter(RpcUtils.getMethodName(invocation), MOCK_KEY, Boolean.FALSE.toString()).trim(); if (ConfigUtils.isEmpty(value)) { //no mock result = this.invoker.invoke(invocation); } else if (value.startsWith(FORCE_KEY)) { if (logger.isWarnEnabled()) { - logger.warn(CLUSTER_FAILED_MOCK_REQUEST,"force mock","","force-mock: " + invocation.getMethodName() + " force-mock enabled , url : " + getUrl()); + logger.warn(CLUSTER_FAILED_MOCK_REQUEST,"force mock","","force-mock: " + RpcUtils.getMethodName(invocation) + " force-mock enabled , url : " + getUrl()); } //force:direct mock result = doMockInvoke(invocation, null); @@ -128,7 +128,7 @@ public class MockClusterInvoker implements ClusterInvoker { } if (logger.isWarnEnabled()) { - logger.warn(CLUSTER_FAILED_MOCK_REQUEST,"failed to mock invoke","","fail-mock: " + invocation.getMethodName() + " fail-mock enabled , url : " + getUrl(),e); + logger.warn(CLUSTER_FAILED_MOCK_REQUEST,"failed to mock invoke","","fail-mock: " + RpcUtils.getMethodName(invocation) + " fail-mock enabled , url : " + getUrl(),e); } result = doMockInvoke(invocation, e); } @@ -198,7 +198,7 @@ public class MockClusterInvoker implements ClusterInvoker { } catch (RpcException e) { if (logger.isInfoEnabled()) { logger.info("Exception when try to invoke mock. Get mock invokers error for service:" - + getUrl().getServiceInterface() + ", method:" + invocation.getMethodName() + + getUrl().getServiceInterface() + ", method:" + RpcUtils.getMethodName(invocation) + ", will construct a new mock with 'new MockInvoker()'.", e); } } diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/wrapper/ScopeClusterInvoker.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/wrapper/ScopeClusterInvoker.java index 71b7ddf95d..a0564c9b0a 100644 --- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/wrapper/ScopeClusterInvoker.java +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/wrapper/ScopeClusterInvoker.java @@ -35,6 +35,7 @@ import org.apache.dubbo.rpc.cluster.Directory; import org.apache.dubbo.rpc.cluster.directory.StaticDirectory; import org.apache.dubbo.rpc.listener.ExporterChangeListener; import org.apache.dubbo.rpc.listener.InjvmExporterListener; +import org.apache.dubbo.rpc.support.RpcUtils; import java.util.ArrayList; import java.util.List; @@ -142,26 +143,26 @@ public class ScopeClusterInvoker implements ClusterInvoker, ExporterChange // When broadcasting, it should be called remotely. if (isBroadcast()) { if (logger.isDebugEnabled()) { - logger.debug("Performing broadcast call for method: " + invocation.getMethodName() + " of service: " + getUrl().getServiceKey()); + logger.debug("Performing broadcast call for method: " + RpcUtils.getMethodName(invocation) + " of service: " + getUrl().getServiceKey()); } return invoker.invoke(invocation); } if (peerFlag) { if (logger.isDebugEnabled()) { - logger.debug("Performing point-to-point call for method: " + invocation.getMethodName() + " of service: " + getUrl().getServiceKey()); + logger.debug("Performing point-to-point call for method: " + RpcUtils.getMethodName(invocation) + " of service: " + getUrl().getServiceKey()); } // If it's a point-to-point direct connection, invoke the original Invoker return invoker.invoke(invocation); } if (isInjvmExported()) { if (logger.isDebugEnabled()) { - logger.debug("Performing local JVM call for method: " + invocation.getMethodName() + " of service: " + getUrl().getServiceKey()); + logger.debug("Performing local JVM call for method: " + RpcUtils.getMethodName(invocation) + " of service: " + getUrl().getServiceKey()); } // If it's exported to the local JVM, invoke the corresponding Invoker return injvmInvoker.invoke(invocation); } if (logger.isDebugEnabled()) { - logger.debug("Performing remote call for method: " + invocation.getMethodName() + " of service: " + getUrl().getServiceKey()); + logger.debug("Performing remote call for method: " + RpcUtils.getMethodName(invocation) + " of service: " + getUrl().getServiceKey()); } // Otherwise, delegate the invocation to the original Invoker return invoker.invoke(invocation); diff --git a/dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/cluster/loadbalance/AbstractLoadBalance.java b/dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/cluster/loadbalance/AbstractLoadBalance.java index a8a39062ad..98f9aa78fd 100644 --- a/dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/cluster/loadbalance/AbstractLoadBalance.java +++ b/dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/cluster/loadbalance/AbstractLoadBalance.java @@ -17,6 +17,8 @@ package com.alibaba.dubbo.rpc.cluster.loadbalance; +import org.apache.dubbo.rpc.support.RpcUtils; + import com.alibaba.dubbo.common.Constants; import com.alibaba.dubbo.common.URL; import com.alibaba.dubbo.rpc.Invocation; @@ -40,7 +42,7 @@ public abstract class AbstractLoadBalance implements LoadBalance { protected abstract Invoker doSelect(List> invokers, URL url, Invocation invocation); protected int getWeight(Invoker invoker, Invocation invocation) { - int weight = invoker.getUrl().getMethodParameter(invocation.getMethodName(), Constants.WEIGHT_KEY, Constants.DEFAULT_WEIGHT); + int weight = invoker.getUrl().getMethodParameter(RpcUtils.getMethodName(invocation), Constants.WEIGHT_KEY, Constants.DEFAULT_WEIGHT); if (weight > 0) { long timestamp = invoker.getUrl().getParameter(Constants.TIMESTAMP_KEY, 0L); if (timestamp > 0L) { diff --git a/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/data/RtStatComposite.java b/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/data/RtStatComposite.java index a6e7a681d2..c440a35b77 100644 --- a/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/data/RtStatComposite.java +++ b/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/data/RtStatComposite.java @@ -30,6 +30,7 @@ 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 org.apache.dubbo.rpc.support.RpcUtils; import java.util.ArrayList; import java.util.Arrays; @@ -94,7 +95,7 @@ public class RtStatComposite extends AbstractMetricsExport { public void calcMethodKeyRt(Invocation invocation, String registryOpType, Long responseTime) { for (LongContainer container : rtStats.stream().filter(longContainer -> longContainer.specifyType(registryOpType)).collect(Collectors.toList())) { - Number current = (Number) ConcurrentHashMapUtils.computeIfAbsent(container, invocation.getTargetServiceUniqueName() + "_" + invocation.getMethodName(), container.getInitFunc()); + Number current = (Number) ConcurrentHashMapUtils.computeIfAbsent(container, invocation.getTargetServiceUniqueName() + "_" + RpcUtils.getMethodName(invocation), container.getInitFunc()); container.getConsumerFunc().accept(responseTime, current); } } diff --git a/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/model/MethodMetric.java b/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/model/MethodMetric.java index 1985dae228..d3f47a7d8a 100644 --- a/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/model/MethodMetric.java +++ b/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/model/MethodMetric.java @@ -20,6 +20,7 @@ package org.apache.dubbo.metrics.model; import org.apache.dubbo.metrics.model.sample.MetricSample; import org.apache.dubbo.rpc.Invocation; import org.apache.dubbo.rpc.model.ApplicationModel; +import org.apache.dubbo.rpc.support.RpcUtils; import java.util.Map; import java.util.Objects; @@ -40,7 +41,7 @@ public class MethodMetric extends ServiceKeyMetric { public MethodMetric(ApplicationModel applicationModel, Invocation invocation) { super(applicationModel, MetricsSupport.getInterfaceName(invocation)); - this.methodName = MetricsSupport.getMethodName(invocation); + this.methodName = RpcUtils.getMethodName(invocation); this.side = MetricsSupport.getSide(invocation); this.group = MetricsSupport.getGroup(invocation); this.version = MetricsSupport.getVersion(invocation); diff --git a/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/model/MetricsSupport.java b/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/model/MetricsSupport.java index a8f26efd13..b444f7a4a7 100644 --- a/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/model/MetricsSupport.java +++ b/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/model/MetricsSupport.java @@ -30,7 +30,6 @@ import org.apache.dubbo.metrics.model.key.MetricsPlaceValue; import org.apache.dubbo.rpc.Invocation; import org.apache.dubbo.rpc.Invoker; import org.apache.dubbo.rpc.RpcException; -import org.apache.dubbo.rpc.RpcInvocation; import org.apache.dubbo.rpc.model.ApplicationModel; import java.util.HashMap; @@ -55,7 +54,6 @@ import static org.apache.dubbo.common.utils.NetUtils.getLocalHostName; import static org.apache.dubbo.metrics.MetricsConstants.ATTACHMENT_KEY_SERVICE; import static org.apache.dubbo.metrics.MetricsConstants.INVOCATION; import static org.apache.dubbo.metrics.MetricsConstants.SELF_INCREMENT_SIZE; -import static org.apache.dubbo.rpc.support.RpcUtils.isGenericCall; public class MetricsSupport { @@ -159,17 +157,6 @@ public class MetricsSupport { return ivArr[0]; } - public static String getMethodName(Invocation invocation) { - String methodName = invocation.getMethodName(); - if (invocation instanceof RpcInvocation - && isGenericCall(((RpcInvocation) invocation).getParameterTypesDesc(), methodName) - && invocation.getArguments() != null - && invocation.getArguments().length == 3) { - methodName = ((String) invocation.getArguments()[0]).trim(); - } - return methodName; - } - public static String getGroup(Invocation invocation) { String serviceUniqueName = invocation.getTargetServiceUniqueName(); String group = null; diff --git a/dubbo-monitor/dubbo-monitor-api/src/main/java/org/apache/dubbo/monitor/support/MonitorFilter.java b/dubbo-monitor/dubbo-monitor-api/src/main/java/org/apache/dubbo/monitor/support/MonitorFilter.java index f8afc4a588..2d0ec9823b 100644 --- a/dubbo-monitor/dubbo-monitor-api/src/main/java/org/apache/dubbo/monitor/support/MonitorFilter.java +++ b/dubbo-monitor/dubbo-monitor-api/src/main/java/org/apache/dubbo/monitor/support/MonitorFilter.java @@ -116,7 +116,7 @@ public class MonitorFilter implements Filter, Filter.Listener { * @return */ private AtomicInteger getConcurrent(Invoker invoker, Invocation invocation) { - String key = invoker.getInterface().getName() + "." + invocation.getMethodName(); + String key = invoker.getInterface().getName() + "." + RpcUtils.getMethodName(invocation); return ConcurrentHashMapUtils.computeIfAbsent(concurrents, key, k -> new AtomicInteger()); } diff --git a/dubbo-plugin/dubbo-auth/src/main/java/org/apache/dubbo/auth/AccessKeyAuthenticator.java b/dubbo-plugin/dubbo-auth/src/main/java/org/apache/dubbo/auth/AccessKeyAuthenticator.java index d4c7750ed1..875a3c3304 100644 --- a/dubbo-plugin/dubbo-auth/src/main/java/org/apache/dubbo/auth/AccessKeyAuthenticator.java +++ b/dubbo-plugin/dubbo-auth/src/main/java/org/apache/dubbo/auth/AccessKeyAuthenticator.java @@ -27,6 +27,7 @@ import org.apache.dubbo.common.constants.CommonConstants; import org.apache.dubbo.common.utils.StringUtils; import org.apache.dubbo.rpc.Invocation; import org.apache.dubbo.rpc.model.ApplicationModel; +import org.apache.dubbo.rpc.support.RpcUtils; public class AccessKeyAuthenticator implements Authenticator { private final ApplicationModel applicationModel; @@ -54,7 +55,7 @@ public class AccessKeyAuthenticator implements Authenticator { if (StringUtils.isAnyEmpty(accessKeyId, consumer, requestTimestamp, originSignature)) { throw new RpcAuthenticationException("Failed to authenticate, maybe consumer side did not enable the auth"); } - + AccessKeyPair accessKeyPair; try { accessKeyPair = getAccessKeyPair(invocation, url); @@ -86,7 +87,7 @@ public class AccessKeyAuthenticator implements Authenticator { } String getSignature(URL url, Invocation invocation, String secretKey, String time) { - String requestString = String.format(Constants.SIGNATURE_STRING_FORMAT, url.getColonSeparatedKey(), invocation.getMethodName(), secretKey, time); + String requestString = String.format(Constants.SIGNATURE_STRING_FORMAT, url.getColonSeparatedKey(), RpcUtils.getMethodName(invocation), secretKey, time); boolean parameterEncrypt = url.getParameter(Constants.PARAMETER_SIGNATURE_ENABLE_KEY, false); if (parameterEncrypt) { return SignatureUtils.sign(invocation.getArguments(), requestString, secretKey); diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/AccessLogFilter.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/AccessLogFilter.java index 0ad448d487..184aaf2001 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/AccessLogFilter.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/AccessLogFilter.java @@ -30,6 +30,7 @@ import org.apache.dubbo.rpc.Invoker; import org.apache.dubbo.rpc.Result; import org.apache.dubbo.rpc.RpcException; import org.apache.dubbo.rpc.support.AccessLogData; +import org.apache.dubbo.rpc.support.RpcUtils; import java.io.File; import java.io.FileWriter; @@ -198,7 +199,7 @@ public class AccessLogFilter implements Filter { private AccessLogData buildAccessLogData(Invoker invoker, Invocation inv) { AccessLogData logData = AccessLogData.newLogData(); logData.setServiceName(invoker.getInterface().getName()); - logData.setMethodName(inv.getMethodName()); + logData.setMethodName(RpcUtils.getMethodName(inv)); logData.setVersion(invoker.getUrl().getVersion()); logData.setGroup(invoker.getUrl().getGroup()); logData.setInvocationTime(new Date()); diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/ActiveLimitFilter.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/ActiveLimitFilter.java index dc954d70e6..6123b5ba10 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/ActiveLimitFilter.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/ActiveLimitFilter.java @@ -24,6 +24,7 @@ import org.apache.dubbo.rpc.Invoker; import org.apache.dubbo.rpc.Result; import org.apache.dubbo.rpc.RpcException; import org.apache.dubbo.rpc.RpcStatus; +import org.apache.dubbo.rpc.support.RpcUtils; import static org.apache.dubbo.common.constants.CommonConstants.CONSUMER; import static org.apache.dubbo.common.constants.CommonConstants.TIMEOUT_KEY; @@ -49,11 +50,11 @@ public class ActiveLimitFilter implements Filter, Filter.Listener { @Override public Result invoke(Invoker invoker, Invocation invocation) throws RpcException { URL url = invoker.getUrl(); - String methodName = invocation.getMethodName(); + String methodName = RpcUtils.getMethodName(invocation); int max = invoker.getUrl().getMethodParameter(methodName, ACTIVES_KEY, 0); - final RpcStatus rpcStatus = RpcStatus.getStatus(invoker.getUrl(), invocation.getMethodName()); + final RpcStatus rpcStatus = RpcStatus.getStatus(invoker.getUrl(), RpcUtils.getMethodName(invocation)); if (!RpcStatus.beginCount(url, methodName, max)) { - long timeout = invoker.getUrl().getMethodParameter(invocation.getMethodName(), TIMEOUT_KEY, 0); + long timeout = invoker.getUrl().getMethodParameter(RpcUtils.getMethodName(invocation), TIMEOUT_KEY, 0); long start = System.currentTimeMillis(); long remain = timeout; synchronized (rpcStatus) { @@ -68,7 +69,7 @@ public class ActiveLimitFilter implements Filter, Filter.Listener { if (remain <= 0) { throw new RpcException(RpcException.LIMIT_EXCEEDED_EXCEPTION, "Waiting concurrent invoke timeout in client-side for service: " + - invoker.getInterface().getName() + ", method: " + invocation.getMethodName() + + invoker.getInterface().getName() + ", method: " + RpcUtils.getMethodName(invocation) + ", elapsed: " + elapsed + ", timeout: " + timeout + ". concurrent invokes: " + rpcStatus.getActive() + ". max concurrent invoke limit: " + max); } @@ -83,7 +84,7 @@ public class ActiveLimitFilter implements Filter, Filter.Listener { @Override public void onResponse(Result appResponse, Invoker invoker, Invocation invocation) { - String methodName = invocation.getMethodName(); + String methodName = RpcUtils.getMethodName(invocation); URL url = invoker.getUrl(); int max = invoker.getUrl().getMethodParameter(methodName, ACTIVES_KEY, 0); @@ -93,7 +94,7 @@ public class ActiveLimitFilter implements Filter, Filter.Listener { @Override public void onError(Throwable t, Invoker invoker, Invocation invocation) { - String methodName = invocation.getMethodName(); + String methodName = RpcUtils.getMethodName(invocation); URL url = invoker.getUrl(); int max = invoker.getUrl().getMethodParameter(methodName, ACTIVES_KEY, 0); diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/DeprecatedFilter.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/DeprecatedFilter.java index 98654af030..228cc44a82 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/DeprecatedFilter.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/DeprecatedFilter.java @@ -26,6 +26,7 @@ import org.apache.dubbo.rpc.Invocation; import org.apache.dubbo.rpc.Invoker; import org.apache.dubbo.rpc.Result; import org.apache.dubbo.rpc.RpcException; +import org.apache.dubbo.rpc.support.RpcUtils; import java.util.Set; @@ -47,10 +48,10 @@ public class DeprecatedFilter implements Filter { @Override public Result invoke(Invoker invoker, Invocation invocation) throws RpcException { - String key = invoker.getInterface().getName() + "." + invocation.getMethodName(); + String key = invoker.getInterface().getName() + "." + RpcUtils.getMethodName(invocation); if (!LOGGED.contains(key)) { LOGGED.add(key); - if (invoker.getUrl().getMethodParameter(invocation.getMethodName(), DEPRECATED_KEY, false)) { + if (invoker.getUrl().getMethodParameter(RpcUtils.getMethodName(invocation), DEPRECATED_KEY, false)) { LOGGER.error(COMMON_UNSUPPORTED_INVOKER, "", "", "The service method " + invoker.getInterface().getName() + "." + getMethodSignature(invocation) + " is DEPRECATED! Declare from " + invoker.getUrl()); } } @@ -58,7 +59,7 @@ public class DeprecatedFilter implements Filter { } private String getMethodSignature(Invocation invocation) { - StringBuilder buf = new StringBuilder(invocation.getMethodName()); + StringBuilder buf = new StringBuilder(RpcUtils.getMethodName(invocation)); buf.append('('); Class[] types = invocation.getParameterTypes(); if (types != null && types.length > 0) { diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/ExceptionFilter.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/ExceptionFilter.java index 91c830cb53..2cadfec117 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/ExceptionFilter.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/ExceptionFilter.java @@ -29,6 +29,7 @@ import org.apache.dubbo.rpc.Result; import org.apache.dubbo.rpc.RpcContext; import org.apache.dubbo.rpc.RpcException; import org.apache.dubbo.rpc.service.GenericService; +import org.apache.dubbo.rpc.support.RpcUtils; import java.lang.reflect.Method; @@ -66,7 +67,7 @@ public class ExceptionFilter implements Filter, Filter.Listener { } // directly throw if the exception appears in the signature try { - Method method = invoker.getInterface().getMethod(invocation.getMethodName(), invocation.getParameterTypes()); + Method method = invoker.getInterface().getMethod(RpcUtils.getMethodName(invocation), invocation.getParameterTypes()); Class[] exceptionClasses = method.getExceptionTypes(); for (Class exceptionClass : exceptionClasses) { if (exception.getClass().equals(exceptionClass)) { @@ -78,7 +79,10 @@ public class ExceptionFilter implements Filter, Filter.Listener { } // for the exception not found in method's signature, print ERROR message in server's log. - logger.error(CONFIG_FILTER_VALIDATION_EXCEPTION, "", "", "Got unchecked and undeclared exception which called by " + RpcContext.getServiceContext().getRemoteHost() + ". service: " + invoker.getInterface().getName() + ", method: " + invocation.getMethodName() + ", exception: " + exception.getClass().getName() + ": " + exception.getMessage(), exception); + logger.error(CONFIG_FILTER_VALIDATION_EXCEPTION, "", "", + "Got unchecked and undeclared exception which called by " + RpcContext.getServiceContext().getRemoteHost() + + ". service: " + invoker.getInterface().getName() + ", method: " + RpcUtils.getMethodName(invocation) + + ", exception: " + exception.getClass().getName() + ": " + exception.getMessage(), exception); // directly throw if exception class and interface class are in the same jar file. String serviceFile = ReflectUtils.getCodeBase(invoker.getInterface()); @@ -99,14 +103,20 @@ public class ExceptionFilter implements Filter, Filter.Listener { // otherwise, wrap with RuntimeException and throw back to the client appResponse.setException(new RuntimeException(StringUtils.toString(exception))); } catch (Throwable e) { - logger.warn(CONFIG_FILTER_VALIDATION_EXCEPTION, "", "", "Fail to ExceptionFilter when called by " + RpcContext.getServiceContext().getRemoteHost() + ". service: " + invoker.getInterface().getName() + ", method: " + invocation.getMethodName() + ", exception: " + e.getClass().getName() + ": " + e.getMessage(), e); + logger.warn(CONFIG_FILTER_VALIDATION_EXCEPTION, "", "", + "Fail to ExceptionFilter when called by " + RpcContext.getServiceContext().getRemoteHost() + + ". service: " + invoker.getInterface().getName() + ", method: " + RpcUtils.getMethodName(invocation) + + ", exception: " + e.getClass().getName() + ": " + e.getMessage(), e); } } } @Override public void onError(Throwable e, Invoker invoker, Invocation invocation) { - logger.error(CONFIG_FILTER_VALIDATION_EXCEPTION, "", "", "Got unchecked and undeclared exception which called by " + RpcContext.getServiceContext().getRemoteHost() + ". service: " + invoker.getInterface().getName() + ", method: " + invocation.getMethodName() + ", exception: " + e.getClass().getName() + ": " + e.getMessage(), e); + logger.error(CONFIG_FILTER_VALIDATION_EXCEPTION, "", "", + "Got unchecked and undeclared exception which called by " + RpcContext.getServiceContext().getRemoteHost() + + ". service: " + invoker.getInterface().getName() + ", method: " + RpcUtils.getMethodName(invocation) + + ", exception: " + e.getClass().getName() + ": " + e.getMessage(), e); } // For test purpose diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/ExecuteLimitFilter.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/ExecuteLimitFilter.java index da36479724..e77e512f3e 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/ExecuteLimitFilter.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/ExecuteLimitFilter.java @@ -26,9 +26,10 @@ import org.apache.dubbo.rpc.Result; import org.apache.dubbo.rpc.RpcException; import org.apache.dubbo.rpc.RpcStatus; import org.apache.dubbo.rpc.service.GenericService; +import org.apache.dubbo.rpc.support.RpcUtils; + import static org.apache.dubbo.common.constants.CommonConstants.$INVOKE; import static org.apache.dubbo.common.constants.CommonConstants.$INVOKE_ASYNC; - import static org.apache.dubbo.rpc.Constants.EXECUTES_KEY; @@ -45,11 +46,11 @@ public class ExecuteLimitFilter implements Filter, Filter.Listener { @Override public Result invoke(Invoker invoker, Invocation invocation) throws RpcException { URL url = invoker.getUrl(); - String methodName = invocation.getMethodName(); + String methodName = RpcUtils.getMethodName(invocation); int max = url.getMethodParameter(methodName, EXECUTES_KEY, 0); if (!RpcStatus.beginCount(url, methodName, max)) { throw new RpcException(RpcException.LIMIT_EXCEEDED_EXCEPTION, - "Failed to invoke method " + invocation.getMethodName() + " in provider " + + "Failed to invoke method " + RpcUtils.getMethodName(invocation) + " in provider " + url + ", cause: The service using threads greater than limited."); } diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/ProfilerServerFilter.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/ProfilerServerFilter.java index 97f108d60b..36aa5c8ca0 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/ProfilerServerFilter.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/ProfilerServerFilter.java @@ -103,7 +103,7 @@ public class ProfilerServerFilter implements Filter, BaseFilter.Listener { Long timeout = RpcUtils.convertToNumber(invocation.getObjectAttachmentWithoutConvert(TIMEOUT_KEY)); if (timeout == null) { - timeout = (long) invoker.getUrl().getMethodPositiveParameter(invocation.getMethodName(), TIMEOUT_KEY, DEFAULT_TIMEOUT); + timeout = (long) invoker.getUrl().getMethodPositiveParameter(RpcUtils.getMethodName(invocation), TIMEOUT_KEY, DEFAULT_TIMEOUT); } long usage = profiler.getEndTime() - profiler.getStartTime(); if (((usage / (1000_000L * ProfilerSwitch.getWarnPercent())) > timeout) && timeout != -1) { @@ -118,7 +118,7 @@ public class ProfilerServerFilter implements Filter, BaseFilter.Listener { "client: %s\n" + "invocation context:\n%s" + "thread info: \n%s", - invocation.getTargetServiceUniqueName(), invocation.getMethodName(), usage / 1000_000, usage % 1000_000, timeout, + invocation.getTargetServiceUniqueName(), RpcUtils.getMethodName(invocation), usage / 1000_000, usage % 1000_000, timeout, invocation.get(CLIENT_IP_KEY), attachment, Profiler.buildDetail(profiler))); } } diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/TimeoutFilter.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/TimeoutFilter.java index f4dae94073..dac40680de 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/TimeoutFilter.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/TimeoutFilter.java @@ -27,6 +27,7 @@ import org.apache.dubbo.rpc.Result; import org.apache.dubbo.rpc.RpcContext; import org.apache.dubbo.rpc.RpcException; import org.apache.dubbo.rpc.TimeoutCountDown; +import org.apache.dubbo.rpc.support.RpcUtils; import static org.apache.dubbo.common.constants.CommonConstants.TIME_COUNTDOWN_KEY; import static org.apache.dubbo.common.constants.LoggerCodeConstants.PROXY_TIMEOUT_REQUEST; @@ -51,7 +52,7 @@ public class TimeoutFilter implements Filter, Filter.Listener { TimeoutCountDown countDown = (TimeoutCountDown) obj; if (countDown.isExpired()) { if (logger.isWarnEnabled()) { - logger.warn(PROXY_TIMEOUT_REQUEST, "", "", "invoke timed out. method: " + invocation.getMethodName() + + logger.warn(PROXY_TIMEOUT_REQUEST, "", "", "invoke timed out. method: " + RpcUtils.getMethodName(invocation) + " url is " + invoker.getUrl() + ", invoke elapsed " + countDown.elapsedMillis() + " ms."); } } diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/TokenFilter.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/TokenFilter.java index 056d27e6a1..f00dae649d 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/TokenFilter.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/TokenFilter.java @@ -25,6 +25,7 @@ import org.apache.dubbo.rpc.Invoker; import org.apache.dubbo.rpc.Result; import org.apache.dubbo.rpc.RpcContext; import org.apache.dubbo.rpc.RpcException; +import org.apache.dubbo.rpc.support.RpcUtils; import static org.apache.dubbo.rpc.Constants.TOKEN_KEY; @@ -45,7 +46,7 @@ public class TokenFilter implements Filter { Class serviceType = invoker.getInterface(); String remoteToken = (String) inv.getObjectAttachmentWithoutConvert(TOKEN_KEY); if (!token.equals(remoteToken)) { - throw new RpcException("Invalid token! Forbid invoke remote service " + serviceType + " method " + inv.getMethodName() + + throw new RpcException("Invalid token! Forbid invoke remote service " + serviceType + " method " + RpcUtils.getMethodName(inv) + "() from consumer " + RpcContext.getServiceContext().getRemoteHost() + " to provider " + RpcContext.getServiceContext().getLocalHost()+ ", consumer incorrect token is " + remoteToken); } diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/TokenHeaderFilter.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/TokenHeaderFilter.java index d72b790a47..583e91d4cc 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/TokenHeaderFilter.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/TokenHeaderFilter.java @@ -23,6 +23,7 @@ import org.apache.dubbo.rpc.Invoker; import org.apache.dubbo.rpc.RpcContext; import org.apache.dubbo.rpc.RpcException; import org.apache.dubbo.rpc.RpcInvocation; +import org.apache.dubbo.rpc.support.RpcUtils; import static org.apache.dubbo.rpc.Constants.TOKEN_KEY; import static org.apache.dubbo.rpc.RpcException.FORBIDDEN_EXCEPTION; @@ -36,7 +37,7 @@ public class TokenHeaderFilter implements HeaderFilter { Class serviceType = invoker.getInterface(); String remoteToken = (String) invocation.getObjectAttachmentWithoutConvert(TOKEN_KEY); if (!token.equals(remoteToken)) { - throw new RpcException(FORBIDDEN_EXCEPTION, "Forbid invoke remote service " + serviceType + " method " + invocation.getMethodName() + + throw new RpcException(FORBIDDEN_EXCEPTION, "Forbid invoke remote service " + serviceType + " method " + RpcUtils.getMethodName(invocation) + "() from consumer " + RpcContext.getServiceContext().getRemoteHost() + " to provider " + RpcContext.getServiceContext().getLocalHost() + ", consumer incorrect token is " + remoteToken); } diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/TpsLimitFilter.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/TpsLimitFilter.java index 4678e0109f..e06444d693 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/TpsLimitFilter.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/TpsLimitFilter.java @@ -26,6 +26,7 @@ import org.apache.dubbo.rpc.Result; import org.apache.dubbo.rpc.RpcException; import org.apache.dubbo.rpc.filter.tps.DefaultTPSLimiter; import org.apache.dubbo.rpc.filter.tps.TPSLimiter; +import org.apache.dubbo.rpc.support.RpcUtils; import static org.apache.dubbo.rpc.Constants.TPS_LIMIT_RATE_KEY; @@ -49,7 +50,7 @@ public class TpsLimitFilter implements Filter { "Failed to invoke service " + invoker.getInterface().getName() + "." + - invocation.getMethodName() + + RpcUtils.getMethodName(invocation) + " because exceed max service tps."); } diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/tps/DefaultTPSLimiter.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/tps/DefaultTPSLimiter.java index 05d32ca483..9d638c0278 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/tps/DefaultTPSLimiter.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/tps/DefaultTPSLimiter.java @@ -18,6 +18,7 @@ package org.apache.dubbo.rpc.filter.tps; import org.apache.dubbo.common.URL; import org.apache.dubbo.rpc.Invocation; +import org.apache.dubbo.rpc.support.RpcUtils; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; @@ -38,8 +39,8 @@ public class DefaultTPSLimiter implements TPSLimiter { @Override public boolean isAllowable(URL url, Invocation invocation) { - int rate = url.getMethodParameter(invocation.getMethodName(), TPS_LIMIT_RATE_KEY, -1); - long interval = url.getMethodParameter(invocation.getMethodName(), TPS_LIMIT_INTERVAL_KEY, DEFAULT_TPS_LIMIT_INTERVAL); + int rate = url.getMethodParameter(RpcUtils.getMethodName(invocation), TPS_LIMIT_RATE_KEY, -1); + long interval = url.getMethodParameter(RpcUtils.getMethodName(invocation), TPS_LIMIT_INTERVAL_KEY, DEFAULT_TPS_LIMIT_INTERVAL); String serviceKey = url.getServiceKey(); if (rate > 0) { StatItem statItem = stats.get(serviceKey); diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/support/AccessLogData.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/support/AccessLogData.java index 0265517eae..a3acfb2efd 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/support/AccessLogData.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/support/AccessLogData.java @@ -284,7 +284,7 @@ public final class AccessLogData { public void buildAccessLogData(Invoker invoker, Invocation inv) { setServiceName(invoker.getInterface().getName()); - setMethodName(inv.getMethodName()); + setMethodName(RpcUtils.getMethodName(inv)); setVersion(invoker.getUrl().getVersion()); setGroup(invoker.getUrl().getGroup()); setInvocationTime(new Date()); diff --git a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/CallbackServiceCodec.java b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/CallbackServiceCodec.java index 9723ebf78f..2bc90887fb 100644 --- a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/CallbackServiceCodec.java +++ b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/CallbackServiceCodec.java @@ -39,6 +39,7 @@ import org.apache.dubbo.rpc.model.ModuleModel; import org.apache.dubbo.rpc.model.ProviderModel; import org.apache.dubbo.rpc.model.ServiceDescriptor; import org.apache.dubbo.rpc.model.ServiceMetadata; +import org.apache.dubbo.rpc.support.RpcUtils; import java.io.IOException; import java.util.HashMap; @@ -52,9 +53,9 @@ import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY; import static org.apache.dubbo.common.constants.CommonConstants.INTERFACE_KEY; import static org.apache.dubbo.common.constants.CommonConstants.METHODS_KEY; import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY; +import static org.apache.dubbo.common.constants.LoggerCodeConstants.COMMON_PROPERTY_TYPE_MISMATCH; import static org.apache.dubbo.common.constants.LoggerCodeConstants.PROTOCOL_FAILED_DESTROY_INVOKER; import static org.apache.dubbo.common.constants.LoggerCodeConstants.PROTOCOL_FAILED_LOAD_MODEL; -import static org.apache.dubbo.common.constants.LoggerCodeConstants.COMMON_PROPERTY_TYPE_MISMATCH; import static org.apache.dubbo.rpc.Constants.IS_SERVER_KEY; import static org.apache.dubbo.rpc.protocol.dubbo.Constants.CALLBACK_SERVICE_KEY; import static org.apache.dubbo.rpc.protocol.dubbo.Constants.CALLBACK_SERVICE_PROXY_KEY; @@ -219,7 +220,7 @@ public class CallbackServiceCodec { channel.setAttribute(CHANNEL_CALLBACK_KEY, callbackInvokers); } callbackInvokers.add(invoker); - logger.info("method " + inv.getMethodName() + " include a callback service :" + invoker.getUrl() + ", a proxy :" + invoker + " has been created."); + logger.info("method " + RpcUtils.getMethodName(inv) + " include a callback service :" + invoker.getUrl() + ", a proxy :" + invoker + " has been created."); } } } else { @@ -307,7 +308,7 @@ public class CallbackServiceCodec { public Object encodeInvocationArgument(Channel channel, RpcInvocation inv, int paraIndex) throws IOException { // get URL directly URL url = inv.getInvoker() == null ? null : inv.getInvoker().getUrl(); - byte callbackStatus = isCallBack(url, inv.getProtocolServiceKey(), inv.getMethodName(), paraIndex); + byte callbackStatus = isCallBack(url, inv.getProtocolServiceKey(), RpcUtils.getMethodName(inv), paraIndex); Object[] args = inv.getArguments(); Class[] pts = inv.getParameterTypes(); switch (callbackStatus) { @@ -334,7 +335,7 @@ public class CallbackServiceCodec { } return inObject; } - byte callbackstatus = isCallBack(url, inv.getProtocolServiceKey(), inv.getMethodName(), paraIndex); + byte callbackstatus = isCallBack(url, inv.getProtocolServiceKey(), RpcUtils.getMethodName(inv), paraIndex); switch (callbackstatus) { case CallbackServiceCodec.CALLBACK_CREATE: try { diff --git a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/ChannelWrappedInvoker.java b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/ChannelWrappedInvoker.java index 1b1b9a5999..71645f8dc6 100644 --- a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/ChannelWrappedInvoker.java +++ b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/ChannelWrappedInvoker.java @@ -81,7 +81,7 @@ class ChannelWrappedInvoker extends AbstractInvoker { try { if (RpcUtils.isOneway(getUrl(), inv)) { // may have concurrency issue - currentClient.send(request, getUrl().getMethodParameter(invocation.getMethodName(), SENT_KEY, false)); + currentClient.send(request, getUrl().getMethodParameter(RpcUtils.getMethodName(invocation), SENT_KEY, false)); return AsyncRpcResult.newDefaultAsyncResult(invocation); } else { CompletableFuture appResponseFuture = currentClient.request(request).thenApply(AppResponse.class::cast); diff --git a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DubboInvoker.java b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DubboInvoker.java index 613ee79d58..9dfb716e75 100644 --- a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DubboInvoker.java +++ b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DubboInvoker.java @@ -19,10 +19,10 @@ package org.apache.dubbo.rpc.protocol.dubbo; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.Version; import org.apache.dubbo.common.config.ConfigurationUtils; +import org.apache.dubbo.common.serialize.SerializationException; import org.apache.dubbo.common.utils.AtomicPositiveInteger; import org.apache.dubbo.remoting.Constants; import org.apache.dubbo.remoting.RemotingException; -import org.apache.dubbo.common.serialize.SerializationException; import org.apache.dubbo.remoting.TimeoutException; import org.apache.dubbo.remoting.exchange.ExchangeClient; import org.apache.dubbo.remoting.exchange.Request; @@ -102,7 +102,7 @@ public class DubboInvoker extends AbstractInvoker { if (timeout <= 0) { return AsyncRpcResult.newDefaultAsyncResult(new RpcException(RpcException.TIMEOUT_TERMINATE, "No time left for making the following call: " + invocation.getServiceName() + "." - + invocation.getMethodName() + ", terminate directly."), invocation); + + RpcUtils.getMethodName(invocation) + ", terminate directly."), invocation); } invocation.setAttachment(TIMEOUT_KEY, String.valueOf(timeout)); @@ -135,9 +135,9 @@ public class DubboInvoker extends AbstractInvoker { return result; } } catch (TimeoutException e) { - throw new RpcException(RpcException.TIMEOUT_EXCEPTION, "Invoke remote method timeout. method: " + invocation.getMethodName() + ", provider: " + getUrl() + ", cause: " + e.getMessage(), e); + throw new RpcException(RpcException.TIMEOUT_EXCEPTION, "Invoke remote method timeout. method: " + RpcUtils.getMethodName(invocation) + ", provider: " + getUrl() + ", cause: " + e.getMessage(), e); } catch (RemotingException e) { - String remoteExpMsg = "Failed to invoke remote method: " + invocation.getMethodName() + ", provider: " + getUrl() + ", cause: " + e.getMessage(); + String remoteExpMsg = "Failed to invoke remote method: " + RpcUtils.getMethodName(invocation) + ", provider: " + getUrl() + ", cause: " + e.getMessage(); if (e.getCause() instanceof IOException && e.getCause().getCause() instanceof SerializationException) { throw new RpcException(RpcException.SERIALIZATION_EXCEPTION, remoteExpMsg, e); } else { diff --git a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/filter/FutureFilter.java b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/filter/FutureFilter.java index b35e00d8d9..ce6d89555d 100644 --- a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/filter/FutureFilter.java +++ b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/filter/FutureFilter.java @@ -28,11 +28,11 @@ import org.apache.dubbo.rpc.cluster.filter.ClusterFilter; import org.apache.dubbo.rpc.model.AsyncMethodInfo; import org.apache.dubbo.rpc.model.ConsumerModel; import org.apache.dubbo.rpc.model.ServiceModel; +import org.apache.dubbo.rpc.support.RpcUtils; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; -import static org.apache.dubbo.common.constants.CommonConstants.$INVOKE; import static org.apache.dubbo.common.constants.LoggerCodeConstants.PROTOCOL_FAILED_REQUEST; import static org.apache.dubbo.rpc.protocol.dubbo.Constants.ASYNC_METHOD_INFO; @@ -180,10 +180,10 @@ public class FutureFilter implements ClusterFilter, ClusterFilter.Listener { } onthrowMethod.invoke(onthrowInst, params); } catch (Throwable e) { - logger.error(PROTOCOL_FAILED_REQUEST, "", "", invocation.getMethodName() + ".call back method invoke error . callback method :" + onthrowMethod + ", url:" + invoker.getUrl(), e); + logger.error(PROTOCOL_FAILED_REQUEST, "", "", RpcUtils.getMethodName(invocation) + ".call back method invoke error . callback method :" + onthrowMethod + ", url:" + invoker.getUrl(), e); } } else { - logger.error(PROTOCOL_FAILED_REQUEST, "", "", invocation.getMethodName() + ".call back method invoke error . callback method :" + onthrowMethod + ", url:" + invoker.getUrl(), exception); + logger.error(PROTOCOL_FAILED_REQUEST, "", "", RpcUtils.getMethodName(invocation) + ".call back method invoke error . callback method :" + onthrowMethod + ", url:" + invoker.getUrl(), exception); } } @@ -198,10 +198,7 @@ public class FutureFilter implements ClusterFilter, ClusterFilter.Listener { return null; } - String methodName = invocation.getMethodName(); - if (methodName.equals($INVOKE)) { - methodName = (String) invocation.getArguments()[0]; - } + String methodName = RpcUtils.getMethodName(invocation); return ((ConsumerModel) serviceModel).getAsyncInfo(methodName); } diff --git a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/filter/TraceFilter.java b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/filter/TraceFilter.java index badd7a6490..f26692e722 100644 --- a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/filter/TraceFilter.java +++ b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/filter/TraceFilter.java @@ -32,6 +32,7 @@ import org.apache.dubbo.rpc.Invoker; import org.apache.dubbo.rpc.Result; import org.apache.dubbo.rpc.RpcContext; import org.apache.dubbo.rpc.RpcException; +import org.apache.dubbo.rpc.support.RpcUtils; import java.util.ArrayList; import java.util.Set; @@ -79,7 +80,7 @@ public class TraceFilter implements Filter { Result result = invoker.invoke(invocation); long end = System.currentTimeMillis(); if (TRACERS.size() > 0) { - String key = invoker.getInterface().getName() + "." + invocation.getMethodName(); + String key = invoker.getInterface().getName() + "." + RpcUtils.getMethodName(invocation); Set channels = TRACERS.get(key); if (CollectionUtils.isEmpty(channels)) { key = invoker.getInterface().getName(); @@ -105,7 +106,7 @@ public class TraceFilter implements Filter { String prompt = channel.getUrl().getParameter(Constants.PROMPT_KEY, Constants.DEFAULT_PROMPT); channel.send("\r\n" + RpcContext.getServiceContext().getRemoteAddress() + " -> " + invoker.getInterface().getName() - + "." + invocation.getMethodName() + + "." + RpcUtils.getMethodName(invocation) + "(" + JsonUtils.toJson(invocation.getArguments()) + ")" + " -> " + JsonUtils.toJson(result.getValue()) + "\r\nelapsed: " + (end - start) + " ms." + "\r\n\r\n" + prompt); diff --git a/dubbo-rpc/dubbo-rpc-injvm/src/main/java/org/apache/dubbo/rpc/protocol/injvm/InjvmInvoker.java b/dubbo-rpc/dubbo-rpc-injvm/src/main/java/org/apache/dubbo/rpc/protocol/injvm/InjvmInvoker.java index 3f8665c8d6..7e3a1d11fb 100644 --- a/dubbo-rpc/dubbo-rpc-injvm/src/main/java/org/apache/dubbo/rpc/protocol/injvm/InjvmInvoker.java +++ b/dubbo-rpc/dubbo-rpc-injvm/src/main/java/org/apache/dubbo/rpc/protocol/injvm/InjvmInvoker.java @@ -103,11 +103,11 @@ public class InjvmInvoker extends AbstractInvoker { invocation.setAttachment(Constants.TOKEN_KEY, serverURL.getParameter(Constants.TOKEN_KEY)); } - int timeout = RpcUtils.calculateTimeout(getUrl(), invocation, invocation.getMethodName(), DEFAULT_TIMEOUT); + int timeout = RpcUtils.calculateTimeout(getUrl(), 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() + "." - + invocation.getMethodName() + ", terminate directly."), invocation); + + RpcUtils.getMethodName(invocation) + ", terminate directly."), invocation); } invocation.setAttachment(TIMEOUT_KEY, String.valueOf(timeout)); diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/TripleInvoker.java b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/TripleInvoker.java index b6bad67e5f..cda6a57c22 100644 --- a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/TripleInvoker.java +++ b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/TripleInvoker.java @@ -219,11 +219,11 @@ public class TripleInvoker extends AbstractInvoker { AsyncRpcResult invokeUnary(MethodDescriptor methodDescriptor, Invocation invocation, ClientCall call, Executor callbackExecutor) { - int timeout = RpcUtils.calculateTimeout(getUrl(), invocation, invocation.getMethodName(), 3000); + int timeout = RpcUtils.calculateTimeout(getUrl(), invocation, RpcUtils.getMethodName(invocation), 3000); if (timeout <= 0) { return AsyncRpcResult.newDefaultAsyncResult(new RpcException(RpcException.TIMEOUT_TERMINATE, "No time left for making the following call: " + invocation.getServiceName() + "." - + invocation.getMethodName() + ", terminate directly."), invocation); + + RpcUtils.getMethodName(invocation)+ ", terminate directly."), invocation); } invocation.setAttachment(TIMEOUT_KEY, String.valueOf(timeout)); diff --git a/dubbo-xds/src/main/java/org/apache/dubbo/rpc/cluster/router/xds/XdsRouter.java b/dubbo-xds/src/main/java/org/apache/dubbo/rpc/cluster/router/xds/XdsRouter.java index 299fcd6417..c994a219ad 100644 --- a/dubbo-xds/src/main/java/org/apache/dubbo/rpc/cluster/router/xds/XdsRouter.java +++ b/dubbo-xds/src/main/java/org/apache/dubbo/rpc/cluster/router/xds/XdsRouter.java @@ -16,15 +16,6 @@ */ package org.apache.dubbo.rpc.cluster.router.xds; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Optional; -import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ThreadLocalRandom; -import java.util.stream.Collectors; - import org.apache.dubbo.common.URL; import org.apache.dubbo.common.utils.CollectionUtils; import org.apache.dubbo.common.utils.ConcurrentHashSet; @@ -45,6 +36,16 @@ import org.apache.dubbo.rpc.cluster.router.xds.rule.HeaderMatcher; import org.apache.dubbo.rpc.cluster.router.xds.rule.HttpRequestMatch; import org.apache.dubbo.rpc.cluster.router.xds.rule.PathMatcher; import org.apache.dubbo.rpc.cluster.router.xds.rule.XdsRouteRule; +import org.apache.dubbo.rpc.support.RpcUtils; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Optional; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ThreadLocalRandom; +import java.util.stream.Collectors; public class XdsRouter extends AbstractStateRouter implements XdsRouteRuleListener, EdsEndpointListener { @@ -171,7 +172,7 @@ public class XdsRouter extends AbstractStateRouter implements XdsRouteRule } PathMatcher pathMatcher = requestMatch.getPathMatcher(); if (pathMatcher != null) { - String path = "/" + invocation.getInvoker().getUrl().getPath() + "/" + invocation.getMethodName(); + String path = "/" + invocation.getInvoker().getUrl().getPath() + "/" + RpcUtils.getMethodName(invocation); if (!pathMatcher.isMatch(path)) { return null; } From 5f39404b076734d93c4437994f56280daaaabcd0 Mon Sep 17 00:00:00 2001 From: Albumen Kevin Date: Tue, 13 Jun 2023 21:42:27 +0800 Subject: [PATCH 05/32] Support set actual content length to inv/res attributes (#12521) --- .../src/main/java/org/apache/dubbo/remoting/Constants.java | 3 +++ .../dubbo/rpc/protocol/dubbo/DecodeableRpcInvocation.java | 4 ++++ .../dubbo/rpc/protocol/dubbo/DecodeableRpcResult.java | 4 ++++ .../dubbo/rpc/protocol/tri/call/AbstractServerCall.java | 4 ++-- .../rpc/protocol/tri/call/BiStreamServerCallListener.java | 2 +- .../org/apache/dubbo/rpc/protocol/tri/call/ClientCall.java | 3 ++- .../tri/call/ObserverToClientCallListenerAdapter.java | 2 +- .../org/apache/dubbo/rpc/protocol/tri/call/ServerCall.java | 3 ++- .../protocol/tri/call/ServerStreamServerCallListener.java | 2 +- .../dubbo/rpc/protocol/tri/call/TripleClientCall.java | 6 +++--- .../rpc/protocol/tri/call/UnaryClientCallListener.java | 6 +++++- .../rpc/protocol/tri/call/UnaryServerCallListener.java | 4 +++- 12 files changed, 31 insertions(+), 12 deletions(-) diff --git a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/Constants.java b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/Constants.java index a5f7fcebef..e3dfee7da7 100644 --- a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/Constants.java +++ b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/Constants.java @@ -163,4 +163,7 @@ public interface Constants { String OK_HTTP = "ok-http"; String URL_CONNECTION = "url-connection"; String APACHE_HTTP_CLIENT = "apache-http-client"; + + String CONTENT_LENGTH_KEY = "content-length"; + } diff --git a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DecodeableRpcInvocation.java b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DecodeableRpcInvocation.java index 3f2127c0b5..f23a7a9345 100644 --- a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DecodeableRpcInvocation.java +++ b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DecodeableRpcInvocation.java @@ -27,6 +27,7 @@ import org.apache.dubbo.common.utils.ReflectUtils; import org.apache.dubbo.common.utils.StringUtils; import org.apache.dubbo.remoting.Channel; import org.apache.dubbo.remoting.Codec; +import org.apache.dubbo.remoting.Constants; import org.apache.dubbo.remoting.Decodeable; import org.apache.dubbo.remoting.RemotingException; import org.apache.dubbo.remoting.exchange.Request; @@ -119,6 +120,9 @@ public class DecodeableRpcInvocation extends RpcInvocation implements Codec, Dec @Override public Object decode(Channel channel, InputStream input) throws IOException { + int contentLength = input.available(); + getAttributes().put(Constants.CONTENT_LENGTH_KEY, contentLength); + ObjectInput in = CodecSupport.getSerialization(serializationType) .deserialize(channel.getUrl(), input); this.put(SERIALIZATION_ID_KEY, serializationType); diff --git a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DecodeableRpcResult.java b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DecodeableRpcResult.java index ef3b89bb31..ea6f94ed89 100644 --- a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DecodeableRpcResult.java +++ b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DecodeableRpcResult.java @@ -27,6 +27,7 @@ import org.apache.dubbo.common.utils.Assert; import org.apache.dubbo.common.utils.StringUtils; import org.apache.dubbo.remoting.Channel; import org.apache.dubbo.remoting.Codec; +import org.apache.dubbo.remoting.Constants; import org.apache.dubbo.remoting.Decodeable; import org.apache.dubbo.remoting.exchange.Response; import org.apache.dubbo.remoting.transport.CodecSupport; @@ -82,6 +83,9 @@ public class DecodeableRpcResult extends AppResponse implements Codec, Decodeabl log.debug("Decoding in thread -- [" + thread.getName() + "#" + thread.getId() + "]"); } + int contentLength = input.available(); + setAttribute(Constants.CONTENT_LENGTH_KEY, contentLength); + // switch TCCL if (invocation != null && invocation.getServiceModel() != null) { Thread.currentThread().setContextClassLoader(invocation.getServiceModel().getClassLoader()); diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/call/AbstractServerCall.java b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/call/AbstractServerCall.java index 623e731ec4..8dddc8daf6 100644 --- a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/call/AbstractServerCall.java +++ b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/call/AbstractServerCall.java @@ -52,8 +52,8 @@ import java.util.concurrent.TimeUnit; import static org.apache.dubbo.common.constants.LoggerCodeConstants.PROTOCOL_FAILED_CREATE_STREAM_TRIPLE; import static org.apache.dubbo.common.constants.LoggerCodeConstants.PROTOCOL_FAILED_PARSE; -import static org.apache.dubbo.common.constants.LoggerCodeConstants.PROTOCOL_FAILED_SERIALIZE_TRIPLE; import static org.apache.dubbo.common.constants.LoggerCodeConstants.PROTOCOL_FAILED_REQUEST; +import static org.apache.dubbo.common.constants.LoggerCodeConstants.PROTOCOL_FAILED_SERIALIZE_TRIPLE; public abstract class AbstractServerCall implements ServerCall, ServerStream.Listener { @@ -212,7 +212,7 @@ public abstract class AbstractServerCall implements ServerCall, ServerStream.Lis .getContextClassLoader(); try { Object instance = parseSingleMessage(message); - listener.onMessage(instance); + listener.onMessage(instance, message.length); } catch (Exception e) { final TriRpcStatus status = TriRpcStatus.UNKNOWN.withDescription("Server error") .withCause(e); diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/call/BiStreamServerCallListener.java b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/call/BiStreamServerCallListener.java index 754ef77f3c..2d3346b5c6 100644 --- a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/call/BiStreamServerCallListener.java +++ b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/call/BiStreamServerCallListener.java @@ -40,7 +40,7 @@ public class BiStreamServerCallListener extends AbstractServerCallListener { } @Override - public void onMessage(Object message) { + public void onMessage(Object message, int actualContentLength) { if (message instanceof Object[]) { message = ((Object[]) message)[0]; } diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/call/ClientCall.java b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/call/ClientCall.java index 6f5b43b6b8..d99c8c3bf0 100644 --- a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/call/ClientCall.java +++ b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/call/ClientCall.java @@ -44,8 +44,9 @@ public interface ClientCall { * Callback when message received. * * @param message message received + * @param actualContentLength actual content length from body */ - void onMessage(Object message); + void onMessage(Object message, int actualContentLength); /** * Callback when call is finished. diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/call/ObserverToClientCallListenerAdapter.java b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/call/ObserverToClientCallListenerAdapter.java index 5d427e05ee..f52bf4e8d1 100644 --- a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/call/ObserverToClientCallListenerAdapter.java +++ b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/call/ObserverToClientCallListenerAdapter.java @@ -38,7 +38,7 @@ public class ObserverToClientCallListenerAdapter implements ClientCall.Listener } @Override - public void onMessage(Object message) { + public void onMessage(Object message, int actualContentLength) { delegate.onNext(message); if (call.isAutoRequest()) { call.request(1); diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/call/ServerCall.java b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/call/ServerCall.java index d43eaab973..45742b9a80 100644 --- a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/call/ServerCall.java +++ b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/call/ServerCall.java @@ -37,8 +37,9 @@ public interface ServerCall { * Callback when a request message is received. * * @param message message received + * @param actualContentLength actual content length from body */ - void onMessage(Object message); + void onMessage(Object message, int actualContentLength); /** * @param status when the call is canceled. diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/call/ServerStreamServerCallListener.java b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/call/ServerStreamServerCallListener.java index d518047321..c6b42e50e2 100644 --- a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/call/ServerStreamServerCallListener.java +++ b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/call/ServerStreamServerCallListener.java @@ -34,7 +34,7 @@ public class ServerStreamServerCallListener extends AbstractServerCallListener { } @Override - public void onMessage(Object message) { + public void onMessage(Object message, int actualContentLength) { if (message instanceof Object[]) { message = ((Object[]) message)[0]; } diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/call/TripleClientCall.java b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/call/TripleClientCall.java index 59aeede63b..4ba712e843 100644 --- a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/call/TripleClientCall.java +++ b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/call/TripleClientCall.java @@ -18,7 +18,6 @@ package org.apache.dubbo.rpc.protocol.tri.call; import org.apache.dubbo.common.logger.ErrorTypeAwareLogger; -import io.netty.handler.codec.http2.Http2Exception; import org.apache.dubbo.common.logger.LoggerFactory; import org.apache.dubbo.common.stream.StreamObserver; import org.apache.dubbo.remoting.api.connection.AbstractConnectionClient; @@ -34,14 +33,15 @@ import org.apache.dubbo.rpc.protocol.tri.stream.TripleClientStream; import org.apache.dubbo.rpc.protocol.tri.transport.TripleWriteQueue; import io.netty.channel.Channel; +import io.netty.handler.codec.http2.Http2Exception; import java.util.Map; import java.util.concurrent.Executor; +import static io.netty.handler.codec.http2.Http2Error.FLOW_CONTROL_ERROR; import static org.apache.dubbo.common.constants.LoggerCodeConstants.PROTOCOL_FAILED_RESPONSE; import static org.apache.dubbo.common.constants.LoggerCodeConstants.PROTOCOL_FAILED_SERIALIZE_TRIPLE; import static org.apache.dubbo.common.constants.LoggerCodeConstants.PROTOCOL_STREAM_LISTENER; -import static io.netty.handler.codec.http2.Http2Error.FLOW_CONTROL_ERROR; public class TripleClientCall implements ClientCall, ClientStream.Listener { private static final ErrorTypeAwareLogger LOGGER = LoggerFactory.getErrorTypeAwareLogger(TripleClientCall.class); @@ -78,7 +78,7 @@ public class TripleClientCall implements ClientCall, ClientStream.Listener { } try { final Object unpacked = requestMetadata.packableMethod.parseResponse(message, isReturnTriException); - listener.onMessage(unpacked); + listener.onMessage(unpacked, message.length); } catch (Throwable t) { TriRpcStatus status = TriRpcStatus.INTERNAL.withDescription("Deserialize response failed") .withCause(t); diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/call/UnaryClientCallListener.java b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/call/UnaryClientCallListener.java index 57dbb625f8..b08ee0618f 100644 --- a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/call/UnaryClientCallListener.java +++ b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/call/UnaryClientCallListener.java @@ -17,6 +17,7 @@ package org.apache.dubbo.rpc.protocol.tri.call; +import org.apache.dubbo.remoting.Constants; import org.apache.dubbo.rpc.AppResponse; import org.apache.dubbo.rpc.TriRpcStatus; import org.apache.dubbo.rpc.protocol.tri.DeadlineFuture; @@ -27,14 +28,16 @@ public class UnaryClientCallListener implements ClientCall.Listener { private final DeadlineFuture future; private Object appResponse; + private int actualContentLength; public UnaryClientCallListener(DeadlineFuture deadlineFuture) { this.future = deadlineFuture; } @Override - public void onMessage(Object message) { + public void onMessage(Object message, int actualContentLength) { this.appResponse = message; + this.actualContentLength = actualContentLength; } @Override @@ -50,6 +53,7 @@ public class UnaryClientCallListener implements ClientCall.Listener { } else { result.setException(status.asException()); } + result.setAttribute(Constants.CONTENT_LENGTH_KEY, actualContentLength); future.received(status, result); } diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/call/UnaryServerCallListener.java b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/call/UnaryServerCallListener.java index 36011c5b3f..e53b72079a 100644 --- a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/call/UnaryServerCallListener.java +++ b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/call/UnaryServerCallListener.java @@ -17,6 +17,7 @@ package org.apache.dubbo.rpc.protocol.tri.call; +import org.apache.dubbo.remoting.Constants; import org.apache.dubbo.rpc.Invoker; import org.apache.dubbo.rpc.RpcException; import org.apache.dubbo.rpc.RpcInvocation; @@ -40,12 +41,13 @@ public class UnaryServerCallListener extends AbstractServerCallListener { } @Override - public void onMessage(Object message) { + public void onMessage(Object message, int actualContentLength) { if (message instanceof Object[]) { invocation.setArguments((Object[]) message); } else { invocation.setArguments(new Object[]{message}); } + invocation.put(Constants.CONTENT_LENGTH_KEY, actualContentLength); } @Override From a613cae2f3d6d42e555575d46c142ef60ec30729 Mon Sep 17 00:00:00 2001 From: conghuhu <56248584+conghuhu@users.noreply.github.com> Date: Sat, 17 Jun 2023 19:54:12 +0800 Subject: [PATCH 06/32] refactor: migrate tracing core from boot-start to dubbo deployer (#12453) Co-authored-by: songxiaosheng --- .artifacts | 1 + dubbo-cluster/pom.xml | 5 - ...che.dubbo.rpc.cluster.filter.ClusterFilter | 1 - .../filter/AbstractObservationFilterTest.java | 83 ------- .../common/constants/LoggerCodeConstants.java | 2 + .../dubbo/config/nested/BaggageConfig.java | 25 +++ .../dubbo/config/nested/ExporterConfig.java | 41 +++- .../config/nested/PropagationConfig.java | 7 + .../dubbo/config/nested/SamplingConfig.java | 7 + dubbo-config/dubbo-config-api/pom.xml | 6 + .../deploy/DefaultApplicationDeployer.java | 117 +++++----- .../DefaultApplicationDeployerTest.java | 9 +- dubbo-dependencies-bom/pom.xml | 17 +- dubbo-distribution/dubbo-all/pom.xml | 10 + dubbo-distribution/dubbo-bom/pom.xml | 7 + dubbo-distribution/dubbo-core-spi/pom.xml | 1 + dubbo-metrics/dubbo-metrics-api/pom.xml | 5 - .../apache/dubbo/metrics/aggregate/Pane.java | 0 .../metrics/aggregate/SlidingWindow.java | 0 .../metrics/utils/MetricsSupportUtil.java | 38 ++++ .../aggregate/TimeWindowAggregatorTest.java | 3 +- dubbo-metrics/dubbo-metrics-default/pom.xml | 5 - .../internal/org.apache.dubbo.rpc.Filter | 2 - dubbo-metrics/dubbo-tracing/pom.xml | 111 +++++++++ ...ractDefaultDubboObservationConvention.java | 8 +- ...faultDubboClientObservationConvention.java | 7 +- ...faultDubboServerObservationConvention.java | 4 +- .../DubboClientObservationConvention.java | 4 +- .../DubboObservationDocumentation.java | 2 +- .../tracing/DubboObservationRegistry.java | 90 ++++++++ .../DubboServerObservationConvention.java | 4 +- .../tracing/context}/DubboClientContext.java | 2 +- .../tracing/context}/DubboServerContext.java | 2 +- .../dubbo/tracing/exporter/TraceExporter.java | 37 +++ .../exporter/TraceExporterFactory.java | 66 ++++++ .../tracing/exporter/otlp/OTlpExporter.java | 66 ++++++ .../exporter/zipkin/ZipkinExporter.java | 60 +++++ .../filter}/ObservationReceiverFilter.java | 19 +- .../filter}/ObservationSenderFilter.java | 23 +- .../tracing/tracer/PropagatorProvider.java | 29 +++ .../tracer/PropagatorProviderFactory.java | 37 +++ .../dubbo/tracing/tracer/TracerProvider.java | 30 +++ .../tracing/tracer/TracerProviderFactory.java | 39 ++++ .../tracer/brave/BravePropagatorProvider.java | 31 +++ .../tracing/tracer/brave/BraveProvider.java | 41 ++++ .../tracer/otel/OTelPropagatorProvider.java | 38 ++++ .../tracer/otel/OpenTelemetryProvider.java | 212 ++++++++++++++++++ .../tracing/utils/ObservationSupportUtil.java | 49 ++++ .../internal/org.apache.dubbo.rpc.Filter | 1 + ...che.dubbo.rpc.cluster.filter.ClusterFilter | 1 + ...tDubboClientObservationConventionTest.java | 8 +- ...tDubboServerObservationConventionTest.java | 9 +- .../apache/dubbo/tracing}/MockInvocation.java | 6 +- .../AbstractObservationFilterTest.java | 8 +- .../ObservationReceiverFilterTest.java | 3 +- .../filter/ObservationSenderFilterTest.java | 14 +- .../tracer/PropagatorProviderFactoryTest.java | 34 +++ .../otel/OTelPropagatorProviderTest.java | 39 ++++ .../otel/OpenTelemetryProviderTest.java | 53 +++++ .../utils/ObservationConventionUtils.java | 7 +- .../utils/ObservationSupportUtilTest.java | 49 ++++ dubbo-metrics/pom.xml | 1 + .../observability/autoconfigure/pom.xml | 6 + .../DubboObservationAutoConfiguration.java | 19 +- .../brave/BraveAutoConfiguration.java | 18 +- .../otel/OpenTelemetryAutoConfiguration.java | 17 +- dubbo-test/dubbo-dependencies-all/pom.xml | 6 +- 67 files changed, 1456 insertions(+), 246 deletions(-) delete mode 100644 dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/filter/AbstractObservationFilterTest.java mode change 100755 => 100644 dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/aggregate/Pane.java mode change 100755 => 100644 dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/aggregate/SlidingWindow.java create mode 100644 dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/utils/MetricsSupportUtil.java delete mode 100644 dubbo-metrics/dubbo-metrics-default/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.Filter create mode 100644 dubbo-metrics/dubbo-tracing/pom.xml rename dubbo-metrics/{dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/observation => dubbo-tracing/src/main/java/org/apache/dubbo/tracing}/AbstractDefaultDubboObservationConvention.java (87%) rename dubbo-metrics/{dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/observation => dubbo-tracing/src/main/java/org/apache/dubbo/tracing}/DefaultDubboClientObservationConvention.java (92%) rename dubbo-metrics/{dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/observation => dubbo-tracing/src/main/java/org/apache/dubbo/tracing}/DefaultDubboServerObservationConvention.java (94%) rename dubbo-metrics/{dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/observation => dubbo-tracing/src/main/java/org/apache/dubbo/tracing}/DubboClientObservationConvention.java (92%) rename dubbo-metrics/{dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/observation => dubbo-tracing/src/main/java/org/apache/dubbo/tracing}/DubboObservationDocumentation.java (98%) create mode 100644 dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/DubboObservationRegistry.java rename dubbo-metrics/{dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/observation => dubbo-tracing/src/main/java/org/apache/dubbo/tracing}/DubboServerObservationConvention.java (92%) rename dubbo-metrics/{dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/observation => dubbo-tracing/src/main/java/org/apache/dubbo/tracing/context}/DubboClientContext.java (97%) rename dubbo-metrics/{dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/observation => dubbo-tracing/src/main/java/org/apache/dubbo/tracing/context}/DubboServerContext.java (97%) create mode 100644 dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/exporter/TraceExporter.java create mode 100644 dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/exporter/TraceExporterFactory.java create mode 100644 dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/exporter/otlp/OTlpExporter.java create mode 100644 dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/exporter/zipkin/ZipkinExporter.java rename dubbo-metrics/{dubbo-metrics-default/src/main/java/org/apache/dubbo/metrics/observation => dubbo-tracing/src/main/java/org/apache/dubbo/tracing/filter}/ObservationReceiverFilter.java (80%) rename {dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/filter/support => dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/filter}/ObservationSenderFilter.java (78%) create mode 100644 dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/tracer/PropagatorProvider.java create mode 100644 dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/tracer/PropagatorProviderFactory.java create mode 100644 dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/tracer/TracerProvider.java create mode 100644 dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/tracer/TracerProviderFactory.java create mode 100644 dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/tracer/brave/BravePropagatorProvider.java create mode 100644 dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/tracer/brave/BraveProvider.java create mode 100644 dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/tracer/otel/OTelPropagatorProvider.java create mode 100644 dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/tracer/otel/OpenTelemetryProvider.java create mode 100644 dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/utils/ObservationSupportUtil.java create mode 100644 dubbo-metrics/dubbo-tracing/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.Filter create mode 100644 dubbo-metrics/dubbo-tracing/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.cluster.filter.ClusterFilter rename dubbo-metrics/{dubbo-metrics-api/src/test/java/org/apache/dubbo/metrics/observation => dubbo-tracing/src/test/java/org/apache/dubbo/tracing}/DefaultDubboClientObservationConventionTest.java (94%) rename dubbo-metrics/{dubbo-metrics-api/src/test/java/org/apache/dubbo/metrics/observation => dubbo-tracing/src/test/java/org/apache/dubbo/tracing}/DefaultDubboServerObservationConventionTest.java (93%) rename dubbo-metrics/{dubbo-metrics-default/src/test/java/org/apache/dubbo/metrics/observation => dubbo-tracing/src/test/java/org/apache/dubbo/tracing}/MockInvocation.java (97%) rename dubbo-metrics/{dubbo-metrics-default/src/test/java/org/apache/dubbo/metrics/observation => dubbo-tracing/src/test/java/org/apache/dubbo/tracing/filter}/AbstractObservationFilterTest.java (94%) rename dubbo-metrics/{dubbo-metrics-default/src/test/java/org/apache/dubbo/metrics/observation => dubbo-tracing/src/test/java/org/apache/dubbo/tracing/filter}/ObservationReceiverFilterTest.java (99%) rename {dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster => dubbo-metrics/dubbo-tracing/src/test/java/org/apache/dubbo/tracing}/filter/ObservationSenderFilterTest.java (92%) create mode 100644 dubbo-metrics/dubbo-tracing/src/test/java/org/apache/dubbo/tracing/tracer/PropagatorProviderFactoryTest.java create mode 100644 dubbo-metrics/dubbo-tracing/src/test/java/org/apache/dubbo/tracing/tracer/otel/OTelPropagatorProviderTest.java create mode 100644 dubbo-metrics/dubbo-tracing/src/test/java/org/apache/dubbo/tracing/tracer/otel/OpenTelemetryProviderTest.java rename dubbo-metrics/{dubbo-metrics-api/src/test/java/org/apache/dubbo/metrics/observation => dubbo-tracing/src/test/java/org/apache/dubbo/tracing}/utils/ObservationConventionUtils.java (97%) create mode 100644 dubbo-metrics/dubbo-tracing/src/test/java/org/apache/dubbo/tracing/utils/ObservationSupportUtilTest.java diff --git a/.artifacts b/.artifacts index 539c51deed..e18fed5eb5 100644 --- a/.artifacts +++ b/.artifacts @@ -114,4 +114,5 @@ dubbo-nacos-spring-boot-starter dubbo-zookeeper-spring-boot-starter dubbo-zookeeper-curator5-spring-boot-starter dubbo-spring-security +dubbo-tracing dubbo-xds diff --git a/dubbo-cluster/pom.xml b/dubbo-cluster/pom.xml index 130b7e3f7e..08b83b8cca 100644 --- a/dubbo-cluster/pom.xml +++ b/dubbo-cluster/pom.xml @@ -86,10 +86,5 @@ ${project.parent.version} true - - io.micrometer - micrometer-tracing-integration-test - test - diff --git a/dubbo-cluster/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.cluster.filter.ClusterFilter b/dubbo-cluster/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.cluster.filter.ClusterFilter index cd0a2f44e8..28a9e73853 100644 --- a/dubbo-cluster/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.cluster.filter.ClusterFilter +++ b/dubbo-cluster/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.cluster.filter.ClusterFilter @@ -1,5 +1,4 @@ consumercontext=org.apache.dubbo.rpc.cluster.filter.support.ConsumerContextFilter consumer-classloader=org.apache.dubbo.rpc.cluster.filter.support.ConsumerClassLoaderFilter router-snapshot=org.apache.dubbo.rpc.cluster.router.RouterSnapshotFilter -observationsender=org.apache.dubbo.rpc.cluster.filter.support.ObservationSenderFilter metricsClusterFilter=org.apache.dubbo.rpc.cluster.filter.support.MetricsClusterFilter \ No newline at end of file diff --git a/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/filter/AbstractObservationFilterTest.java b/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/filter/AbstractObservationFilterTest.java deleted file mode 100644 index 2f293484b4..0000000000 --- a/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/filter/AbstractObservationFilterTest.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * 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.rpc.cluster.filter; - -import io.micrometer.tracing.test.SampleTestRunner; -import org.apache.dubbo.config.ApplicationConfig; -import org.apache.dubbo.config.TracingConfig; -import org.apache.dubbo.rpc.AppResponse; -import org.apache.dubbo.rpc.BaseFilter; -import org.apache.dubbo.rpc.Invoker; -import org.apache.dubbo.rpc.RpcInvocation; -import org.apache.dubbo.rpc.model.ApplicationModel; -import org.junit.jupiter.api.AfterEach; - -import static org.mockito.BDDMockito.given; -import static org.mockito.Mockito.mock; - -abstract class AbstractObservationFilterTest extends SampleTestRunner { - - ApplicationModel applicationModel; - RpcInvocation invocation; - - BaseFilter filter; - - Invoker invoker = mock(Invoker.class); - - static final String INTERFACE_NAME = "org.apache.dubbo.MockInterface"; - static final String METHOD_NAME = "mockMethod"; - static final String GROUP = "mockGroup"; - static final String VERSION = "1.0.0"; - - @AfterEach - public void teardown() { - if (applicationModel != null) { - applicationModel.destroy(); - } - } - - abstract BaseFilter createFilter(ApplicationModel applicationModel); - - void setupConfig() { - ApplicationConfig config = new ApplicationConfig(); - config.setName("MockObservations"); - - applicationModel = ApplicationModel.defaultModel(); - applicationModel.getApplicationConfigManager().setApplication(config); - - invocation = new RpcInvocation(new MockInvocation()); - invocation.addInvokedInvoker(invoker); - - applicationModel.getBeanFactory().registerBean(getObservationRegistry()); - TracingConfig tracingConfig = new TracingConfig(); - tracingConfig.setEnabled(true); - applicationModel.getApplicationConfigManager().setTracing(tracingConfig); - - filter = createFilter(applicationModel); - - given(invoker.invoke(invocation)).willReturn(new AppResponse("success")); - - initParam(); - } - - private void initParam() { - invocation.setTargetServiceUniqueName(GROUP + "/" + INTERFACE_NAME + ":" + VERSION); - invocation.setMethodName(METHOD_NAME); - invocation.setParameterTypes(new Class[] {String.class}); - } - -} diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/constants/LoggerCodeConstants.java b/dubbo-common/src/main/java/org/apache/dubbo/common/constants/LoggerCodeConstants.java index 0a3bfa2125..83e7b62dfa 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/constants/LoggerCodeConstants.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/constants/LoggerCodeConstants.java @@ -92,6 +92,8 @@ public interface LoggerCodeConstants { String VULNERABILITY_WARNING = "0-28"; + String COMMON_NOT_FOUND_TRACER_DEPENDENCY = "0-29"; + // Registry module diff --git a/dubbo-common/src/main/java/org/apache/dubbo/config/nested/BaggageConfig.java b/dubbo-common/src/main/java/org/apache/dubbo/config/nested/BaggageConfig.java index beba9b5ddd..b39f0ece30 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/config/nested/BaggageConfig.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/config/nested/BaggageConfig.java @@ -39,6 +39,19 @@ public class BaggageConfig implements Serializable { */ private List remoteFields = new ArrayList<>(); + public BaggageConfig() { + } + + public BaggageConfig(Boolean enabled) { + this.enabled = enabled; + } + + public BaggageConfig(Boolean enabled, Correlation correlation, List remoteFields) { + this.enabled = enabled; + this.correlation = correlation; + this.remoteFields = remoteFields; + } + public Boolean getEnabled() { return enabled; } @@ -76,6 +89,18 @@ public class BaggageConfig implements Serializable { */ private List fields = new ArrayList<>(); + public Correlation() { + } + + public Correlation(boolean enabled) { + this.enabled = enabled; + } + + public Correlation(boolean enabled, List fields) { + this.enabled = enabled; + this.fields = fields; + } + public boolean isEnabled() { return this.enabled; } diff --git a/dubbo-common/src/main/java/org/apache/dubbo/config/nested/ExporterConfig.java b/dubbo-common/src/main/java/org/apache/dubbo/config/nested/ExporterConfig.java index 3b621572d0..871a5afbab 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/config/nested/ExporterConfig.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/config/nested/ExporterConfig.java @@ -17,13 +17,13 @@ package org.apache.dubbo.config.nested; +import org.apache.dubbo.config.support.Nested; + import java.io.Serializable; import java.time.Duration; import java.util.HashMap; import java.util.Map; -import org.apache.dubbo.config.support.Nested; - public class ExporterConfig implements Serializable { @Nested @@ -56,15 +56,28 @@ public class ExporterConfig implements Serializable { private String endpoint; /** - * Connection timeout for requests to Zipkin. + * Connection timeout for requests to Zipkin. (seconds) */ private Duration connectTimeout = Duration.ofSeconds(1); /** - * Read timeout for requests to Zipkin. + * Read timeout for requests to Zipkin. (seconds) */ private Duration readTimeout = Duration.ofSeconds(10); + public ZipkinConfig() { + } + + public ZipkinConfig(String endpoint) { + this.endpoint = endpoint; + } + + public ZipkinConfig(String endpoint, Duration connectTimeout, Duration readTimeout) { + this.endpoint = endpoint; + this.connectTimeout = connectTimeout; + this.readTimeout = readTimeout; + } + public String getEndpoint() { return endpoint; } @@ -98,7 +111,7 @@ public class ExporterConfig implements Serializable { private String endpoint; /** - * The maximum time to wait for the collector to process an exported batch of spans. + * The maximum time to wait for the collector to process an exported batch of spans. (seconds) */ private Duration timeout = Duration.ofSeconds(10); @@ -110,6 +123,24 @@ public class ExporterConfig implements Serializable { private Map headers = new HashMap<>(); + public OtlpConfig() { + } + + public OtlpConfig(String endpoint) { + this.endpoint = endpoint; + } + + public OtlpConfig(String endpoint, Duration timeout) { + this.endpoint = endpoint; + this.timeout = timeout; + } + + public OtlpConfig(String endpoint, Duration timeout, String compressionMethod) { + this.endpoint = endpoint; + this.timeout = timeout; + this.compressionMethod = compressionMethod; + } + public String getEndpoint() { return endpoint; } diff --git a/dubbo-common/src/main/java/org/apache/dubbo/config/nested/PropagationConfig.java b/dubbo-common/src/main/java/org/apache/dubbo/config/nested/PropagationConfig.java index 8e52353323..c574bd0e6d 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/config/nested/PropagationConfig.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/config/nested/PropagationConfig.java @@ -29,6 +29,13 @@ public class PropagationConfig implements Serializable { */ private String type = W3C; + public PropagationConfig() { + } + + public PropagationConfig(String type) { + this.type = type; + } + public String getType() { return type; } diff --git a/dubbo-common/src/main/java/org/apache/dubbo/config/nested/SamplingConfig.java b/dubbo-common/src/main/java/org/apache/dubbo/config/nested/SamplingConfig.java index a605527190..0e98a98b5f 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/config/nested/SamplingConfig.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/config/nested/SamplingConfig.java @@ -25,6 +25,13 @@ public class SamplingConfig implements Serializable { */ private float probability = 0.10f; + public SamplingConfig() { + } + + public SamplingConfig(float probability) { + this.probability = probability; + } + public float getProbability() { return this.probability; } diff --git a/dubbo-config/dubbo-config-api/pom.xml b/dubbo-config/dubbo-config-api/pom.xml index fec3459350..7bd4234ebd 100644 --- a/dubbo-config/dubbo-config-api/pom.xml +++ b/dubbo-config/dubbo-config-api/pom.xml @@ -72,6 +72,12 @@ ${project.parent.version} + + org.apache.dubbo + dubbo-tracing + ${project.parent.version} + + org.apache.dubbo dubbo-monitor-api diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/deploy/DefaultApplicationDeployer.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/deploy/DefaultApplicationDeployer.java index bf8d285681..af73f59ad2 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/deploy/DefaultApplicationDeployer.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/deploy/DefaultApplicationDeployer.java @@ -38,7 +38,6 @@ import org.apache.dubbo.common.logger.LoggerFactory; import org.apache.dubbo.common.threadpool.manager.ExecutorRepository; import org.apache.dubbo.common.threadpool.manager.FrameworkExecutorRepository; import org.apache.dubbo.common.utils.ArrayUtils; -import org.apache.dubbo.common.utils.ClassUtils; import org.apache.dubbo.common.utils.CollectionUtils; import org.apache.dubbo.common.utils.StringUtils; import org.apache.dubbo.config.ApplicationConfig; @@ -47,6 +46,7 @@ import org.apache.dubbo.config.DubboShutdownHook; import org.apache.dubbo.config.MetadataReportConfig; import org.apache.dubbo.config.MetricsConfig; import org.apache.dubbo.config.RegistryConfig; +import org.apache.dubbo.config.TracingConfig; import org.apache.dubbo.config.context.ConfigManager; import org.apache.dubbo.config.utils.CompositeReferenceCache; import org.apache.dubbo.config.utils.ConfigValidationUtils; @@ -60,6 +60,7 @@ import org.apache.dubbo.metrics.report.DefaultMetricsReporterFactory; import org.apache.dubbo.metrics.report.MetricsReporter; import org.apache.dubbo.metrics.report.MetricsReporterFactory; import org.apache.dubbo.metrics.service.MetricsServiceExporter; +import org.apache.dubbo.metrics.utils.MetricsSupportUtil; import org.apache.dubbo.registry.Registry; import org.apache.dubbo.registry.RegistryFactory; import org.apache.dubbo.registry.client.metadata.ServiceInstanceMetadataUtils; @@ -70,6 +71,8 @@ import org.apache.dubbo.rpc.model.ModuleServiceRepository; import org.apache.dubbo.rpc.model.ProviderModel; import org.apache.dubbo.rpc.model.ScopeModel; import org.apache.dubbo.rpc.model.ScopeModelUtil; +import org.apache.dubbo.tracing.DubboObservationRegistry; +import org.apache.dubbo.tracing.utils.ObservationSupportUtil; import java.io.IOException; import java.util.ArrayList; @@ -152,7 +155,7 @@ public class DefaultApplicationDeployer extends AbstractDeployer deployListeners = applicationModel.getExtensionLoader(ApplicationDeployListener.class) - .getSupportedExtensionInstances(); + .getSupportedExtensionInstances(); for (ApplicationDeployListener listener : deployListeners) { this.addDeployListener(listener); } @@ -226,6 +229,9 @@ public class DefaultApplicationDeployer extends AbstractDeployer defaultRegistries = configManager.getDefaultRegistries(); if (defaultRegistries.size() > 0) { defaultRegistries - .stream() - .filter(this::isUsedRegistryAsConfigCenter) - .map(this::registryAsConfigCenter) - .forEach(configCenter -> { - if (configManager.getConfigCenter(configCenter.getId()).isPresent()) { - return; - } - configManager.addConfigCenter(configCenter); - logger.info("use registry as config-center: " + configCenter); + .stream() + .filter(this::isUsedRegistryAsConfigCenter) + .map(this::registryAsConfigCenter) + .forEach(configCenter -> { + if (configManager.getConfigCenter(configCenter.getId()).isPresent()) { + return; + } + configManager.addConfigCenter(configCenter); + logger.info("use registry as config-center: " + configCenter); - }); + }); } } @@ -372,16 +378,16 @@ public class DefaultApplicationDeployer extends AbstractDeployer configOptional = configManager.getMetrics(); //If no specific metrics type is configured and there is no Prometheus dependency in the dependencies. MetricsConfig metricsConfig = configOptional.orElse(new MetricsConfig(applicationModel)); if (StringUtils.isBlank(metricsConfig.getProtocol())) { - metricsConfig.setProtocol(isSupportPrometheus() ? PROTOCOL_PROMETHEUS : PROTOCOL_DEFAULT); + metricsConfig.setProtocol(MetricsSupportUtil.isSupportPrometheus() ? PROTOCOL_PROMETHEUS : PROTOCOL_DEFAULT); } collector.setCollectEnabled(true); collector.collectApplication(); @@ -409,26 +415,35 @@ public class DefaultApplicationDeployer extends AbstractDeployer 1.10.0"); + } + return; + } + if (!ObservationSupportUtil.isSupportTracing()) { + if (logger.isDebugEnabled()) { + logger.debug("Not found micrometer-tracing dependency, skip init ObservationRegistry."); + } + return; + } + Optional configOptional = configManager.getTracing(); + if (!configOptional.isPresent() || !configOptional.get().getEnabled()) { + return; + } - public static boolean isSupportPrometheus() { - return isClassPresent("io.micrometer.prometheus.PrometheusConfig") - && isClassPresent("io.prometheus.client.exporter.BasicAuthHttpConnectionFactory") - && isClassPresent("io.prometheus.client.exporter.HttpConnectionFactory") - && isClassPresent("io.prometheus.client.exporter.PushGateway"); - } - - - private static boolean isClassPresent(String className) { - return ClassUtils.isPresent(className, DefaultApplicationDeployer.class.getClassLoader()); + DubboObservationRegistry dubboObservationRegistry = new DubboObservationRegistry(applicationModel, configOptional.get()); + dubboObservationRegistry.initObservationRegistry(); } private boolean isUsedRegistryAsConfigCenter(RegistryConfig registryConfig) { return isUsedRegistryAsCenter(registryConfig, registryConfig::getUseAsConfigCenter, "config", - DynamicConfigurationFactory.class); + DynamicConfigurationFactory.class); } private ConfigCenterConfig registryAsConfigCenter(RegistryConfig registryConfig) { @@ -470,9 +485,9 @@ public class DefaultApplicationDeployer extends AbstractDeployer metadataConfigsToOverride = originMetadataConfigs - .stream() - .filter(m -> Objects.isNull(m.getAddress())) - .collect(Collectors.toList()); + .stream() + .filter(m -> Objects.isNull(m.getAddress())) + .collect(Collectors.toList()); if (metadataConfigsToOverride.size() > 1) { return; @@ -483,12 +498,12 @@ public class DefaultApplicationDeployer extends AbstractDeployer defaultRegistries = configManager.getDefaultRegistries(); if (!defaultRegistries.isEmpty()) { defaultRegistries - .stream() - .filter(this::isUsedRegistryAsMetadataCenter) - .map(registryConfig -> registryAsMetadataCenter(registryConfig, metadataConfigToOverride)) - .forEach(metadataReportConfig -> { - overrideMetadataReportConfig(metadataConfigToOverride, metadataReportConfig); - }); + .stream() + .filter(this::isUsedRegistryAsMetadataCenter) + .map(registryConfig -> registryAsMetadataCenter(registryConfig, metadataConfigToOverride)) + .forEach(metadataReportConfig -> { + overrideMetadataReportConfig(metadataConfigToOverride, metadataReportConfig); + }); } } @@ -517,7 +532,7 @@ public class DefaultApplicationDeployer extends AbstractDeployer { - ServiceInstanceMetadataUtils.registerMetadataAndInstance(applicationModel); - return null; - } + () -> { + ServiceInstanceMetadataUtils.registerMetadataAndInstance(applicationModel); + return null; + } ); } catch (Exception e) { logger.error(CONFIG_REGISTER_INSTANCE_ERROR, "configuration server disconnected", "", "Register instance error.", e); @@ -1017,7 +1032,7 @@ public class DefaultApplicationDeployer extends AbstractDeployer1.8.0 0.1.35 1.11.0 - + 1.26.0 + 2.16.4 1.1.1 3.3 0.16.0 @@ -231,6 +232,20 @@ pom import + + io.opentelemetry + opentelemetry-bom + ${opentelemetry.version} + pom + import + + + io.zipkin.reporter2 + zipkin-reporter-bom + ${zipkin-reporter.version} + pom + import + io.netty netty-all diff --git a/dubbo-distribution/dubbo-all/pom.xml b/dubbo-distribution/dubbo-all/pom.xml index 3951a9fd9d..76fc002d1c 100644 --- a/dubbo-distribution/dubbo-all/pom.xml +++ b/dubbo-distribution/dubbo-all/pom.xml @@ -219,6 +219,15 @@ true + + + org.apache.dubbo + dubbo-tracing + ${project.version} + compile + true + + org.apache.dubbo @@ -530,6 +539,7 @@ org.apache.dubbo:dubbo-metrics-metadata org.apache.dubbo:dubbo-metrics-config-center org.apache.dubbo:dubbo-metrics-prometheus + org.apache.dubbo:dubbo-tracing org.apache.dubbo:dubbo-monitor-api org.apache.dubbo:dubbo-monitor-default org.apache.dubbo:dubbo-qos diff --git a/dubbo-distribution/dubbo-bom/pom.xml b/dubbo-distribution/dubbo-bom/pom.xml index 2d163f10e8..dac1366414 100644 --- a/dubbo-distribution/dubbo-bom/pom.xml +++ b/dubbo-distribution/dubbo-bom/pom.xml @@ -256,6 +256,13 @@ ${project.version} + + + org.apache.dubbo + dubbo-tracing + ${project.version} + + org.apache.dubbo diff --git a/dubbo-distribution/dubbo-core-spi/pom.xml b/dubbo-distribution/dubbo-core-spi/pom.xml index 88939753e9..2a441485f8 100644 --- a/dubbo-distribution/dubbo-core-spi/pom.xml +++ b/dubbo-distribution/dubbo-core-spi/pom.xml @@ -134,6 +134,7 @@ org.apache.dubbo:dubbo-metadata-api org.apache.dubbo:dubbo-metrics-api org.apache.dubbo:dubbo-metrics-default + org.apache.dubbo:dubbo-tracing org.apache.dubbo:dubbo-monitor-api org.apache.dubbo:dubbo-registry-api org.apache.dubbo:dubbo-remoting-api diff --git a/dubbo-metrics/dubbo-metrics-api/pom.xml b/dubbo-metrics/dubbo-metrics-api/pom.xml index a35c238395..3c31ae389c 100644 --- a/dubbo-metrics/dubbo-metrics-api/pom.xml +++ b/dubbo-metrics/dubbo-metrics-api/pom.xml @@ -49,10 +49,5 @@ com.tdunning t-digest - - io.micrometer - micrometer-tracing-integration-test - test - diff --git a/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/aggregate/Pane.java b/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/aggregate/Pane.java old mode 100755 new mode 100644 diff --git a/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/aggregate/SlidingWindow.java b/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/aggregate/SlidingWindow.java old mode 100755 new mode 100644 diff --git a/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/utils/MetricsSupportUtil.java b/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/utils/MetricsSupportUtil.java new file mode 100644 index 0000000000..e0a02f5f04 --- /dev/null +++ b/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/utils/MetricsSupportUtil.java @@ -0,0 +1,38 @@ +/* + * 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.utils; + +import org.apache.dubbo.common.utils.ClassUtils; + +public class MetricsSupportUtil { + + public static boolean isSupportMetrics() { + return isClassPresent("io.micrometer.core.instrument.MeterRegistry"); + } + + public static boolean isSupportPrometheus() { + return isClassPresent("io.micrometer.prometheus.PrometheusConfig") + && isClassPresent("io.prometheus.client.exporter.BasicAuthHttpConnectionFactory") + && isClassPresent("io.prometheus.client.exporter.HttpConnectionFactory") + && isClassPresent("io.prometheus.client.exporter.PushGateway"); + } + + private static boolean isClassPresent(String className) { + return ClassUtils.isPresent(className, MetricsSupportUtil.class.getClassLoader()); + } +} diff --git a/dubbo-metrics/dubbo-metrics-api/src/test/java/org/apache/dubbo/metrics/aggregate/TimeWindowAggregatorTest.java b/dubbo-metrics/dubbo-metrics-api/src/test/java/org/apache/dubbo/metrics/aggregate/TimeWindowAggregatorTest.java index e0db96730f..2a660a5dd4 100644 --- a/dubbo-metrics/dubbo-metrics-api/src/test/java/org/apache/dubbo/metrics/aggregate/TimeWindowAggregatorTest.java +++ b/dubbo-metrics/dubbo-metrics-api/src/test/java/org/apache/dubbo/metrics/aggregate/TimeWindowAggregatorTest.java @@ -17,8 +17,9 @@ package org.apache.dubbo.metrics.aggregate; -import org.junit.Test; + import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import java.util.concurrent.TimeUnit; diff --git a/dubbo-metrics/dubbo-metrics-default/pom.xml b/dubbo-metrics/dubbo-metrics-default/pom.xml index 71be413c6a..0d2fd8a6bf 100644 --- a/dubbo-metrics/dubbo-metrics-default/pom.xml +++ b/dubbo-metrics/dubbo-metrics-default/pom.xml @@ -41,10 +41,5 @@ micrometer-test test - - io.micrometer - micrometer-tracing-integration-test - test - diff --git a/dubbo-metrics/dubbo-metrics-default/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.Filter b/dubbo-metrics/dubbo-metrics-default/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.Filter deleted file mode 100644 index 5ee6c1d455..0000000000 --- a/dubbo-metrics/dubbo-metrics-default/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.Filter +++ /dev/null @@ -1,2 +0,0 @@ -metrics-beta=org.apache.dubbo.metrics.filter.MetricsFilter -observationreceiver=org.apache.dubbo.metrics.observation.ObservationReceiverFilter \ No newline at end of file diff --git a/dubbo-metrics/dubbo-tracing/pom.xml b/dubbo-metrics/dubbo-tracing/pom.xml new file mode 100644 index 0000000000..e50dae23bd --- /dev/null +++ b/dubbo-metrics/dubbo-tracing/pom.xml @@ -0,0 +1,111 @@ + + + 4.0.0 + + org.apache.dubbo + dubbo-metrics + ${revision} + ../pom.xml + + + dubbo-tracing + jar + ${project.artifactId} + The tracing module of dubbo project + + + 11 + 11 + UTF-8 + false + + + + + org.apache.dubbo + dubbo-common + ${project.parent.version} + + + org.apache.dubbo + dubbo-cluster + ${project.parent.version} + + + org.apache.dubbo + dubbo-rpc-api + ${project.parent.version} + + + org.apache.dubbo + dubbo-metrics-default + ${project.parent.version} + + + + + io.micrometer + micrometer-core + + + io.micrometer + micrometer-tracing + + + io.micrometer + micrometer-test + test + + + io.micrometer + micrometer-tracing-integration-test + test + + + + + io.micrometer + micrometer-tracing-bridge-otel + true + + + io.micrometer + micrometer-tracing-bridge-brave + true + + + + + io.opentelemetry + opentelemetry-exporter-zipkin + true + + + io.opentelemetry + opentelemetry-exporter-otlp + true + + + io.zipkin.reporter2 + zipkin-reporter-brave + true + + + \ No newline at end of file diff --git a/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/observation/AbstractDefaultDubboObservationConvention.java b/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/AbstractDefaultDubboObservationConvention.java similarity index 87% rename from dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/observation/AbstractDefaultDubboObservationConvention.java rename to dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/AbstractDefaultDubboObservationConvention.java index 8d8e963868..a688a4c826 100644 --- a/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/observation/AbstractDefaultDubboObservationConvention.java +++ b/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/AbstractDefaultDubboObservationConvention.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.metrics.observation; +package org.apache.dubbo.tracing; import io.micrometer.common.KeyValues; import io.micrometer.common.docs.KeyName; @@ -25,9 +25,9 @@ import org.apache.dubbo.common.utils.StringUtils; import org.apache.dubbo.rpc.Invocation; import org.apache.dubbo.rpc.support.RpcUtils; -import static org.apache.dubbo.metrics.observation.DubboObservationDocumentation.LowCardinalityKeyNames.RPC_METHOD; -import static org.apache.dubbo.metrics.observation.DubboObservationDocumentation.LowCardinalityKeyNames.RPC_SERVICE; -import static org.apache.dubbo.metrics.observation.DubboObservationDocumentation.LowCardinalityKeyNames.RPC_SYSTEM; +import static org.apache.dubbo.tracing.DubboObservationDocumentation.LowCardinalityKeyNames.RPC_METHOD; +import static org.apache.dubbo.tracing.DubboObservationDocumentation.LowCardinalityKeyNames.RPC_SERVICE; +import static org.apache.dubbo.tracing.DubboObservationDocumentation.LowCardinalityKeyNames.RPC_SYSTEM; class AbstractDefaultDubboObservationConvention { KeyValues getLowCardinalityKeyValues(Invocation invocation) { diff --git a/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/observation/DefaultDubboClientObservationConvention.java b/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/DefaultDubboClientObservationConvention.java similarity index 92% rename from dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/observation/DefaultDubboClientObservationConvention.java rename to dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/DefaultDubboClientObservationConvention.java index 91e88da2a3..481861d1f9 100644 --- a/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/observation/DefaultDubboClientObservationConvention.java +++ b/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/DefaultDubboClientObservationConvention.java @@ -14,19 +14,20 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.metrics.observation; +package org.apache.dubbo.tracing; import org.apache.dubbo.common.URL; import org.apache.dubbo.rpc.Invoker; import org.apache.dubbo.rpc.RpcContext; import org.apache.dubbo.rpc.RpcContextAttachment; +import org.apache.dubbo.tracing.context.DubboClientContext; import io.micrometer.common.KeyValues; import java.util.List; -import static org.apache.dubbo.metrics.observation.DubboObservationDocumentation.LowCardinalityKeyNames.NET_PEER_NAME; -import static org.apache.dubbo.metrics.observation.DubboObservationDocumentation.LowCardinalityKeyNames.NET_PEER_PORT; +import static org.apache.dubbo.tracing.DubboObservationDocumentation.LowCardinalityKeyNames.NET_PEER_NAME; +import static org.apache.dubbo.tracing.DubboObservationDocumentation.LowCardinalityKeyNames.NET_PEER_PORT; /** * Default implementation of the {@link DubboClientObservationConvention}. diff --git a/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/observation/DefaultDubboServerObservationConvention.java b/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/DefaultDubboServerObservationConvention.java similarity index 94% rename from dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/observation/DefaultDubboServerObservationConvention.java rename to dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/DefaultDubboServerObservationConvention.java index adcebdbdac..c78be59806 100644 --- a/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/observation/DefaultDubboServerObservationConvention.java +++ b/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/DefaultDubboServerObservationConvention.java @@ -14,7 +14,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.metrics.observation; +package org.apache.dubbo.tracing; + +import org.apache.dubbo.tracing.context.DubboServerContext; import io.micrometer.common.KeyValues; diff --git a/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/observation/DubboClientObservationConvention.java b/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/DubboClientObservationConvention.java similarity index 92% rename from dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/observation/DubboClientObservationConvention.java rename to dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/DubboClientObservationConvention.java index d33164294d..5bd74dec50 100644 --- a/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/observation/DubboClientObservationConvention.java +++ b/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/DubboClientObservationConvention.java @@ -14,7 +14,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.metrics.observation; +package org.apache.dubbo.tracing; + +import org.apache.dubbo.tracing.context.DubboClientContext; import io.micrometer.observation.Observation; import io.micrometer.observation.ObservationConvention; diff --git a/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/observation/DubboObservationDocumentation.java b/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/DubboObservationDocumentation.java similarity index 98% rename from dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/observation/DubboObservationDocumentation.java rename to dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/DubboObservationDocumentation.java index 855a2e01e1..cd0dfe3d61 100644 --- a/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/observation/DubboObservationDocumentation.java +++ b/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/DubboObservationDocumentation.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.metrics.observation; +package org.apache.dubbo.tracing; import io.micrometer.common.docs.KeyName; import io.micrometer.common.lang.NonNullApi; diff --git a/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/DubboObservationRegistry.java b/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/DubboObservationRegistry.java new file mode 100644 index 0000000000..a8497d998b --- /dev/null +++ b/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/DubboObservationRegistry.java @@ -0,0 +1,90 @@ +/* + * 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.tracing; + +import org.apache.dubbo.common.logger.ErrorTypeAwareLogger; +import org.apache.dubbo.common.logger.LoggerFactory; +import org.apache.dubbo.common.utils.JsonUtils; +import org.apache.dubbo.config.TracingConfig; +import org.apache.dubbo.metrics.MetricsGlobalRegistry; +import org.apache.dubbo.metrics.utils.MetricsSupportUtil; +import org.apache.dubbo.rpc.model.ApplicationModel; +import org.apache.dubbo.tracing.tracer.PropagatorProvider; +import org.apache.dubbo.tracing.tracer.PropagatorProviderFactory; +import org.apache.dubbo.tracing.tracer.TracerProvider; +import org.apache.dubbo.tracing.tracer.TracerProviderFactory; + +import static org.apache.dubbo.common.constants.LoggerCodeConstants.COMMON_NOT_FOUND_TRACER_DEPENDENCY; + +public class DubboObservationRegistry { + + private static final ErrorTypeAwareLogger logger = LoggerFactory.getErrorTypeAwareLogger(DubboObservationRegistry.class); + + private final ApplicationModel applicationModel; + + private final TracingConfig tracingConfig; + + public DubboObservationRegistry(ApplicationModel applicationModel, TracingConfig tracingConfig) { + this.applicationModel = applicationModel; + this.tracingConfig = tracingConfig; + } + + public void initObservationRegistry() { + // If get ObservationRegistry.class from external(eg Spring.), use external. + io.micrometer.observation.ObservationRegistry externalObservationRegistry = applicationModel.getBeanFactory().getBean(io.micrometer.observation.ObservationRegistry.class); + if (externalObservationRegistry != null) { + if (logger.isDebugEnabled()) { + logger.debug("ObservationRegistry.class from external is existed."); + } + return; + } + + if (logger.isDebugEnabled()) { + logger.debug("Tracing config is: " + JsonUtils.toJson(tracingConfig)); + } + + TracerProvider tracerProvider = TracerProviderFactory.getProvider(applicationModel, tracingConfig); + if (tracerProvider == null) { + logger.warn(COMMON_NOT_FOUND_TRACER_DEPENDENCY, "", "", "Can not found OpenTelemetry/Brave tracer dependencies, skip init ObservationRegistry."); + return; + } + // The real tracer will come from tracer implementation (OTel / Brave) + io.micrometer.tracing.Tracer tracer = tracerProvider.getTracer(); + + // The real propagator will come from tracer implementation (OTel / Brave) + PropagatorProvider propagatorProvider = PropagatorProviderFactory.getPropagatorProvider(); + io.micrometer.tracing.propagation.Propagator propagator = propagatorProvider != null ? propagatorProvider.getPropagator() : io.micrometer.tracing.propagation.Propagator.NOOP; + + io.micrometer.observation.ObservationRegistry registry = io.micrometer.observation.ObservationRegistry.create(); + registry.observationConfig() + // set up a first matching handler that creates spans - it comes from Micrometer Tracing. + // set up spans for sending and receiving data over the wire and a default one. + .observationHandler(new io.micrometer.observation.ObservationHandler.FirstMatchingCompositeObservationHandler( + new io.micrometer.tracing.handler.PropagatingSenderTracingObservationHandler<>(tracer, propagator), + new io.micrometer.tracing.handler.PropagatingReceiverTracingObservationHandler<>(tracer, propagator), + new io.micrometer.tracing.handler.DefaultTracingObservationHandler(tracer))); + + if (MetricsSupportUtil.isSupportMetrics()) { + io.micrometer.core.instrument.MeterRegistry meterRegistry = MetricsGlobalRegistry.getCompositeRegistry(applicationModel); + registry.observationConfig().observationHandler(new io.micrometer.core.instrument.observation.DefaultMeterObservationHandler(meterRegistry)); + } + + applicationModel.getBeanFactory().registerBean(registry); + applicationModel.getBeanFactory().registerBean(tracer); + applicationModel.getBeanFactory().registerBean(propagator); + } +} diff --git a/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/observation/DubboServerObservationConvention.java b/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/DubboServerObservationConvention.java similarity index 92% rename from dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/observation/DubboServerObservationConvention.java rename to dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/DubboServerObservationConvention.java index 678226ee7f..0f7917aded 100644 --- a/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/observation/DubboServerObservationConvention.java +++ b/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/DubboServerObservationConvention.java @@ -14,7 +14,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.metrics.observation; +package org.apache.dubbo.tracing; + +import org.apache.dubbo.tracing.context.DubboServerContext; import io.micrometer.observation.Observation; import io.micrometer.observation.ObservationConvention; diff --git a/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/observation/DubboClientContext.java b/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/context/DubboClientContext.java similarity index 97% rename from dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/observation/DubboClientContext.java rename to dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/context/DubboClientContext.java index 6cd559fa1e..f1998bc91a 100644 --- a/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/observation/DubboClientContext.java +++ b/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/context/DubboClientContext.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.metrics.observation; +package org.apache.dubbo.tracing.context; import java.util.Objects; diff --git a/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/observation/DubboServerContext.java b/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/context/DubboServerContext.java similarity index 97% rename from dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/observation/DubboServerContext.java rename to dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/context/DubboServerContext.java index d4ad9d97f3..3e5bd13fae 100644 --- a/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/observation/DubboServerContext.java +++ b/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/context/DubboServerContext.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.metrics.observation; +package org.apache.dubbo.tracing.context; import io.micrometer.observation.transport.ReceiverContext; import org.apache.dubbo.rpc.Invocation; diff --git a/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/exporter/TraceExporter.java b/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/exporter/TraceExporter.java new file mode 100644 index 0000000000..9b8f12ee4b --- /dev/null +++ b/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/exporter/TraceExporter.java @@ -0,0 +1,37 @@ +/* + * 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.tracing.exporter; + +import brave.handler.SpanHandler; +import io.opentelemetry.sdk.trace.export.SpanExporter; + +public interface TraceExporter { + + /** + * for otel + * + * @return + */ + SpanExporter getSpanExporter(); + + /** + * for brave + * + * @return + */ + SpanHandler getSpanHandler(); +} diff --git a/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/exporter/TraceExporterFactory.java b/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/exporter/TraceExporterFactory.java new file mode 100644 index 0000000000..7327cf038e --- /dev/null +++ b/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/exporter/TraceExporterFactory.java @@ -0,0 +1,66 @@ +/* + * 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.tracing.exporter; + +import org.apache.dubbo.common.logger.ErrorTypeAwareLogger; +import org.apache.dubbo.common.logger.LoggerFactory; +import org.apache.dubbo.common.utils.StringUtils; +import org.apache.dubbo.config.nested.ExporterConfig; +import org.apache.dubbo.rpc.model.ApplicationModel; +import org.apache.dubbo.tracing.exporter.otlp.OTlpExporter; +import org.apache.dubbo.tracing.exporter.zipkin.ZipkinExporter; + +import brave.handler.SpanHandler; +import io.opentelemetry.sdk.trace.export.SpanExporter; + +import java.util.ArrayList; +import java.util.List; + +public class TraceExporterFactory { + + private final static ErrorTypeAwareLogger LOGGER = LoggerFactory.getErrorTypeAwareLogger(TraceExporterFactory.class); + + /** + * for OTel + */ + public static List getSpanExporters(ApplicationModel applicationModel, ExporterConfig exporterConfig) { + ExporterConfig.ZipkinConfig zipkinConfig = exporterConfig.getZipkinConfig(); + ExporterConfig.OtlpConfig otlpConfig = exporterConfig.getOtlpConfig(); + List res = new ArrayList<>(); + if (zipkinConfig != null && StringUtils.isNotEmpty(zipkinConfig.getEndpoint())) { + ZipkinExporter zipkinExporter = new ZipkinExporter(applicationModel, zipkinConfig); + LOGGER.info("Create zipkin span exporter."); + res.add(zipkinExporter.getSpanExporter()); + } + if (otlpConfig != null && StringUtils.isNotEmpty(otlpConfig.getEndpoint())) { + OTlpExporter otlpExporter = new OTlpExporter(applicationModel, otlpConfig); + LOGGER.info("Create OTlp span exporter."); + res.add(otlpExporter.getSpanExporter()); + } + + return res; + } + + /** + * for Brave + */ + public static List getSpanHandlers(ApplicationModel applicationModel, ExporterConfig exporterConfig) { + List res = new ArrayList<>(); + // TODO brave SpanHandler impl + return res; + } +} diff --git a/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/exporter/otlp/OTlpExporter.java b/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/exporter/otlp/OTlpExporter.java new file mode 100644 index 0000000000..72da78a795 --- /dev/null +++ b/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/exporter/otlp/OTlpExporter.java @@ -0,0 +1,66 @@ +/* + * 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.tracing.exporter.otlp; + +import org.apache.dubbo.config.nested.ExporterConfig; +import org.apache.dubbo.rpc.model.ApplicationModel; +import org.apache.dubbo.tracing.exporter.TraceExporter; + +import brave.handler.SpanHandler; +import io.opentelemetry.exporter.otlp.http.trace.OtlpHttpSpanExporter; +import io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporter; +import io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporterBuilder; +import io.opentelemetry.sdk.trace.export.SpanExporter; + +import java.util.Map; + +public class OTlpExporter implements TraceExporter { + + private final ApplicationModel applicationModel; + private final ExporterConfig.OtlpConfig otlpConfig; + + public OTlpExporter(ApplicationModel applicationModel, ExporterConfig.OtlpConfig otlpConfig) { + this.applicationModel = applicationModel; + this.otlpConfig = otlpConfig; + } + + @Override + public SpanExporter getSpanExporter() { + OtlpGrpcSpanExporter externalOTlpGrpcSpanExporter = applicationModel.getBeanFactory().getBean(OtlpGrpcSpanExporter.class); + if (externalOTlpGrpcSpanExporter != null) { + return externalOTlpGrpcSpanExporter; + } + OtlpHttpSpanExporter externalOtlpHttpSpanExporter = applicationModel.getBeanFactory().getBean(OtlpHttpSpanExporter.class); + if (externalOtlpHttpSpanExporter != null) { + return externalOtlpHttpSpanExporter; + } + OtlpGrpcSpanExporterBuilder builder = OtlpGrpcSpanExporter.builder() + .setEndpoint(otlpConfig.getEndpoint()) + .setTimeout(otlpConfig.getTimeout()) + .setCompression(otlpConfig.getCompressionMethod()); + for (Map.Entry entry : otlpConfig.getHeaders().entrySet()) { + builder.addHeader(entry.getKey(), entry.getValue()); + } + return builder.build(); + } + + @Override + public SpanHandler getSpanHandler() { + // OTlp is only belong to OTel. + return null; + } +} diff --git a/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/exporter/zipkin/ZipkinExporter.java b/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/exporter/zipkin/ZipkinExporter.java new file mode 100644 index 0000000000..c0c00c6fa8 --- /dev/null +++ b/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/exporter/zipkin/ZipkinExporter.java @@ -0,0 +1,60 @@ +/* + * 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.tracing.exporter.zipkin; + +import org.apache.dubbo.config.nested.ExporterConfig; +import org.apache.dubbo.rpc.model.ApplicationModel; +import org.apache.dubbo.tracing.exporter.TraceExporter; + +import brave.handler.SpanHandler; +import io.opentelemetry.exporter.zipkin.ZipkinSpanExporter; +import io.opentelemetry.sdk.trace.export.SpanExporter; +import zipkin2.Span; +import zipkin2.codec.BytesEncoder; +import zipkin2.codec.SpanBytesEncoder; + +public class ZipkinExporter implements TraceExporter { + + private final ApplicationModel applicationModel; + private final ExporterConfig.ZipkinConfig zipkinConfig; + + public ZipkinExporter(ApplicationModel applicationModel, ExporterConfig.ZipkinConfig zipkinConfig) { + this.applicationModel = applicationModel; + this.zipkinConfig = zipkinConfig; + } + + @Override + public SpanExporter getSpanExporter() { + BytesEncoder encoder = getSpanBytesEncoder(); + return ZipkinSpanExporter.builder() + .setEncoder(encoder) + .setEndpoint(zipkinConfig.getEndpoint()) + .setReadTimeout(zipkinConfig.getReadTimeout()) + .build(); + } + + @Override + public SpanHandler getSpanHandler() { + // TODO SpanHandler of Brave impl + return null; + } + + private BytesEncoder getSpanBytesEncoder() { + BytesEncoder encoder = applicationModel.getBeanFactory().getBean(BytesEncoder.class); + return encoder == null ? SpanBytesEncoder.JSON_V2 : encoder; + } +} diff --git a/dubbo-metrics/dubbo-metrics-default/src/main/java/org/apache/dubbo/metrics/observation/ObservationReceiverFilter.java b/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/filter/ObservationReceiverFilter.java similarity index 80% rename from dubbo-metrics/dubbo-metrics-default/src/main/java/org/apache/dubbo/metrics/observation/ObservationReceiverFilter.java rename to dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/filter/ObservationReceiverFilter.java index 5a33ced437..25b7008c67 100644 --- a/dubbo-metrics/dubbo-metrics-default/src/main/java/org/apache/dubbo/metrics/observation/ObservationReceiverFilter.java +++ b/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/filter/ObservationReceiverFilter.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.metrics.observation; +package org.apache.dubbo.tracing.filter; import org.apache.dubbo.common.extension.Activate; import org.apache.dubbo.rpc.BaseFilter; @@ -25,6 +25,10 @@ import org.apache.dubbo.rpc.Result; import org.apache.dubbo.rpc.RpcException; import org.apache.dubbo.rpc.model.ApplicationModel; import org.apache.dubbo.rpc.model.ScopeModelAware; +import org.apache.dubbo.tracing.DefaultDubboServerObservationConvention; +import org.apache.dubbo.tracing.DubboObservationDocumentation; +import org.apache.dubbo.tracing.DubboServerObservationConvention; +import org.apache.dubbo.tracing.context.DubboServerContext; import io.micrometer.observation.Observation; import io.micrometer.observation.ObservationRegistry; @@ -34,7 +38,7 @@ import static org.apache.dubbo.common.constants.CommonConstants.PROVIDER; /** * A {@link Filter} that creates an {@link Observation} around the incoming message. */ -@Activate(group = PROVIDER, order = -1, onClass = "io.micrometer.observation.NoopObservationRegistry") +@Activate(group = PROVIDER, order = Integer.MIN_VALUE + 50, onClass = "io.micrometer.observation.NoopObservationRegistry") public class ObservationReceiverFilter implements Filter, BaseFilter.Listener, ScopeModelAware { private ObservationRegistry observationRegistry; @@ -42,12 +46,8 @@ public class ObservationReceiverFilter implements Filter, BaseFilter.Listener, S private DubboServerObservationConvention serverObservationConvention; public ObservationReceiverFilter(ApplicationModel applicationModel) { - applicationModel.getApplicationConfigManager().getTracing().ifPresent(cfg -> { - if (Boolean.TRUE.equals(cfg.getEnabled())) { - observationRegistry = applicationModel.getBeanFactory().getBean(ObservationRegistry.class); - serverObservationConvention = applicationModel.getBeanFactory().getBean(DubboServerObservationConvention.class); - } - }); + observationRegistry = applicationModel.getBeanFactory().getBean(ObservationRegistry.class); + serverObservationConvention = applicationModel.getBeanFactory().getBean(DubboServerObservationConvention.class); } @Override @@ -70,6 +70,9 @@ public class ObservationReceiverFilter implements Filter, BaseFilter.Listener, S if (observation == null) { return; } + if (appResponse != null && appResponse.hasException()) { + observation.error(appResponse.getException()); + } observation.stop(); } diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/filter/support/ObservationSenderFilter.java b/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/filter/ObservationSenderFilter.java similarity index 78% rename from dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/filter/support/ObservationSenderFilter.java rename to dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/filter/ObservationSenderFilter.java index 233a5ed35b..bce47b7b9a 100644 --- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/filter/support/ObservationSenderFilter.java +++ b/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/filter/ObservationSenderFilter.java @@ -14,13 +14,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.rpc.cluster.filter.support; +package org.apache.dubbo.tracing.filter; import org.apache.dubbo.common.extension.Activate; -import org.apache.dubbo.metrics.observation.DefaultDubboClientObservationConvention; -import org.apache.dubbo.metrics.observation.DubboClientContext; -import org.apache.dubbo.metrics.observation.DubboClientObservationConvention; -import org.apache.dubbo.metrics.observation.DubboObservationDocumentation; import org.apache.dubbo.rpc.BaseFilter; import org.apache.dubbo.rpc.Filter; import org.apache.dubbo.rpc.Invocation; @@ -30,6 +26,10 @@ import org.apache.dubbo.rpc.RpcException; import org.apache.dubbo.rpc.cluster.filter.ClusterFilter; import org.apache.dubbo.rpc.model.ApplicationModel; import org.apache.dubbo.rpc.model.ScopeModelAware; +import org.apache.dubbo.tracing.DefaultDubboClientObservationConvention; +import org.apache.dubbo.tracing.DubboClientObservationConvention; +import org.apache.dubbo.tracing.DubboObservationDocumentation; +import org.apache.dubbo.tracing.context.DubboClientContext; import io.micrometer.observation.Observation; import io.micrometer.observation.ObservationRegistry; @@ -39,7 +39,7 @@ import static org.apache.dubbo.common.constants.CommonConstants.CONSUMER; /** * A {@link Filter} that creates an {@link Observation} around the outgoing message. */ -@Activate(group = CONSUMER, order = -1, onClass = "io.micrometer.observation.NoopObservationRegistry") +@Activate(group = CONSUMER, order = Integer.MIN_VALUE + 50, onClass = "io.micrometer.observation.NoopObservationRegistry") public class ObservationSenderFilter implements ClusterFilter, BaseFilter.Listener, ScopeModelAware { private ObservationRegistry observationRegistry; @@ -47,12 +47,8 @@ public class ObservationSenderFilter implements ClusterFilter, BaseFilter.Listen private DubboClientObservationConvention clientObservationConvention; public ObservationSenderFilter(ApplicationModel applicationModel) { - applicationModel.getApplicationConfigManager().getTracing().ifPresent(cfg -> { - if (Boolean.TRUE.equals(cfg.getEnabled())) { - observationRegistry = applicationModel.getBeanFactory().getBean(ObservationRegistry.class); - clientObservationConvention = applicationModel.getBeanFactory().getBean(DubboClientObservationConvention.class); - } - }); + observationRegistry = applicationModel.getBeanFactory().getBean(ObservationRegistry.class); + clientObservationConvention = applicationModel.getBeanFactory().getBean(DubboClientObservationConvention.class); } @Override @@ -75,6 +71,9 @@ public class ObservationSenderFilter implements ClusterFilter, BaseFilter.Listen if (observation == null) { return; } + if (appResponse != null && appResponse.hasException()) { + observation.error(appResponse.getException()); + } observation.stop(); } diff --git a/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/tracer/PropagatorProvider.java b/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/tracer/PropagatorProvider.java new file mode 100644 index 0000000000..dc9b58f4e0 --- /dev/null +++ b/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/tracer/PropagatorProvider.java @@ -0,0 +1,29 @@ +/* + * 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.tracing.tracer; + +import io.micrometer.tracing.propagation.Propagator; + +public interface PropagatorProvider { + + /** + * The real propagator will come from tracer implementation (OTel / Brave) + * + * @return Propagator + */ + Propagator getPropagator(); +} diff --git a/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/tracer/PropagatorProviderFactory.java b/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/tracer/PropagatorProviderFactory.java new file mode 100644 index 0000000000..066cb7ad63 --- /dev/null +++ b/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/tracer/PropagatorProviderFactory.java @@ -0,0 +1,37 @@ +/* + * 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.tracing.tracer; + +import org.apache.dubbo.tracing.tracer.brave.BravePropagatorProvider; +import org.apache.dubbo.tracing.tracer.otel.OTelPropagatorProvider; +import org.apache.dubbo.tracing.utils.ObservationSupportUtil; + +public class PropagatorProviderFactory { + + public static PropagatorProvider getPropagatorProvider() { + // If support OTel firstly, return OTel, then Brave. + if (ObservationSupportUtil.isSupportOTelTracer()) { + return new OTelPropagatorProvider(); + } + + if (ObservationSupportUtil.isSupportBraveTracer()) { + return new BravePropagatorProvider(); + } + + return null; + } +} diff --git a/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/tracer/TracerProvider.java b/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/tracer/TracerProvider.java new file mode 100644 index 0000000000..05305ada67 --- /dev/null +++ b/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/tracer/TracerProvider.java @@ -0,0 +1,30 @@ +/* + * 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.tracing.tracer; + +import io.micrometer.tracing.Tracer; + +public interface TracerProvider { + + /** + * Tracer of Micrometer. The real tracer will come from tracer implementation (OTel / Brave) + * + * @return Tracer + */ + Tracer getTracer(); + +} diff --git a/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/tracer/TracerProviderFactory.java b/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/tracer/TracerProviderFactory.java new file mode 100644 index 0000000000..7e325809cb --- /dev/null +++ b/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/tracer/TracerProviderFactory.java @@ -0,0 +1,39 @@ +/* + * 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.tracing.tracer; + +import org.apache.dubbo.config.TracingConfig; +import org.apache.dubbo.rpc.model.ApplicationModel; +import org.apache.dubbo.tracing.tracer.brave.BraveProvider; +import org.apache.dubbo.tracing.tracer.otel.OpenTelemetryProvider; +import org.apache.dubbo.tracing.utils.ObservationSupportUtil; + +public class TracerProviderFactory { + + public static TracerProvider getProvider(ApplicationModel applicationModel, TracingConfig tracingConfig) { + // If support OTel firstly, return OTel, then Brave. + if (ObservationSupportUtil.isSupportOTelTracer()) { + return new OpenTelemetryProvider(applicationModel, tracingConfig); + } + + if (ObservationSupportUtil.isSupportBraveTracer()) { + return new BraveProvider(applicationModel, tracingConfig); + } + + return null; + } +} diff --git a/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/tracer/brave/BravePropagatorProvider.java b/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/tracer/brave/BravePropagatorProvider.java new file mode 100644 index 0000000000..8560a5b149 --- /dev/null +++ b/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/tracer/brave/BravePropagatorProvider.java @@ -0,0 +1,31 @@ +/* + * 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.tracing.tracer.brave; + +import org.apache.dubbo.tracing.tracer.PropagatorProvider; + +import io.micrometer.tracing.propagation.Propagator; + + +public class BravePropagatorProvider implements PropagatorProvider { + + @Override + public Propagator getPropagator() { + // TODO impl + return null; + } +} diff --git a/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/tracer/brave/BraveProvider.java b/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/tracer/brave/BraveProvider.java new file mode 100644 index 0000000000..9ab8172b02 --- /dev/null +++ b/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/tracer/brave/BraveProvider.java @@ -0,0 +1,41 @@ +/* + * 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.tracing.tracer.brave; + +import org.apache.dubbo.config.TracingConfig; +import org.apache.dubbo.rpc.model.ApplicationModel; +import org.apache.dubbo.tracing.tracer.TracerProvider; + +import io.micrometer.tracing.Tracer; + + +public class BraveProvider implements TracerProvider { + + private final ApplicationModel applicationModel; + private final TracingConfig tracingConfig; + + public BraveProvider(ApplicationModel applicationModel, TracingConfig tracingConfig) { + this.applicationModel = applicationModel; + this.tracingConfig = tracingConfig; + } + + @Override + public Tracer getTracer() { + // TODO impl + return null; + } +} diff --git a/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/tracer/otel/OTelPropagatorProvider.java b/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/tracer/otel/OTelPropagatorProvider.java new file mode 100644 index 0000000000..9f537f1e4d --- /dev/null +++ b/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/tracer/otel/OTelPropagatorProvider.java @@ -0,0 +1,38 @@ +/* + * 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.tracing.tracer.otel; + +import org.apache.dubbo.tracing.tracer.PropagatorProvider; + +import io.micrometer.tracing.otel.bridge.OtelPropagator; +import io.micrometer.tracing.propagation.Propagator; +import io.opentelemetry.api.trace.Tracer; +import io.opentelemetry.context.propagation.ContextPropagators; + +public class OTelPropagatorProvider implements PropagatorProvider { + + private static Propagator propagator; + + @Override + public Propagator getPropagator() { + return propagator; + } + + protected static void createMicrometerPropagator(ContextPropagators contextPropagators, Tracer tracer) { + propagator = new OtelPropagator(contextPropagators, tracer); + } +} diff --git a/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/tracer/otel/OpenTelemetryProvider.java b/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/tracer/otel/OpenTelemetryProvider.java new file mode 100644 index 0000000000..36b3c3f191 --- /dev/null +++ b/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/tracer/otel/OpenTelemetryProvider.java @@ -0,0 +1,212 @@ +/* + * 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.tracing.tracer.otel; + +import org.apache.dubbo.common.Version; +import org.apache.dubbo.common.lang.Nullable; +import org.apache.dubbo.config.ApplicationConfig; +import org.apache.dubbo.config.TracingConfig; +import org.apache.dubbo.config.nested.BaggageConfig; +import org.apache.dubbo.config.nested.PropagationConfig; +import org.apache.dubbo.rpc.model.ApplicationModel; +import org.apache.dubbo.tracing.exporter.TraceExporterFactory; +import org.apache.dubbo.tracing.tracer.TracerProvider; + +import io.micrometer.tracing.Tracer; +import io.micrometer.tracing.otel.bridge.CompositeSpanExporter; +import io.micrometer.tracing.otel.bridge.EventListener; +import io.micrometer.tracing.otel.bridge.EventPublishingContextWrapper; +import io.micrometer.tracing.otel.bridge.OtelBaggageManager; +import io.micrometer.tracing.otel.bridge.OtelCurrentTraceContext; +import io.micrometer.tracing.otel.bridge.OtelTracer; +import io.micrometer.tracing.otel.bridge.Slf4JBaggageEventListener; +import io.micrometer.tracing.otel.bridge.Slf4JEventListener; +import io.micrometer.tracing.otel.propagation.BaggageTextMapPropagator; +import io.opentelemetry.api.baggage.propagation.W3CBaggagePropagator; +import io.opentelemetry.api.common.Attributes; +import io.opentelemetry.api.trace.propagation.W3CTraceContextPropagator; +import io.opentelemetry.context.ContextStorage; +import io.opentelemetry.context.propagation.ContextPropagators; +import io.opentelemetry.context.propagation.TextMapPropagator; +import io.opentelemetry.extension.trace.propagation.B3Propagator; +import io.opentelemetry.sdk.OpenTelemetrySdk; +import io.opentelemetry.sdk.resources.Resource; +import io.opentelemetry.sdk.trace.SdkTracerProvider; +import io.opentelemetry.sdk.trace.export.BatchSpanProcessor; +import io.opentelemetry.sdk.trace.export.SpanExporter; +import io.opentelemetry.sdk.trace.samplers.Sampler; +import io.opentelemetry.semconv.resource.attributes.ResourceAttributes; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +public class OpenTelemetryProvider implements TracerProvider { + + private static final String DEFAULT_APPLICATION_NAME = "dubbo-application"; + private final ApplicationModel applicationModel; + private final TracingConfig tracingConfig; + + private OTelEventPublisher publisher; + private OtelCurrentTraceContext otelCurrentTraceContext; + + public OpenTelemetryProvider(ApplicationModel applicationModel, TracingConfig tracingConfig) { + this.applicationModel = applicationModel; + this.tracingConfig = tracingConfig; + } + + @Override + public Tracer getTracer() { + // [OTel component] SpanExporter is a component that gets called when a span is finished. + List spanExporters = TraceExporterFactory.getSpanExporters(applicationModel, tracingConfig.getTracingExporter()); + + String applicationName = applicationModel.getApplicationConfigManager().getApplication() + .map(ApplicationConfig::getName) + .orElse(DEFAULT_APPLICATION_NAME); + + this.publisher = new OTelEventPublisher(getEventListeners()); + + // [Micrometer Tracing component] A Micrometer Tracing wrapper for OTel + this.otelCurrentTraceContext = createCurrentTraceContext(); + + // [OTel component] SdkTracerProvider is an SDK implementation for TracerProvider + SdkTracerProvider sdkTracerProvider = SdkTracerProvider.builder() + .setSampler(getSampler()) + .setResource(Resource.create(Attributes.of(ResourceAttributes.SERVICE_NAME, applicationName))) + .addSpanProcessor(BatchSpanProcessor + .builder(new CompositeSpanExporter(spanExporters, null, null, null)) + .build()) + .build(); + + ContextPropagators otelContextPropagators = createOtelContextPropagators(); + + // [OTel component] The SDK implementation of OpenTelemetry + OpenTelemetrySdk openTelemetrySdk = OpenTelemetrySdk.builder() + .setTracerProvider(sdkTracerProvider) + .setPropagators(otelContextPropagators) + .build(); + + // [OTel component] Tracer is a component that handles the life-cycle of a span + io.opentelemetry.api.trace.Tracer otelTracer = openTelemetrySdk.getTracerProvider() + .get("org.apache.dubbo", Version.getVersion()); + + OTelPropagatorProvider.createMicrometerPropagator(otelContextPropagators, otelTracer); + + // [Micrometer Tracing component] A Micrometer Tracing wrapper for OTel's Tracer. + return new OtelTracer(otelTracer, otelCurrentTraceContext, publisher, + new OtelBaggageManager(otelCurrentTraceContext, + tracingConfig.getBaggage().getRemoteFields(), + Collections.emptyList())); + } + + /** + * sampler with probability + * + * @return sampler + */ + private Sampler getSampler() { + Sampler rootSampler = Sampler.traceIdRatioBased(tracingConfig.getSampling().getProbability()); + return Sampler.parentBased(rootSampler); + } + + private List getEventListeners() { + List listeners = new ArrayList<>(); + + // [Micrometer Tracing component] A Micrometer Tracing listener for setting up MDC. + Slf4JEventListener slf4JEventListener = new Slf4JEventListener(); + listeners.add(slf4JEventListener); + + if (tracingConfig.getBaggage().getEnabled()) { + // [Micrometer Tracing component] A Micrometer Tracing listener for setting Baggage in MDC. + // Customizable with correlation fields. + Slf4JBaggageEventListener slf4JBaggageEventListener = new Slf4JBaggageEventListener(tracingConfig.getBaggage().getCorrelation().getFields()); + listeners.add(slf4JBaggageEventListener); + } + + return listeners; + } + + private OtelCurrentTraceContext createCurrentTraceContext() { + ContextStorage.addWrapper(new EventPublishingContextWrapper(publisher)); + return new OtelCurrentTraceContext(); + } + + private ContextPropagators createOtelContextPropagators() { + return ContextPropagators.create( + TextMapPropagator.composite( + PropagatorFactory.getPropagator(tracingConfig.getPropagation(), + tracingConfig.getBaggage(), + otelCurrentTraceContext + ))); + } + + static class OTelEventPublisher implements OtelTracer.EventPublisher { + + private final List listeners; + + OTelEventPublisher(List listeners) { + this.listeners = listeners; + } + + @Override + public void publishEvent(Object event) { + for (EventListener listener : this.listeners) { + listener.onEvent(event); + } + } + } + + static class PropagatorFactory { + + public static TextMapPropagator getPropagator(PropagationConfig propagationConfig, + @Nullable BaggageConfig baggageConfig, + @Nullable OtelCurrentTraceContext currentTraceContext) { + if (baggageConfig == null || !baggageConfig.getEnabled()) { + return getPropagatorWithoutBaggage(propagationConfig); + } + return getPropagatorWithBaggage(propagationConfig, baggageConfig, currentTraceContext); + } + + private static TextMapPropagator getPropagatorWithoutBaggage(PropagationConfig propagationConfig) { + String type = propagationConfig.getType(); + if ("B3".equals(type)) { + return B3Propagator.injectingSingleHeader(); + } else if ("W3C".equals(type)) { + return W3CTraceContextPropagator.getInstance(); + } + return TextMapPropagator.noop(); + } + + private static TextMapPropagator getPropagatorWithBaggage(PropagationConfig propagationConfig, + BaggageConfig baggageConfig, + OtelCurrentTraceContext currentTraceContext) { + String type = propagationConfig.getType(); + if ("B3".equals(type)) { + List remoteFields = baggageConfig.getRemoteFields(); + return TextMapPropagator.composite(B3Propagator.injectingSingleHeader(), + new BaggageTextMapPropagator(remoteFields, + new OtelBaggageManager(currentTraceContext, remoteFields, Collections.emptyList()))); + } else if ("W3C".equals(type)) { + List remoteFields = baggageConfig.getRemoteFields(); + return TextMapPropagator.composite(W3CTraceContextPropagator.getInstance(), + W3CBaggagePropagator.getInstance(), new BaggageTextMapPropagator(remoteFields, + new OtelBaggageManager(currentTraceContext, remoteFields, Collections.emptyList()))); + } + return TextMapPropagator.noop(); + } + } +} diff --git a/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/utils/ObservationSupportUtil.java b/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/utils/ObservationSupportUtil.java new file mode 100644 index 0000000000..4cf8e05edf --- /dev/null +++ b/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/utils/ObservationSupportUtil.java @@ -0,0 +1,49 @@ +/* + * 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.tracing.utils; + +import org.apache.dubbo.common.utils.ClassUtils; + +public class ObservationSupportUtil { + + public static boolean isSupportObservation() { + return isClassPresent("io.micrometer.observation.Observation") + && isClassPresent("io.micrometer.observation.ObservationRegistry") + && isClassPresent("io.micrometer.observation.ObservationHandler"); + } + + public static boolean isSupportTracing() { + return isClassPresent("io.micrometer.tracing.Tracer") + && isClassPresent("io.micrometer.tracing.propagation.Propagator"); + } + + public static boolean isSupportOTelTracer() { + return isClassPresent("io.micrometer.tracing.otel.bridge.OtelTracer") + && isClassPresent("io.opentelemetry.sdk.trace.SdkTracerProvider") + && isClassPresent("io.opentelemetry.api.OpenTelemetry"); + } + + public static boolean isSupportBraveTracer() { + return isClassPresent("io.micrometer.tracing.Tracer") + && isClassPresent("io.micrometer.tracing.brave.bridge.BraveTracer") + && isClassPresent("brave.Tracing"); + } + + private static boolean isClassPresent(String className) { + return ClassUtils.isPresent(className, ObservationSupportUtil.class.getClassLoader()); + } +} diff --git a/dubbo-metrics/dubbo-tracing/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.Filter b/dubbo-metrics/dubbo-tracing/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.Filter new file mode 100644 index 0000000000..a7efac7c5e --- /dev/null +++ b/dubbo-metrics/dubbo-tracing/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.Filter @@ -0,0 +1 @@ +observationreceiver=org.apache.dubbo.tracing.filter.ObservationReceiverFilter \ No newline at end of file diff --git a/dubbo-metrics/dubbo-tracing/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.cluster.filter.ClusterFilter b/dubbo-metrics/dubbo-tracing/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.cluster.filter.ClusterFilter new file mode 100644 index 0000000000..f13199c666 --- /dev/null +++ b/dubbo-metrics/dubbo-tracing/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.cluster.filter.ClusterFilter @@ -0,0 +1 @@ +observationsender=org.apache.dubbo.tracing.filter.ObservationSenderFilter \ No newline at end of file diff --git a/dubbo-metrics/dubbo-metrics-api/src/test/java/org/apache/dubbo/metrics/observation/DefaultDubboClientObservationConventionTest.java b/dubbo-metrics/dubbo-tracing/src/test/java/org/apache/dubbo/tracing/DefaultDubboClientObservationConventionTest.java similarity index 94% rename from dubbo-metrics/dubbo-metrics-api/src/test/java/org/apache/dubbo/metrics/observation/DefaultDubboClientObservationConventionTest.java rename to dubbo-metrics/dubbo-tracing/src/test/java/org/apache/dubbo/tracing/DefaultDubboClientObservationConventionTest.java index 8b91e2531d..0f1e641c4a 100644 --- a/dubbo-metrics/dubbo-metrics-api/src/test/java/org/apache/dubbo/metrics/observation/DefaultDubboClientObservationConventionTest.java +++ b/dubbo-metrics/dubbo-tracing/src/test/java/org/apache/dubbo/tracing/DefaultDubboClientObservationConventionTest.java @@ -14,12 +14,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.metrics.observation; +package org.apache.dubbo.tracing; -import io.micrometer.common.KeyValues; -import org.apache.dubbo.metrics.observation.utils.ObservationConventionUtils; import org.apache.dubbo.rpc.Invoker; import org.apache.dubbo.rpc.RpcInvocation; +import org.apache.dubbo.tracing.context.DubboClientContext; +import org.apache.dubbo.tracing.utils.ObservationConventionUtils; + +import io.micrometer.common.KeyValues; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; diff --git a/dubbo-metrics/dubbo-metrics-api/src/test/java/org/apache/dubbo/metrics/observation/DefaultDubboServerObservationConventionTest.java b/dubbo-metrics/dubbo-tracing/src/test/java/org/apache/dubbo/tracing/DefaultDubboServerObservationConventionTest.java similarity index 93% rename from dubbo-metrics/dubbo-metrics-api/src/test/java/org/apache/dubbo/metrics/observation/DefaultDubboServerObservationConventionTest.java rename to dubbo-metrics/dubbo-tracing/src/test/java/org/apache/dubbo/tracing/DefaultDubboServerObservationConventionTest.java index faa49457e7..95a755cd98 100644 --- a/dubbo-metrics/dubbo-metrics-api/src/test/java/org/apache/dubbo/metrics/observation/DefaultDubboServerObservationConventionTest.java +++ b/dubbo-metrics/dubbo-tracing/src/test/java/org/apache/dubbo/tracing/DefaultDubboServerObservationConventionTest.java @@ -14,12 +14,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.metrics.observation; +package org.apache.dubbo.tracing; -import io.micrometer.common.KeyValues; -import org.apache.dubbo.metrics.observation.utils.ObservationConventionUtils; import org.apache.dubbo.rpc.Invoker; import org.apache.dubbo.rpc.RpcInvocation; +import org.apache.dubbo.tracing.context.DubboClientContext; +import org.apache.dubbo.tracing.context.DubboServerContext; +import org.apache.dubbo.tracing.utils.ObservationConventionUtils; + +import io.micrometer.common.KeyValues; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; diff --git a/dubbo-metrics/dubbo-metrics-default/src/test/java/org/apache/dubbo/metrics/observation/MockInvocation.java b/dubbo-metrics/dubbo-tracing/src/test/java/org/apache/dubbo/tracing/MockInvocation.java similarity index 97% rename from dubbo-metrics/dubbo-metrics-default/src/test/java/org/apache/dubbo/metrics/observation/MockInvocation.java rename to dubbo-metrics/dubbo-tracing/src/test/java/org/apache/dubbo/tracing/MockInvocation.java index 8cb43471d8..cd9c0335dd 100644 --- a/dubbo-metrics/dubbo-metrics-default/src/test/java/org/apache/dubbo/metrics/observation/MockInvocation.java +++ b/dubbo-metrics/dubbo-tracing/src/test/java/org/apache/dubbo/tracing/MockInvocation.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.metrics.observation; +package org.apache.dubbo.tracing; import org.apache.dubbo.rpc.AttachmentsAdapter; import org.apache.dubbo.rpc.Invoker; @@ -68,11 +68,11 @@ public class MockInvocation extends RpcInvocation { } public Class[] getParameterTypes() { - return new Class[] {String.class}; + return new Class[]{String.class}; } public Object[] getArguments() { - return new Object[] {"aa"}; + return new Object[]{"aa"}; } public Map getAttachments() { diff --git a/dubbo-metrics/dubbo-metrics-default/src/test/java/org/apache/dubbo/metrics/observation/AbstractObservationFilterTest.java b/dubbo-metrics/dubbo-tracing/src/test/java/org/apache/dubbo/tracing/filter/AbstractObservationFilterTest.java similarity index 94% rename from dubbo-metrics/dubbo-metrics-default/src/test/java/org/apache/dubbo/metrics/observation/AbstractObservationFilterTest.java rename to dubbo-metrics/dubbo-tracing/src/test/java/org/apache/dubbo/tracing/filter/AbstractObservationFilterTest.java index 99bf615947..046a0f1f95 100644 --- a/dubbo-metrics/dubbo-metrics-default/src/test/java/org/apache/dubbo/metrics/observation/AbstractObservationFilterTest.java +++ b/dubbo-metrics/dubbo-tracing/src/test/java/org/apache/dubbo/tracing/filter/AbstractObservationFilterTest.java @@ -15,9 +15,8 @@ * limitations under the License. */ -package org.apache.dubbo.metrics.observation; +package org.apache.dubbo.tracing.filter; -import io.micrometer.tracing.test.SampleTestRunner; import org.apache.dubbo.config.ApplicationConfig; import org.apache.dubbo.config.TracingConfig; import org.apache.dubbo.rpc.AppResponse; @@ -25,6 +24,9 @@ import org.apache.dubbo.rpc.BaseFilter; import org.apache.dubbo.rpc.Invoker; import org.apache.dubbo.rpc.RpcInvocation; import org.apache.dubbo.rpc.model.ApplicationModel; +import org.apache.dubbo.tracing.MockInvocation; + +import io.micrometer.tracing.test.SampleTestRunner; import org.junit.jupiter.api.AfterEach; import static org.mockito.BDDMockito.given; @@ -78,7 +80,7 @@ abstract class AbstractObservationFilterTest extends SampleTestRunner { private void initParam() { invocation.setTargetServiceUniqueName(GROUP + "/" + INTERFACE_NAME + ":" + VERSION); invocation.setMethodName(METHOD_NAME); - invocation.setParameterTypes(new Class[] {String.class}); + invocation.setParameterTypes(new Class[]{String.class}); } } diff --git a/dubbo-metrics/dubbo-metrics-default/src/test/java/org/apache/dubbo/metrics/observation/ObservationReceiverFilterTest.java b/dubbo-metrics/dubbo-tracing/src/test/java/org/apache/dubbo/tracing/filter/ObservationReceiverFilterTest.java similarity index 99% rename from dubbo-metrics/dubbo-metrics-default/src/test/java/org/apache/dubbo/metrics/observation/ObservationReceiverFilterTest.java rename to dubbo-metrics/dubbo-tracing/src/test/java/org/apache/dubbo/tracing/filter/ObservationReceiverFilterTest.java index 1fe702e193..4cb0282430 100644 --- a/dubbo-metrics/dubbo-metrics-default/src/test/java/org/apache/dubbo/metrics/observation/ObservationReceiverFilterTest.java +++ b/dubbo-metrics/dubbo-tracing/src/test/java/org/apache/dubbo/tracing/filter/ObservationReceiverFilterTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.dubbo.metrics.observation; +package org.apache.dubbo.tracing.filter; import io.micrometer.common.KeyValues; import io.micrometer.core.tck.MeterRegistryAssert; @@ -31,6 +31,7 @@ import org.apache.dubbo.rpc.Result; import org.apache.dubbo.rpc.RpcContext; import org.apache.dubbo.rpc.RpcException; import org.apache.dubbo.rpc.model.ApplicationModel; + import org.assertj.core.api.BDDAssertions; class ObservationReceiverFilterTest extends AbstractObservationFilterTest { diff --git a/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/filter/ObservationSenderFilterTest.java b/dubbo-metrics/dubbo-tracing/src/test/java/org/apache/dubbo/tracing/filter/ObservationSenderFilterTest.java similarity index 92% rename from dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/filter/ObservationSenderFilterTest.java rename to dubbo-metrics/dubbo-tracing/src/test/java/org/apache/dubbo/tracing/filter/ObservationSenderFilterTest.java index 8166203400..071bc0e978 100644 --- a/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/filter/ObservationSenderFilterTest.java +++ b/dubbo-metrics/dubbo-tracing/src/test/java/org/apache/dubbo/tracing/filter/ObservationSenderFilterTest.java @@ -15,22 +15,22 @@ * limitations under the License. */ -package org.apache.dubbo.rpc.cluster.filter; +package org.apache.dubbo.tracing.filter; + +import org.apache.dubbo.common.URL; +import org.apache.dubbo.rpc.RpcContext; +import org.apache.dubbo.rpc.cluster.filter.ClusterFilter; +import org.apache.dubbo.rpc.model.ApplicationModel; import io.micrometer.common.KeyValues; import io.micrometer.core.tck.MeterRegistryAssert; -import io.micrometer.tracing.test.SampleTestRunner; import io.micrometer.tracing.test.simple.SpansAssert; -import org.apache.dubbo.common.URL; -import org.apache.dubbo.rpc.RpcContext; -import org.apache.dubbo.rpc.cluster.filter.support.ObservationSenderFilter; -import org.apache.dubbo.rpc.model.ApplicationModel; import org.assertj.core.api.BDDAssertions; class ObservationSenderFilterTest extends AbstractObservationFilterTest { @Override - public SampleTestRunner.SampleTestRunnerConsumer yourCode() { + public SampleTestRunnerConsumer yourCode() { return (buildingBlocks, meterRegistry) -> { setupConfig(); setupAttachments(); diff --git a/dubbo-metrics/dubbo-tracing/src/test/java/org/apache/dubbo/tracing/tracer/PropagatorProviderFactoryTest.java b/dubbo-metrics/dubbo-tracing/src/test/java/org/apache/dubbo/tracing/tracer/PropagatorProviderFactoryTest.java new file mode 100644 index 0000000000..18f1a74e0e --- /dev/null +++ b/dubbo-metrics/dubbo-tracing/src/test/java/org/apache/dubbo/tracing/tracer/PropagatorProviderFactoryTest.java @@ -0,0 +1,34 @@ +/* + * 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.tracing.tracer; + +import org.apache.dubbo.common.utils.Assert; +import org.apache.dubbo.tracing.tracer.otel.OTelPropagatorProvider; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +class PropagatorProviderFactoryTest { + + @Test + void testPropagatorProviderFactory() { + PropagatorProvider propagatorProvider = PropagatorProviderFactory.getPropagatorProvider(); + Assert.notNull(propagatorProvider, "PropagatorProvider should not be null"); + assertEquals(OTelPropagatorProvider.class, propagatorProvider.getClass()); + } +} \ No newline at end of file diff --git a/dubbo-metrics/dubbo-tracing/src/test/java/org/apache/dubbo/tracing/tracer/otel/OTelPropagatorProviderTest.java b/dubbo-metrics/dubbo-tracing/src/test/java/org/apache/dubbo/tracing/tracer/otel/OTelPropagatorProviderTest.java new file mode 100644 index 0000000000..83f2cd2df0 --- /dev/null +++ b/dubbo-metrics/dubbo-tracing/src/test/java/org/apache/dubbo/tracing/tracer/otel/OTelPropagatorProviderTest.java @@ -0,0 +1,39 @@ +/* + * 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.tracing.tracer.otel; + +import org.apache.dubbo.common.utils.Assert; + +import io.micrometer.tracing.propagation.Propagator; +import io.opentelemetry.api.trace.Tracer; +import io.opentelemetry.context.propagation.ContextPropagators; +import org.junit.jupiter.api.Test; + +import static org.mockito.Mockito.mock; + +class OTelPropagatorProviderTest { + + @Test + void testOTelPropagatorProvider() { + ContextPropagators contextPropagators = mock(ContextPropagators.class); + Tracer tracer = mock(Tracer.class); + OTelPropagatorProvider.createMicrometerPropagator(contextPropagators, tracer); + OTelPropagatorProvider oTelPropagatorProvider = new OTelPropagatorProvider(); + Propagator propagator = oTelPropagatorProvider.getPropagator(); + Assert.notNull(propagator, "Propagator don't be null."); + } +} \ No newline at end of file diff --git a/dubbo-metrics/dubbo-tracing/src/test/java/org/apache/dubbo/tracing/tracer/otel/OpenTelemetryProviderTest.java b/dubbo-metrics/dubbo-tracing/src/test/java/org/apache/dubbo/tracing/tracer/otel/OpenTelemetryProviderTest.java new file mode 100644 index 0000000000..0374912c3a --- /dev/null +++ b/dubbo-metrics/dubbo-tracing/src/test/java/org/apache/dubbo/tracing/tracer/otel/OpenTelemetryProviderTest.java @@ -0,0 +1,53 @@ +/* + * 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.tracing.tracer.otel; + +import org.apache.dubbo.common.utils.Assert; +import org.apache.dubbo.config.TracingConfig; +import org.apache.dubbo.config.nested.BaggageConfig; +import org.apache.dubbo.config.nested.ExporterConfig; +import org.apache.dubbo.rpc.model.ApplicationModel; +import org.apache.dubbo.tracing.tracer.TracerProvider; +import org.apache.dubbo.tracing.tracer.TracerProviderFactory; + +import io.micrometer.tracing.Tracer; +import io.micrometer.tracing.otel.bridge.OtelTracer; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +class OpenTelemetryProviderTest { + + @Test + void testGetTracer() { + TracingConfig tracingConfig = new TracingConfig(); + tracingConfig.setEnabled(true); + ExporterConfig exporterConfig = new ExporterConfig(); + exporterConfig.setZipkinConfig(new ExporterConfig.ZipkinConfig("")); + tracingConfig.setTracingExporter(exporterConfig); + TracerProvider tracerProvider1 = TracerProviderFactory.getProvider(ApplicationModel.defaultModel(), tracingConfig); + Assert.notNull(tracerProvider1, "TracerProvider should not be null."); + Tracer tracer1 = tracerProvider1.getTracer(); + assertEquals(OtelTracer.class, tracer1.getClass()); + + tracingConfig.setBaggage(new BaggageConfig(false)); + TracerProvider tracerProvider2 = TracerProviderFactory.getProvider(ApplicationModel.defaultModel(), tracingConfig); + Assert.notNull(tracerProvider2, "TracerProvider should not be null."); + Tracer tracer2 = tracerProvider2.getTracer(); + assertEquals(OtelTracer.class, tracer2.getClass()); + } +} \ No newline at end of file diff --git a/dubbo-metrics/dubbo-metrics-api/src/test/java/org/apache/dubbo/metrics/observation/utils/ObservationConventionUtils.java b/dubbo-metrics/dubbo-tracing/src/test/java/org/apache/dubbo/tracing/utils/ObservationConventionUtils.java similarity index 97% rename from dubbo-metrics/dubbo-metrics-api/src/test/java/org/apache/dubbo/metrics/observation/utils/ObservationConventionUtils.java rename to dubbo-metrics/dubbo-tracing/src/test/java/org/apache/dubbo/tracing/utils/ObservationConventionUtils.java index 4bf2abfa1e..f0b75c8c2c 100644 --- a/dubbo-metrics/dubbo-metrics-api/src/test/java/org/apache/dubbo/metrics/observation/utils/ObservationConventionUtils.java +++ b/dubbo-metrics/dubbo-tracing/src/test/java/org/apache/dubbo/tracing/utils/ObservationConventionUtils.java @@ -14,12 +14,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.metrics.observation.utils; +package org.apache.dubbo.tracing.utils; + +import org.apache.dubbo.common.URL; +import org.apache.dubbo.rpc.Invoker; import io.micrometer.common.KeyValue; import io.micrometer.common.KeyValues; -import org.apache.dubbo.common.URL; -import org.apache.dubbo.rpc.Invoker; import org.mockito.Mockito; import java.lang.reflect.Field; diff --git a/dubbo-metrics/dubbo-tracing/src/test/java/org/apache/dubbo/tracing/utils/ObservationSupportUtilTest.java b/dubbo-metrics/dubbo-tracing/src/test/java/org/apache/dubbo/tracing/utils/ObservationSupportUtilTest.java new file mode 100644 index 0000000000..3903053ca8 --- /dev/null +++ b/dubbo-metrics/dubbo-tracing/src/test/java/org/apache/dubbo/tracing/utils/ObservationSupportUtilTest.java @@ -0,0 +1,49 @@ +/* + * 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.tracing.utils; + +import org.apache.dubbo.common.utils.Assert; + +import org.junit.jupiter.api.Test; + +public class ObservationSupportUtilTest { + + @Test + void testIsSupportObservation() { + boolean supportObservation = ObservationSupportUtil.isSupportObservation(); + Assert.assertTrue(supportObservation, "ObservationSupportUtil.isSupportObservation() should return true"); + } + + @Test + void testIsSupportTracing() { + boolean supportTracing = ObservationSupportUtil.isSupportTracing(); + Assert.assertTrue(supportTracing, "ObservationSupportUtil.isSupportTracing() should return true"); + } + + @Test + void testIsSupportOTelTracer() { + boolean supportOTelTracer = ObservationSupportUtil.isSupportOTelTracer(); + Assert.assertTrue(supportOTelTracer, "ObservationSupportUtil.isSupportOTelTracer() should return true"); + } + + @Test + void testIsSupportBraveTracer() { + boolean supportBraveTracer = ObservationSupportUtil.isSupportBraveTracer(); + Assert.assertTrue(supportBraveTracer, "ObservationSupportUtil.isSupportOTelTracer() should return true"); + } +} diff --git a/dubbo-metrics/pom.xml b/dubbo-metrics/pom.xml index 04abd6e077..c10defb8d6 100644 --- a/dubbo-metrics/pom.xml +++ b/dubbo-metrics/pom.xml @@ -24,6 +24,7 @@ dubbo-metrics-metadata dubbo-metrics-prometheus dubbo-metrics-config-center + dubbo-tracing org.apache.dubbo diff --git a/dubbo-spring-boot/dubbo-spring-boot-starters/observability/autoconfigure/pom.xml b/dubbo-spring-boot/dubbo-spring-boot-starters/observability/autoconfigure/pom.xml index b9e1369556..e8d997bda9 100644 --- a/dubbo-spring-boot/dubbo-spring-boot-starters/observability/autoconfigure/pom.xml +++ b/dubbo-spring-boot/dubbo-spring-boot-starters/observability/autoconfigure/pom.xml @@ -137,6 +137,12 @@ ${project.version} true + + org.apache.dubbo + dubbo-config-spring + ${project.version} + true + diff --git a/dubbo-spring-boot/dubbo-spring-boot-starters/observability/autoconfigure/src/main/java/org/apache/dubbo/spring/boot/observability/autoconfigure/DubboObservationAutoConfiguration.java b/dubbo-spring-boot/dubbo-spring-boot-starters/observability/autoconfigure/src/main/java/org/apache/dubbo/spring/boot/observability/autoconfigure/DubboObservationAutoConfiguration.java index 37f552fadf..10ffaa9be1 100644 --- a/dubbo-spring-boot/dubbo-spring-boot-starters/observability/autoconfigure/src/main/java/org/apache/dubbo/spring/boot/observability/autoconfigure/DubboObservationAutoConfiguration.java +++ b/dubbo-spring-boot/dubbo-spring-boot-starters/observability/autoconfigure/src/main/java/org/apache/dubbo/spring/boot/observability/autoconfigure/DubboObservationAutoConfiguration.java @@ -18,6 +18,7 @@ package org.apache.dubbo.spring.boot.observability.autoconfigure; import org.apache.dubbo.common.logger.ErrorTypeAwareLogger; import org.apache.dubbo.common.logger.LoggerFactory; +import org.apache.dubbo.config.spring.context.event.DubboConfigInitEvent; import org.apache.dubbo.qos.protocol.QosProtocolWrapper; import org.apache.dubbo.rpc.model.ApplicationModel; import org.apache.dubbo.spring.boot.observability.autoconfigure.annotation.ConditionalOnDubboTracingEnable; @@ -28,14 +29,15 @@ import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactoryAware; import org.springframework.beans.factory.NoSuchBeanDefinitionException; import org.springframework.beans.factory.ObjectProvider; -import org.springframework.beans.factory.SmartInitializingSingleton; import org.springframework.boot.autoconfigure.AutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass; +import org.springframework.context.ApplicationListener; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.core.Ordered; import java.util.Arrays; @@ -46,7 +48,7 @@ import java.util.Arrays; @AutoConfiguration(after = DubboMicrometerTracingAutoConfiguration.class, afterName = "org.springframework.boot.actuate.autoconfigure.observation.ObservationAutoConfiguration") @ConditionalOnDubboTracingEnable @ConditionalOnClass(name = {"io.micrometer.observation.Observation", "io.micrometer.tracing.Tracer"}) -public class DubboObservationAutoConfiguration implements BeanFactoryAware, SmartInitializingSingleton { +public class DubboObservationAutoConfiguration implements BeanFactoryAware, ApplicationListener, Ordered { private final ErrorTypeAwareLogger logger = LoggerFactory.getErrorTypeAwareLogger(QosProtocolWrapper.class); @@ -79,16 +81,21 @@ public class DubboObservationAutoConfiguration implements BeanFactoryAware, Smar } @Override - public void afterSingletonsInstantiated() { + public void onApplicationEvent(DubboConfigInitEvent event) { try { applicationModel.getBeanFactory().registerBean(beanFactory.getBean(io.micrometer.observation.ObservationRegistry.class)); - io.micrometer.tracing.Tracer bean = beanFactory.getBean(io.micrometer.tracing.Tracer.class); - applicationModel.getBeanFactory().registerBean(bean); + applicationModel.getBeanFactory().registerBean(beanFactory.getBean(io.micrometer.tracing.Tracer.class)); + applicationModel.getBeanFactory().registerBean(beanFactory.getBean(io.micrometer.tracing.propagation.Propagator.class)); } catch (NoSuchBeanDefinitionException e) { - logger.info("Please use a version of micrometer higher than 1.10.0 :{}" + e.getMessage()); + logger.info("Please use a version of micrometer higher than 1.10.0: " + e.getMessage()); } } + @Override + public int getOrder() { + return HIGHEST_PRECEDENCE; + } + @Configuration(proxyBeanMethods = false) @ConditionalOnClass(MeterRegistry.class) @ConditionalOnMissingClass("io.micrometer.tracing.Tracer") diff --git a/dubbo-spring-boot/dubbo-spring-boot-starters/observability/autoconfigure/src/main/java/org/apache/dubbo/spring/boot/observability/autoconfigure/brave/BraveAutoConfiguration.java b/dubbo-spring-boot/dubbo-spring-boot-starters/observability/autoconfigure/src/main/java/org/apache/dubbo/spring/boot/observability/autoconfigure/brave/BraveAutoConfiguration.java index 24be95c4ec..8894b890cb 100644 --- a/dubbo-spring-boot/dubbo-spring-boot-starters/observability/autoconfigure/src/main/java/org/apache/dubbo/spring/boot/observability/autoconfigure/brave/BraveAutoConfiguration.java +++ b/dubbo-spring-boot/dubbo-spring-boot-starters/observability/autoconfigure/src/main/java/org/apache/dubbo/spring/boot/observability/autoconfigure/brave/BraveAutoConfiguration.java @@ -16,8 +16,7 @@ */ package org.apache.dubbo.spring.boot.observability.autoconfigure.brave; -import org.apache.dubbo.config.ApplicationConfig; -import org.apache.dubbo.rpc.model.ModuleModel; +import org.apache.dubbo.common.utils.StringUtils; import org.apache.dubbo.spring.boot.autoconfigure.DubboConfigurationProperties; import org.apache.dubbo.spring.boot.observability.autoconfigure.DubboMicrometerTracingAutoConfiguration; import org.apache.dubbo.spring.boot.observability.autoconfigure.ObservabilityUtils; @@ -53,12 +52,12 @@ public class BraveAutoConfiguration { /** * Default value for application name if {@code spring.application.name} is not set. */ - private static final String DEFAULT_APPLICATION_NAME = "application"; + private static final String DEFAULT_APPLICATION_NAME = "dubbo-application"; - private final ModuleModel moduleModel; + private final DubboConfigurationProperties dubboConfigProperties; - public BraveAutoConfiguration(ModuleModel moduleModel) { - this.moduleModel = moduleModel; + public BraveAutoConfiguration(DubboConfigurationProperties dubboConfigProperties) { + this.dubboConfigProperties = dubboConfigProperties; } @Bean @@ -76,9 +75,10 @@ public class BraveAutoConfiguration { public brave.Tracing braveTracing(List spanHandlers, List tracingCustomizers, brave.propagation.CurrentTraceContext currentTraceContext, brave.propagation.Propagation.Factory propagationFactory, brave.sampler.Sampler sampler) { - String applicationName = moduleModel.getApplicationModel().getApplicationConfigManager().getApplication() - .map(ApplicationConfig::getName) - .orElse(DEFAULT_APPLICATION_NAME); + String applicationName = dubboConfigProperties.getApplication().getName(); + if (StringUtils.isEmpty(applicationName)) { + applicationName = DEFAULT_APPLICATION_NAME; + } brave.Tracing.Builder builder = brave.Tracing.newBuilder().currentTraceContext(currentTraceContext).traceId128Bit(true) .supportsJoin(false).propagationFactory(propagationFactory).sampler(sampler) .localServiceName(applicationName); diff --git a/dubbo-spring-boot/dubbo-spring-boot-starters/observability/autoconfigure/src/main/java/org/apache/dubbo/spring/boot/observability/autoconfigure/otel/OpenTelemetryAutoConfiguration.java b/dubbo-spring-boot/dubbo-spring-boot-starters/observability/autoconfigure/src/main/java/org/apache/dubbo/spring/boot/observability/autoconfigure/otel/OpenTelemetryAutoConfiguration.java index 85babb77f8..6b4e38f7c9 100644 --- a/dubbo-spring-boot/dubbo-spring-boot-starters/observability/autoconfigure/src/main/java/org/apache/dubbo/spring/boot/observability/autoconfigure/otel/OpenTelemetryAutoConfiguration.java +++ b/dubbo-spring-boot/dubbo-spring-boot-starters/observability/autoconfigure/src/main/java/org/apache/dubbo/spring/boot/observability/autoconfigure/otel/OpenTelemetryAutoConfiguration.java @@ -18,8 +18,7 @@ package org.apache.dubbo.spring.boot.observability.autoconfigure.otel; import org.apache.dubbo.common.Version; -import org.apache.dubbo.config.ApplicationConfig; -import org.apache.dubbo.rpc.model.ModuleModel; +import org.apache.dubbo.common.utils.StringUtils; import org.apache.dubbo.spring.boot.autoconfigure.DubboConfigurationProperties; import org.apache.dubbo.spring.boot.observability.autoconfigure.DubboMicrometerTracingAutoConfiguration; import org.apache.dubbo.spring.boot.observability.autoconfigure.ObservabilityUtils; @@ -52,15 +51,12 @@ public class OpenTelemetryAutoConfiguration { /** * Default value for application name if {@code spring.application.name} is not set. */ - private static final String DEFAULT_APPLICATION_NAME = "application"; + private static final String DEFAULT_APPLICATION_NAME = "dubbo-application"; private final DubboConfigurationProperties dubboConfigProperties; - private final ModuleModel moduleModel; - - OpenTelemetryAutoConfiguration(DubboConfigurationProperties dubboConfigProperties, ModuleModel moduleModel) { + OpenTelemetryAutoConfiguration(DubboConfigurationProperties dubboConfigProperties) { this.dubboConfigProperties = dubboConfigProperties; - this.moduleModel = moduleModel; } @Bean @@ -74,9 +70,10 @@ public class OpenTelemetryAutoConfiguration { @ConditionalOnMissingBean io.opentelemetry.sdk.trace.SdkTracerProvider otelSdkTracerProvider(ObjectProvider spanProcessors, io.opentelemetry.sdk.trace.samplers.Sampler sampler) { - String applicationName = moduleModel.getApplicationModel().getApplicationConfigManager().getApplication() - .map(ApplicationConfig::getName) - .orElse(DEFAULT_APPLICATION_NAME); + String applicationName = dubboConfigProperties.getApplication().getName(); + if (StringUtils.isEmpty(applicationName)) { + applicationName = DEFAULT_APPLICATION_NAME; + } io.opentelemetry.sdk.trace.SdkTracerProviderBuilder builder = io.opentelemetry.sdk.trace.SdkTracerProvider.builder().setSampler(sampler) .setResource(io.opentelemetry.sdk.resources.Resource.create(io.opentelemetry.api.common.Attributes.of(io.opentelemetry.semconv.resource.attributes.ResourceAttributes.SERVICE_NAME, applicationName))); spanProcessors.orderedStream().forEach(builder::addSpanProcessor); diff --git a/dubbo-test/dubbo-dependencies-all/pom.xml b/dubbo-test/dubbo-dependencies-all/pom.xml index 526743f360..991154acbb 100644 --- a/dubbo-test/dubbo-dependencies-all/pom.xml +++ b/dubbo-test/dubbo-dependencies-all/pom.xml @@ -193,6 +193,11 @@ dubbo-metrics-prometheus ${project.version} + + org.apache.dubbo + dubbo-tracing + ${project.version} + @@ -205,7 +210,6 @@ dubbo-monitor-default ${project.version} - org.apache.dubbo From 467622aac6b62408c1f5861ddec2880cd74e88cc Mon Sep 17 00:00:00 2001 From: Zhang Xiang Wei Date: Sun, 18 Jun 2023 13:45:06 +0800 Subject: [PATCH 07/32] fix https://github.com/apache/dubbo/issues/12526 (#12527) --- .../main/java/org/apache/dubbo/config/ReferenceConfig.java | 6 ++---- .../main/java/org/apache/dubbo/config/ServiceConfig.java | 6 ++---- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ReferenceConfig.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ReferenceConfig.java index 50bf549a20..e8da1c28d4 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ReferenceConfig.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ReferenceConfig.java @@ -57,7 +57,7 @@ import org.apache.dubbo.rpc.support.ProtocolUtils; import java.beans.Transient; import java.util.ArrayList; import java.util.Arrays; -import java.util.Comparator; +import java.util.TreeSet; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -409,9 +409,7 @@ public class ReferenceConfig extends ReferenceConfigBase { logger.warn(CONFIG_NO_METHOD_FOUND, "", "", "No method found in service interface: " + interfaceClass.getName()); map.put(METHODS_KEY, ANY_VALUE); } else { - List copyOfMethods = new ArrayList<>(Arrays.asList(methods)); - copyOfMethods.sort(Comparator.naturalOrder()); - map.put(METHODS_KEY, String.join(COMMA_SEPARATOR, copyOfMethods)); + map.put(METHODS_KEY, StringUtils.join(new TreeSet<>(Arrays.asList(methods)), COMMA_SEPARATOR)); } } diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ServiceConfig.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ServiceConfig.java index 7fad3c8359..a382c2fdb4 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ServiceConfig.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ServiceConfig.java @@ -57,7 +57,7 @@ import java.beans.Transient; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Arrays; -import java.util.Comparator; +import java.util.TreeSet; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -584,9 +584,7 @@ public class ServiceConfig extends ServiceConfigBase { logger.warn(CONFIG_NO_METHOD_FOUND, "", "", "No method found in service interface: " + interfaceClass.getName()); map.put(METHODS_KEY, ANY_VALUE); } else { - List copyOfMethods = new ArrayList<>(Arrays.asList(methods)); - copyOfMethods.sort(Comparator.naturalOrder()); - map.put(METHODS_KEY, String.join(COMMA_SEPARATOR, copyOfMethods)); + map.put(METHODS_KEY, StringUtils.join(new TreeSet<>(Arrays.asList(methods)), COMMA_SEPARATOR)); } } From d606e11da5c6c1e14d3defe37d18efb3001cdf11 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 18 Jun 2023 14:16:36 +0800 Subject: [PATCH 08/32] Bump snappy-java from 1.1.10.0 to 1.1.10.1 in /dubbo-dependencies-bom (#12544) Bumps [snappy-java](https://github.com/xerial/snappy-java) from 1.1.10.0 to 1.1.10.1. - [Release notes](https://github.com/xerial/snappy-java/releases) - [Commits](https://github.com/xerial/snappy-java/compare/v1.1.10.0...v1.1.10.1) --- updated-dependencies: - dependency-name: org.xerial.snappy:snappy-java dependency-type: direct:production ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- dubbo-dependencies-bom/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dubbo-dependencies-bom/pom.xml b/dubbo-dependencies-bom/pom.xml index f61a49e9ad..1c3a7eec13 100644 --- a/dubbo-dependencies-bom/pom.xml +++ b/dubbo-dependencies-bom/pom.xml @@ -180,7 +180,7 @@ 3.2.13 1.6.11 - 1.1.10.0 + 1.1.10.1 1.70 2.0.6 5.4.3 From b20d63ef1f3e43646a82ddab61c3413ab575bb5b Mon Sep 17 00:00:00 2001 From: Albumen Kevin Date: Sun, 18 Jun 2023 15:12:38 +0800 Subject: [PATCH 09/32] Disable all filters for internal service (#12515) * Disable all filters for internal service * fix uts * fix uts --- .../bootstrap/builders/InternalServiceConfigBuilder.java | 1 + .../AbstractRegistryCenterExporterListener.java | 9 ++++++++- ...tipleRegistryCenterExportProviderIntegrationTest.java | 2 +- .../MultipleRegistryCenterInjvmIntegrationTest.java | 4 ++-- ...ingleRegistryCenterExportProviderIntegrationTest.java | 4 ++-- .../injvm/SingleRegistryCenterInjvmIntegrationTest.java | 4 ++-- 6 files changed, 16 insertions(+), 8 deletions(-) diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/bootstrap/builders/InternalServiceConfigBuilder.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/bootstrap/builders/InternalServiceConfigBuilder.java index 6e37707f28..5a2dbdbaf6 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/bootstrap/builders/InternalServiceConfigBuilder.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/bootstrap/builders/InternalServiceConfigBuilder.java @@ -275,6 +275,7 @@ public class InternalServiceConfigBuilder { serviceConfig.setRef(this.ref); serviceConfig.setGroup(applicationConfig.getName()); serviceConfig.setVersion("1.0.0"); + serviceConfig.setFilter("-default"); serviceConfig.setExecutor(executor); diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/AbstractRegistryCenterExporterListener.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/AbstractRegistryCenterExporterListener.java index 74e1e69592..b62c15f4b6 100644 --- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/AbstractRegistryCenterExporterListener.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/AbstractRegistryCenterExporterListener.java @@ -19,6 +19,7 @@ package org.apache.dubbo.config.integration; import org.apache.dubbo.rpc.Exporter; import org.apache.dubbo.rpc.ExporterListener; import org.apache.dubbo.rpc.Filter; +import org.apache.dubbo.rpc.Invoker; import org.apache.dubbo.rpc.RpcException; import org.apache.dubbo.rpc.cluster.filter.FilterChainBuilder; import org.apache.dubbo.rpc.listener.ListenerExporterWrapper; @@ -56,7 +57,13 @@ public abstract class AbstractRegistryCenterExporterListener implements Exporter @Override public void exported(Exporter exporter) throws RpcException { ListenerExporterWrapper listenerExporterWrapper = (ListenerExporterWrapper) exporter; - FilterChainBuilder.CallbackRegistrationInvoker callbackRegistrationInvoker = (FilterChainBuilder.CallbackRegistrationInvoker) listenerExporterWrapper.getInvoker(); + + Invoker invoker = listenerExporterWrapper.getInvoker(); + if (!(invoker instanceof FilterChainBuilder.CallbackRegistrationInvoker)) { + exportedExporters.add(exporter); + return; + } + FilterChainBuilder.CallbackRegistrationInvoker callbackRegistrationInvoker = (FilterChainBuilder.CallbackRegistrationInvoker) invoker; if (callbackRegistrationInvoker == null || callbackRegistrationInvoker.getInterface() != getInterface()) { return; diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/exportprovider/MultipleRegistryCenterExportProviderIntegrationTest.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/exportprovider/MultipleRegistryCenterExportProviderIntegrationTest.java index 7ed2e63358..445ddb6dfc 100644 --- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/exportprovider/MultipleRegistryCenterExportProviderIntegrationTest.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/exportprovider/MultipleRegistryCenterExportProviderIntegrationTest.java @@ -188,7 +188,7 @@ class MultipleRegistryCenterExportProviderIntegrationTest implements Integration // 1. InjvmExporter // 2. DubboExporter with service-discovery-registry protocol // 3. DubboExporter with registry protocol - Assertions.assertEquals(exporterListener.getExportedExporters().size(), 5); + Assertions.assertEquals(exporterListener.getExportedExporters().size(), 7); // The exported exporter contains MultipleRegistryCenterExportProviderFilter Assertions.assertTrue(exporterListener.getFilters().contains(filter)); diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/injvm/MultipleRegistryCenterInjvmIntegrationTest.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/injvm/MultipleRegistryCenterInjvmIntegrationTest.java index 3f5df17128..227eaf2718 100644 --- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/injvm/MultipleRegistryCenterInjvmIntegrationTest.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/injvm/MultipleRegistryCenterInjvmIntegrationTest.java @@ -156,7 +156,7 @@ class MultipleRegistryCenterInjvmIntegrationTest implements IntegrationTest { // The MultipleRegistryCenterInjvmService is exported Assertions.assertTrue(serviceListener.getExportedServices().get(0).isExported()); // The exported exporter is only one - Assertions.assertEquals(exporterListener.getExportedExporters().size(), 1); + Assertions.assertEquals(exporterListener.getExportedExporters().size(), 3); // The exported exporter contains MultipleRegistryCenterInjvmFilter Assertions.assertTrue(exporterListener.getFilters().contains(filter)); } @@ -189,4 +189,4 @@ class MultipleRegistryCenterInjvmIntegrationTest implements IntegrationTest { serviceListener = null; logger.info(getClass().getSimpleName() + " testcase is ending..."); } -} \ No newline at end of file +} diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/exportprovider/SingleRegistryCenterExportProviderIntegrationTest.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/exportprovider/SingleRegistryCenterExportProviderIntegrationTest.java index 50dca60a21..3ab4bf7b53 100644 --- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/exportprovider/SingleRegistryCenterExportProviderIntegrationTest.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/exportprovider/SingleRegistryCenterExportProviderIntegrationTest.java @@ -195,7 +195,7 @@ class SingleRegistryCenterExportProviderIntegrationTest implements IntegrationTe // 1. InjvmExporter // 2. DubboExporter with service-discovery-registry protocol // 3. DubboExporter with registry protocol - Assertions.assertEquals(exporterListener.getExportedExporters().size(), 3); + Assertions.assertEquals(exporterListener.getExportedExporters().size(), 5); // The exported exporter contains SingleRegistryCenterExportProviderFilter Assertions.assertTrue(exporterListener.getFilters().contains(filter)); // The consumer can be notified and get provider's metadata through metadata mapping info. @@ -244,4 +244,4 @@ class SingleRegistryCenterExportProviderIntegrationTest implements IntegrationTe logger.info(getClass().getSimpleName() + " testcase is ending..."); registryProtocolListener = null; } -} \ No newline at end of file +} diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/injvm/SingleRegistryCenterInjvmIntegrationTest.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/injvm/SingleRegistryCenterInjvmIntegrationTest.java index 62b72e80f3..b313d4461a 100644 --- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/injvm/SingleRegistryCenterInjvmIntegrationTest.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/injvm/SingleRegistryCenterInjvmIntegrationTest.java @@ -156,7 +156,7 @@ class SingleRegistryCenterInjvmIntegrationTest implements IntegrationTest { // The SingleRegistryCenterInjvmService is exported Assertions.assertTrue(serviceListener.getExportedServices().get(0).isExported()); // The exported exporter is only one - Assertions.assertEquals(exporterListener.getExportedExporters().size(), 1); + Assertions.assertEquals(exporterListener.getExportedExporters().size(), 3); // The exported exporter contains SingleRegistryCenterInjvmFilter Assertions.assertTrue(exporterListener.getFilters().contains(filter)); } @@ -188,4 +188,4 @@ class SingleRegistryCenterInjvmIntegrationTest implements IntegrationTest { serviceListener = null; logger.info(getClass().getSimpleName() + " testcase is ending..."); } -} \ No newline at end of file +} From 55484cbfccdec370d90fb5ad3e7d630f6d69d136 Mon Sep 17 00:00:00 2001 From: zdrjson Date: Sun, 18 Jun 2023 17:02:06 +0800 Subject: [PATCH 10/32] docs: Add path to cd dubbo-samples/dubbo-samples-api (#12548) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9285dd01f5..e34ee20894 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ The following code snippet comes from [Dubbo Samples](https://github.com/apache/ ```bash git clone https://github.com/apache/dubbo-samples.git -cd dubbo-samples/dubbo-samples-api +cd dubbo-samples/1-basic/dubbo-samples-api ``` There's a [README](https://github.com/apache/dubbo-samples/blob/389cd612f1ea57ee6e575005b32f195c442c35a2/1-basic/dubbo-samples-api/README.md) file under `dubbo-samples-api` directory. We recommend referencing the samples in that directory by following the below-mentioned instructions: From 5f875ea9581373eb720ff5335db72c5b4cf7c3b3 Mon Sep 17 00:00:00 2001 From: Albumen Kevin Date: Mon, 19 Jun 2023 09:33:36 +0800 Subject: [PATCH 11/32] Fix Registry Notification use same event time (#12556) --- .../java/org/apache/dubbo/registry/RegistryNotifier.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/RegistryNotifier.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/RegistryNotifier.java index 168368690a..fe9296b8e3 100644 --- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/RegistryNotifier.java +++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/RegistryNotifier.java @@ -77,6 +77,14 @@ public abstract class RegistryNotifier { } scheduler.submit(new NotificationTask(this, notifyTime)); } + try { + while (this.lastEventTime == System.currentTimeMillis()) { + // wait to let event time refresh + Thread.sleep(1); + } + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + } } public long getDelayTime() { From d3be69b349bcd5f297eb63bca3344f26cc024b5a Mon Sep 17 00:00:00 2001 From: Albumen Kevin Date: Mon, 19 Jun 2023 09:33:52 +0800 Subject: [PATCH 12/32] Fix config center properties log level (#12555) --- .../org/apache/dubbo/common/config/ConfigurationUtils.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/config/ConfigurationUtils.java b/dubbo-common/src/main/java/org/apache/dubbo/common/config/ConfigurationUtils.java index eaca5a8dbb..efdfe2104d 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/config/ConfigurationUtils.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/config/ConfigurationUtils.java @@ -44,7 +44,6 @@ import java.util.Set; import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_SERVER_SHUTDOWN_TIMEOUT; import static org.apache.dubbo.common.constants.CommonConstants.SHUTDOWN_WAIT_KEY; import static org.apache.dubbo.common.constants.CommonConstants.SHUTDOWN_WAIT_SECONDS_KEY; -import static org.apache.dubbo.common.constants.LoggerCodeConstants.COMMON_UNEXPECTED_EXCEPTION; /** * Utilities for manipulating configurations from different sources @@ -174,7 +173,7 @@ public final class ConfigurationUtils { public static Map parseProperties(String content) throws IOException { Map map = new HashMap<>(); if (StringUtils.isEmpty(content)) { - logger.warn(COMMON_UNEXPECTED_EXCEPTION, "", "", "Config center was specified, but no config item found."); + logger.info("Config center was specified, but no config item found."); } else { Properties properties = new Properties(); properties.load(new StringReader(content)); From 3160602072c198728cca48e449984a4e596e7c37 Mon Sep 17 00:00:00 2001 From: Albumen Kevin Date: Mon, 19 Jun 2023 09:34:06 +0800 Subject: [PATCH 13/32] Rename getModelEnvironment to modelEnvironment (#12551) --- .../DefaultGovernanceRuleRepositoryImpl.java | 2 +- .../ShortestResponseLoadBalance.java | 2 +- .../common/config/ConfigurationUtils.java | 16 +++---- .../common/config/ModuleEnvironment.java | 2 +- .../apache/dubbo/config/AbstractConfig.java | 2 +- .../dubbo/config/AbstractInterfaceConfig.java | 2 +- .../org/apache/dubbo/config/MethodConfig.java | 2 +- .../config/context/AbstractConfigManager.java | 4 +- .../dubbo/rpc/model/ApplicationModel.java | 6 +-- .../dubbo/rpc/model/FrameworkModel.java | 2 +- .../apache/dubbo/rpc/model/ModuleModel.java | 2 +- .../apache/dubbo/rpc/model/ScopeModel.java | 23 +++++++++- .../common/config/ConfigurationUtilsTest.java | 4 +- .../dubbo/common/config/EnvironmentTest.java | 4 +- .../dubbo/rpc/model/ModuleModelTest.java | 2 +- .../dubbo/rpc/model/ScopeModelUtilTest.java | 2 +- .../config/bootstrap/DubboBootstrap.java | 2 +- .../deploy/DefaultApplicationDeployer.java | 2 +- .../config/utils/ConfigValidationUtils.java | 2 +- .../dubbo/config/AbstractConfigTest.java | 44 +++++++++---------- .../dubbo/config/ConfigCenterConfigTest.java | 14 +++--- .../dubbo/config/ConsumerConfigTest.java | 8 ++-- .../config/bootstrap/DubboBootstrapTest.java | 6 +-- .../DubboInfraBeanRegisterPostProcessor.java | 2 +- .../ServiceDiscoveryRegistryDirectory.java | 6 +-- .../migration/MigrationRuleListener.java | 4 +- .../integration/RegistryDirectory.java | 8 ++-- .../integration/RegistryProtocol.java | 12 ++--- .../migration/MigrationRuleListenerTest.java | 12 ++--- .../dubbo/rpc/filter/GenericFilter.java | 2 +- 30 files changed, 111 insertions(+), 90 deletions(-) diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/governance/DefaultGovernanceRuleRepositoryImpl.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/governance/DefaultGovernanceRuleRepositoryImpl.java index 6d6770876b..1d8d7183c3 100644 --- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/governance/DefaultGovernanceRuleRepositoryImpl.java +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/governance/DefaultGovernanceRuleRepositoryImpl.java @@ -54,7 +54,7 @@ public class DefaultGovernanceRuleRepositoryImpl implements GovernanceRuleReposi } private DynamicConfiguration getDynamicConfiguration() { - return moduleModel.getModelEnvironment().getDynamicConfiguration().orElse(null); + return moduleModel.modelEnvironment().getDynamicConfiguration().orElse(null); } } diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/loadbalance/ShortestResponseLoadBalance.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/loadbalance/ShortestResponseLoadBalance.java index 67df332e48..1244e76147 100644 --- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/loadbalance/ShortestResponseLoadBalance.java +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/loadbalance/ShortestResponseLoadBalance.java @@ -59,7 +59,7 @@ public class ShortestResponseLoadBalance extends AbstractLoadBalance implements @Override public void setApplicationModel(ApplicationModel applicationModel) { - slidePeriod = applicationModel.getModelEnvironment().getConfiguration().getInt(Constants.SHORTEST_RESPONSE_SLIDE_PERIOD, 30_000); + slidePeriod = applicationModel.modelEnvironment().getConfiguration().getInt(Constants.SHORTEST_RESPONSE_SLIDE_PERIOD, 30_000); executorService = applicationModel.getFrameworkModel().getBeanFactory() .getBean(FrameworkExecutorRepository.class).getSharedExecutor(); } diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/config/ConfigurationUtils.java b/dubbo-common/src/main/java/org/apache/dubbo/common/config/ConfigurationUtils.java index efdfe2104d..dae8a0ca03 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/config/ConfigurationUtils.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/config/ConfigurationUtils.java @@ -76,7 +76,7 @@ public final class ConfigurationUtils { * @return */ public static Configuration getSystemConfiguration(ScopeModel scopeModel) { - return getScopeModelOrDefaultApplicationModel(scopeModel).getModelEnvironment().getSystemConfiguration(); + return getScopeModelOrDefaultApplicationModel(scopeModel).modelEnvironment().getSystemConfiguration(); } /** @@ -85,7 +85,7 @@ public final class ConfigurationUtils { * @return */ public static Configuration getEnvConfiguration(ScopeModel scopeModel) { - return getScopeModelOrDefaultApplicationModel(scopeModel).getModelEnvironment().getEnvironmentConfiguration(); + return getScopeModelOrDefaultApplicationModel(scopeModel).modelEnvironment().getEnvironmentConfiguration(); } /** @@ -97,11 +97,11 @@ public final class ConfigurationUtils { */ public static Configuration getGlobalConfiguration(ScopeModel scopeModel) { - return getScopeModelOrDefaultApplicationModel(scopeModel).getModelEnvironment().getConfiguration(); + return getScopeModelOrDefaultApplicationModel(scopeModel).modelEnvironment().getConfiguration(); } public static Configuration getDynamicGlobalConfiguration(ScopeModel scopeModel) { - return scopeModel.getModelEnvironment().getDynamicGlobalConfiguration(); + return scopeModel.modelEnvironment().getDynamicGlobalConfiguration(); } // FIXME @@ -364,7 +364,7 @@ public final class ConfigurationUtils { */ @Deprecated public static Configuration getSystemConfiguration() { - return ApplicationModel.defaultModel().getModelEnvironment().getSystemConfiguration(); + return ApplicationModel.defaultModel().modelEnvironment().getSystemConfiguration(); } /** @@ -374,7 +374,7 @@ public final class ConfigurationUtils { */ @Deprecated public static Configuration getEnvConfiguration() { - return ApplicationModel.defaultModel().getModelEnvironment().getEnvironmentConfiguration(); + return ApplicationModel.defaultModel().modelEnvironment().getEnvironmentConfiguration(); } /** @@ -384,7 +384,7 @@ public final class ConfigurationUtils { */ @Deprecated public static Configuration getGlobalConfiguration() { - return ApplicationModel.defaultModel().getModelEnvironment().getConfiguration(); + return ApplicationModel.defaultModel().modelEnvironment().getConfiguration(); } /** @@ -394,7 +394,7 @@ public final class ConfigurationUtils { */ @Deprecated public static Configuration getDynamicGlobalConfiguration() { - return ApplicationModel.defaultModel().getDefaultModule().getModelEnvironment().getDynamicGlobalConfiguration(); + return ApplicationModel.defaultModel().getDefaultModule().modelEnvironment().getDynamicGlobalConfiguration(); } /** diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/config/ModuleEnvironment.java b/dubbo-common/src/main/java/org/apache/dubbo/common/config/ModuleEnvironment.java index 673815afb1..cf51624262 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/config/ModuleEnvironment.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/config/ModuleEnvironment.java @@ -54,7 +54,7 @@ public class ModuleEnvironment extends Environment implements ModuleExt { public ModuleEnvironment(ModuleModel moduleModel) { super(moduleModel); this.moduleModel = moduleModel; - this.applicationDelegate = moduleModel.getApplicationModel().getModelEnvironment(); + this.applicationDelegate = moduleModel.getApplicationModel().modelEnvironment(); } @Override diff --git a/dubbo-common/src/main/java/org/apache/dubbo/config/AbstractConfig.java b/dubbo-common/src/main/java/org/apache/dubbo/config/AbstractConfig.java index 3e4daf34bc..eee83f501c 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/config/AbstractConfig.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/config/AbstractConfig.java @@ -696,7 +696,7 @@ public abstract class AbstractConfig implements Serializable { } protected void refreshWithPrefixes(List prefixes, ConfigMode configMode) { - Environment environment = getScopeModel().getModelEnvironment(); + Environment environment = getScopeModel().modelEnvironment(); List> configurationMaps = environment.getConfigurationMaps(); // Search props starts with PREFIX in order diff --git a/dubbo-common/src/main/java/org/apache/dubbo/config/AbstractInterfaceConfig.java b/dubbo-common/src/main/java/org/apache/dubbo/config/AbstractInterfaceConfig.java index 450d49f605..8b0f4c4167 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/config/AbstractInterfaceConfig.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/config/AbstractInterfaceConfig.java @@ -302,7 +302,7 @@ public abstract class AbstractInterfaceConfig extends AbstractMethodConfig { } protected Environment getEnvironment() { - return getScopeModel().getModelEnvironment(); + return getScopeModel().modelEnvironment(); } @Override diff --git a/dubbo-common/src/main/java/org/apache/dubbo/config/MethodConfig.java b/dubbo-common/src/main/java/org/apache/dubbo/config/MethodConfig.java index d8696fadc4..914002e1a4 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/config/MethodConfig.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/config/MethodConfig.java @@ -236,7 +236,7 @@ public class MethodConfig extends AbstractMethodConfig { private void refreshArgument(ArgumentConfig argument, InmemoryConfiguration subPropsConfiguration) { if (argument.getIndex() != null && argument.getIndex() >= 0) { String prefix = argument.getIndex() + "."; - Environment environment = getScopeModel().getModelEnvironment(); + Environment environment = getScopeModel().modelEnvironment(); List methods = MethodUtils.getMethods(argument.getClass(), method -> method.getDeclaringClass() != Object.class); for (java.lang.reflect.Method method : methods) { diff --git a/dubbo-common/src/main/java/org/apache/dubbo/config/context/AbstractConfigManager.java b/dubbo-common/src/main/java/org/apache/dubbo/config/context/AbstractConfigManager.java index 8a5dfdd79b..0f8a0e23d4 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/config/context/AbstractConfigManager.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/config/context/AbstractConfigManager.java @@ -105,7 +105,7 @@ public abstract class AbstractConfigManager extends LifecycleAdapter { this.scopeModel = scopeModel; this.applicationModel = ScopeModelUtil.getApplicationModel(scopeModel); this.supportedConfigTypes = supportedConfigTypes; - environment = scopeModel.getModelEnvironment(); + environment = scopeModel.modelEnvironment(); } @Override @@ -113,7 +113,7 @@ public abstract class AbstractConfigManager extends LifecycleAdapter { if (!initialized.compareAndSet(false, true)) { return; } - CompositeConfiguration configuration = scopeModel.getModelEnvironment().getConfiguration(); + CompositeConfiguration configuration = scopeModel.modelEnvironment().getConfiguration(); // dubbo.config.mode String configModeStr = (String) configuration.getProperty(ConfigKeys.DUBBO_CONFIG_MODE); diff --git a/dubbo-common/src/main/java/org/apache/dubbo/rpc/model/ApplicationModel.java b/dubbo-common/src/main/java/org/apache/dubbo/rpc/model/ApplicationModel.java index 0978143257..0544df59ed 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/rpc/model/ApplicationModel.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/rpc/model/ApplicationModel.java @@ -201,7 +201,7 @@ public class ApplicationModel extends ScopeModel { } @Override - public Environment getModelEnvironment() { + public Environment modelEnvironment() { if (environment == null) { environment = (Environment) this.getExtensionLoader(ApplicationExt.class) .getExtension(Environment.NAME); @@ -390,11 +390,11 @@ public class ApplicationModel extends ScopeModel { } /** - * @deprecated Replace to {@link ScopeModel#getModelEnvironment()} + * @deprecated Replace to {@link ScopeModel#modelEnvironment()} */ @Deprecated public static Environment getEnvironment() { - return defaultModel().getModelEnvironment(); + return defaultModel().modelEnvironment(); } /** diff --git a/dubbo-common/src/main/java/org/apache/dubbo/rpc/model/FrameworkModel.java b/dubbo-common/src/main/java/org/apache/dubbo/rpc/model/FrameworkModel.java index 2bdfa9f577..09a001f3bb 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/rpc/model/FrameworkModel.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/rpc/model/FrameworkModel.java @@ -367,7 +367,7 @@ public class FrameworkModel extends ScopeModel { } @Override - public Environment getModelEnvironment() { + public Environment modelEnvironment() { throw new UnsupportedOperationException("Environment is inaccessible for FrameworkModel"); } diff --git a/dubbo-common/src/main/java/org/apache/dubbo/rpc/model/ModuleModel.java b/dubbo-common/src/main/java/org/apache/dubbo/rpc/model/ModuleModel.java index 5422c6169a..358868af69 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/rpc/model/ModuleModel.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/rpc/model/ModuleModel.java @@ -150,7 +150,7 @@ public class ModuleModel extends ScopeModel { } @Override - public ModuleEnvironment getModelEnvironment() { + public ModuleEnvironment modelEnvironment() { if (moduleEnvironment == null) { moduleEnvironment = (ModuleEnvironment) this.getExtensionLoader(ModuleExt.class) .getExtension(ModuleEnvironment.NAME); diff --git a/dubbo-common/src/main/java/org/apache/dubbo/rpc/model/ScopeModel.java b/dubbo-common/src/main/java/org/apache/dubbo/rpc/model/ScopeModel.java index bbf1bcc987..a96df0eb43 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/rpc/model/ScopeModel.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/rpc/model/ScopeModel.java @@ -243,7 +243,28 @@ public abstract class ScopeModel implements ExtensionAccessor { return Collections.unmodifiableSet(classLoaders); } - public abstract Environment getModelEnvironment(); + /** + * Get current model's environment. + *
+ * Note: This method should not start with `get` or it would be invoked due to Spring boot refresh. + * @see Configuration refresh issue + */ + public abstract Environment modelEnvironment(); + + /** + * Get current model's environment. + * + * @see Configuration refresh issue + * @deprecated use modelEnvironment() instead + */ + @Deprecated + public final Environment getModelEnvironment() { + try { + return modelEnvironment(); + } catch (Exception ex) { + return null; + } + } public String getInternalId() { return this.internalId; diff --git a/dubbo-common/src/test/java/org/apache/dubbo/common/config/ConfigurationUtilsTest.java b/dubbo-common/src/test/java/org/apache/dubbo/common/config/ConfigurationUtilsTest.java index de3bd2df71..16853eb32e 100644 --- a/dubbo-common/src/test/java/org/apache/dubbo/common/config/ConfigurationUtilsTest.java +++ b/dubbo-common/src/test/java/org/apache/dubbo/common/config/ConfigurationUtilsTest.java @@ -37,7 +37,7 @@ class ConfigurationUtilsTest { FrameworkModel frameworkModel = new FrameworkModel(); ApplicationModel applicationModel = frameworkModel.newApplication(); - Environment originApplicationEnvironment = applicationModel.getModelEnvironment(); + Environment originApplicationEnvironment = applicationModel.modelEnvironment(); Environment applicationEnvironment = Mockito.spy(originApplicationEnvironment); applicationModel.setEnvironment(applicationEnvironment); @@ -52,7 +52,7 @@ class ConfigurationUtilsTest { Assertions.assertEquals("a", ConfigurationUtils.getCachedDynamicProperty(applicationModel, "TestKey", "xxx")); ModuleModel moduleModel = applicationModel.newModule(); - ModuleEnvironment originModuleEnvironment = moduleModel.getModelEnvironment(); + ModuleEnvironment originModuleEnvironment = moduleModel.modelEnvironment(); ModuleEnvironment moduleEnvironment = Mockito.spy(originModuleEnvironment); moduleModel.setModuleEnvironment(moduleEnvironment); diff --git a/dubbo-common/src/test/java/org/apache/dubbo/common/config/EnvironmentTest.java b/dubbo-common/src/test/java/org/apache/dubbo/common/config/EnvironmentTest.java index 5d502fffaa..e0a1204193 100644 --- a/dubbo-common/src/test/java/org/apache/dubbo/common/config/EnvironmentTest.java +++ b/dubbo-common/src/test/java/org/apache/dubbo/common/config/EnvironmentTest.java @@ -39,7 +39,7 @@ class EnvironmentTest { @Test void testResolvePlaceholders() { - Environment environment = ApplicationModel.defaultModel().getModelEnvironment(); + Environment environment = ApplicationModel.defaultModel().modelEnvironment(); Map externalMap = new LinkedHashMap<>(); externalMap.put("zookeeper.address", "127.0.0.1"); @@ -65,7 +65,7 @@ class EnvironmentTest { void test() { FrameworkModel frameworkModel = new FrameworkModel(); ApplicationModel applicationModel = frameworkModel.newApplication(); - Environment environment = applicationModel.getModelEnvironment(); + Environment environment = applicationModel.modelEnvironment(); // test getPrefixedConfiguration RegistryConfig registryConfig = new RegistryConfig(); diff --git a/dubbo-common/src/test/java/org/apache/dubbo/rpc/model/ModuleModelTest.java b/dubbo-common/src/test/java/org/apache/dubbo/rpc/model/ModuleModelTest.java index 2f76c09edb..4bf1b6f748 100644 --- a/dubbo-common/src/test/java/org/apache/dubbo/rpc/model/ModuleModelTest.java +++ b/dubbo-common/src/test/java/org/apache/dubbo/rpc/model/ModuleModelTest.java @@ -61,7 +61,7 @@ class ModuleModelTest { ApplicationModel applicationModel = frameworkModel.newApplication(); ModuleModel moduleModel = applicationModel.newModule(); - ModuleEnvironment modelEnvironment = moduleModel.getModelEnvironment(); + ModuleEnvironment modelEnvironment = moduleModel.modelEnvironment(); Assertions.assertNotNull(modelEnvironment); frameworkModel.destroy(); diff --git a/dubbo-common/src/test/java/org/apache/dubbo/rpc/model/ScopeModelUtilTest.java b/dubbo-common/src/test/java/org/apache/dubbo/rpc/model/ScopeModelUtilTest.java index dcf0cfba79..2e90314da1 100644 --- a/dubbo-common/src/test/java/org/apache/dubbo/rpc/model/ScopeModelUtilTest.java +++ b/dubbo-common/src/test/java/org/apache/dubbo/rpc/model/ScopeModelUtilTest.java @@ -108,7 +108,7 @@ class ScopeModelUtilTest { } @Override - public Environment getModelEnvironment() { + public Environment modelEnvironment() { return null; } diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/bootstrap/DubboBootstrap.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/bootstrap/DubboBootstrap.java index 2002ec0cb0..bfb2278fb6 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/bootstrap/DubboBootstrap.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/bootstrap/DubboBootstrap.java @@ -162,7 +162,7 @@ public final class DubboBootstrap { private DubboBootstrap(ApplicationModel applicationModel) { this.applicationModel = applicationModel; configManager = applicationModel.getApplicationConfigManager(); - environment = applicationModel.getModelEnvironment(); + environment = applicationModel.modelEnvironment(); executorRepository = ExecutorRepository.getInstance(applicationModel); applicationDeployer = applicationModel.getDeployer(); diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/deploy/DefaultApplicationDeployer.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/deploy/DefaultApplicationDeployer.java index af73f59ad2..6302ee6eb3 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/deploy/DefaultApplicationDeployer.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/deploy/DefaultApplicationDeployer.java @@ -146,7 +146,7 @@ public class DefaultApplicationDeployer extends AbstractDeployer 0) { System.setProperty(SHUTDOWN_WAIT_KEY, wait.trim()); diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/AbstractConfigTest.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/AbstractConfigTest.java index 02e93d69b2..0a811bbae5 100644 --- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/AbstractConfigTest.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/AbstractConfigTest.java @@ -335,8 +335,8 @@ class AbstractConfigTest { external.put("dubbo.override.key", "external"); // @Parameter(key="key2", useKeyAsProperty=true) external.put("dubbo.override.key2", "external"); - ApplicationModel.defaultModel().getModelEnvironment().initialize(); - ApplicationModel.defaultModel().getModelEnvironment().setExternalConfigMap(external); + ApplicationModel.defaultModel().modelEnvironment().initialize(); + ApplicationModel.defaultModel().modelEnvironment().setExternalConfigMap(external); SysProps.setProperty("dubbo.override.address", "system://127.0.0.1:2181"); SysProps.setProperty("dubbo.override.protocol", "system"); @@ -353,7 +353,7 @@ class AbstractConfigTest { Assertions.assertEquals("external", overrideConfig.getKey()); Assertions.assertEquals("system", overrideConfig.getKey2()); } finally { - ApplicationModel.defaultModel().getModelEnvironment().destroy(); + ApplicationModel.defaultModel().modelEnvironment().destroy(); } } @@ -377,14 +377,14 @@ class AbstractConfigTest { Assertions.assertEquals("override-config://", overrideConfig.getEscape()); Assertions.assertEquals("system", overrideConfig.getKey()); } finally { - ApplicationModel.defaultModel().getModelEnvironment().destroy(); + ApplicationModel.defaultModel().modelEnvironment().destroy(); } } @Test void testRefreshProperties() throws Exception { try { - ApplicationModel.defaultModel().getModelEnvironment().setExternalConfigMap(new HashMap<>()); + ApplicationModel.defaultModel().modelEnvironment().setExternalConfigMap(new HashMap<>()); OverrideConfig overrideConfig = new OverrideConfig(); overrideConfig.setAddress("override-config://127.0.0.1:2181"); overrideConfig.setProtocol("override-config"); @@ -392,7 +392,7 @@ class AbstractConfigTest { Properties properties = new Properties(); properties.load(this.getClass().getResourceAsStream("/dubbo.properties")); - ApplicationModel.defaultModel().getModelEnvironment().getPropertiesConfiguration().setProperties(properties); + ApplicationModel.defaultModel().modelEnvironment().getPropertiesConfiguration().setProperties(properties); overrideConfig.refresh(); @@ -402,7 +402,7 @@ class AbstractConfigTest { Assertions.assertEquals("properties", overrideConfig.getKey2()); //Assertions.assertEquals("properties", overrideConfig.getUseKeyAsProperty()); } finally { - ApplicationModel.defaultModel().getModelEnvironment().destroy(); + ApplicationModel.defaultModel().modelEnvironment().destroy(); } } @@ -425,8 +425,8 @@ class AbstractConfigTest { external.put("dubbo.override.key", "external"); // @Parameter(key="key2", useKeyAsProperty=true) external.put("dubbo.override.key2", "external"); - ApplicationModel.defaultModel().getModelEnvironment().initialize(); - ApplicationModel.defaultModel().getModelEnvironment().setExternalConfigMap(external); + ApplicationModel.defaultModel().modelEnvironment().initialize(); + ApplicationModel.defaultModel().modelEnvironment().setExternalConfigMap(external); overrideConfig.refresh(); @@ -437,7 +437,7 @@ class AbstractConfigTest { Assertions.assertEquals("external", overrideConfig.getKey()); Assertions.assertEquals("external", overrideConfig.getKey2()); } finally { - ApplicationModel.defaultModel().getModelEnvironment().destroy(); + ApplicationModel.defaultModel().modelEnvironment().destroy(); } } @@ -457,8 +457,8 @@ class AbstractConfigTest { external.put("dubbo.overrides.override-id.key2", "external"); external.put("dubbo.override.address", "external://127.0.0.1:2181"); external.put("dubbo.override.exclude", "external"); - ApplicationModel.defaultModel().getModelEnvironment().initialize(); - ApplicationModel.defaultModel().getModelEnvironment().setExternalConfigMap(external); + ApplicationModel.defaultModel().modelEnvironment().initialize(); + ApplicationModel.defaultModel().modelEnvironment().setExternalConfigMap(external); // refresh config overrideConfig.refresh(); @@ -469,7 +469,7 @@ class AbstractConfigTest { Assertions.assertEquals("external", overrideConfig.getKey()); Assertions.assertEquals("external", overrideConfig.getKey2()); } finally { - ApplicationModel.defaultModel().getModelEnvironment().destroy(); + ApplicationModel.defaultModel().modelEnvironment().destroy(); } } @@ -485,8 +485,8 @@ class AbstractConfigTest { Map external = new HashMap<>(); external.put("dubbo.override.parameters", "[{key3:value3},{key4:value4},{key2:value5}]"); - ApplicationModel.defaultModel().getModelEnvironment().initialize(); - ApplicationModel.defaultModel().getModelEnvironment().setExternalConfigMap(external); + ApplicationModel.defaultModel().modelEnvironment().initialize(); + ApplicationModel.defaultModel().modelEnvironment().setExternalConfigMap(external); // refresh config overrideConfig.refresh(); @@ -502,7 +502,7 @@ class AbstractConfigTest { Assertions.assertEquals("value6", overrideConfig.getParameters().get("key3")); Assertions.assertEquals("value4", overrideConfig.getParameters().get("key4")); } finally { - ApplicationModel.defaultModel().getModelEnvironment().destroy(); + ApplicationModel.defaultModel().modelEnvironment().destroy(); } } @@ -514,7 +514,7 @@ class AbstractConfigTest { overrideConfig.refresh(); assertEquals("value00", overrideConfig.getParameters().get("key00")); } finally { - ApplicationModel.defaultModel().getModelEnvironment().destroy(); + ApplicationModel.defaultModel().modelEnvironment().destroy(); } } @@ -587,14 +587,14 @@ class AbstractConfigTest { external.put("notConflictKey", "value-from-external"); external.put("dubbo.override.notConflictKey2", "value-from-external"); - ApplicationModel.defaultModel().getModelEnvironment().setExternalConfigMap(external); + ApplicationModel.defaultModel().modelEnvironment().setExternalConfigMap(external); overrideConfig.refresh(); Assertions.assertEquals("value-from-config", overrideConfig.getNotConflictKey()); Assertions.assertEquals("value-from-external", overrideConfig.getNotConflictKey2()); } finally { - ApplicationModel.defaultModel().getModelEnvironment().destroy(); + ApplicationModel.defaultModel().modelEnvironment().destroy(); } } @@ -1021,8 +1021,8 @@ class AbstractConfigTest { external.put("dubbo.outer.a1", "1"); external.put("dubbo.outer.b.b1", "11"); external.put("dubbo.outer.b.b2", "12"); - ApplicationModel.defaultModel().getModelEnvironment().initialize(); - ApplicationModel.defaultModel().getModelEnvironment().setExternalConfigMap(external); + ApplicationModel.defaultModel().modelEnvironment().initialize(); + ApplicationModel.defaultModel().modelEnvironment().setExternalConfigMap(external); // refresh config outerConfig.refresh(); @@ -1031,7 +1031,7 @@ class AbstractConfigTest { Assertions.assertEquals(11, outerConfig.getB().getB1()); Assertions.assertEquals(12, outerConfig.getB().getB2()); } finally { - ApplicationModel.defaultModel().getModelEnvironment().destroy(); + ApplicationModel.defaultModel().modelEnvironment().destroy(); } } diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/ConfigCenterConfigTest.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/ConfigCenterConfigTest.java index 961feee93b..0af13133ca 100644 --- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/ConfigCenterConfigTest.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/ConfigCenterConfigTest.java @@ -160,8 +160,8 @@ class ConfigCenterConfigTest { ApplicationModel.defaultModel().getDefaultModule(); // Config instance has id, dubbo props has no id - ApplicationModel.defaultModel().getModelEnvironment().getPropertiesConfiguration().setProperty("dubbo.config-center.check", "false"); - ApplicationModel.defaultModel().getModelEnvironment().getPropertiesConfiguration().setProperty("dubbo.config-center.timeout", "1234"); + ApplicationModel.defaultModel().modelEnvironment().getPropertiesConfiguration().setProperty("dubbo.config-center.check", "false"); + ApplicationModel.defaultModel().modelEnvironment().getPropertiesConfiguration().setProperty("dubbo.config-center.timeout", "1234"); try { // Config instance has id @@ -179,7 +179,7 @@ class ConfigCenterConfigTest { Assertions.assertEquals(3000L, configCenter.getTimeout()); Assertions.assertEquals(false, configCenter.isCheck()); } finally { - ApplicationModel.defaultModel().getModelEnvironment().getPropertiesConfiguration().refresh(); + ApplicationModel.defaultModel().modelEnvironment().getPropertiesConfiguration().refresh(); DubboBootstrap.getInstance().stop(); } } @@ -215,8 +215,8 @@ class ConfigCenterConfigTest { ApplicationModel.defaultModel().getDefaultModule(); // Config instance has id, dubbo props has id - ApplicationModel.defaultModel().getModelEnvironment().getPropertiesConfiguration().setProperty("dubbo.config-centers.configcenterA.check", "false"); - ApplicationModel.defaultModel().getModelEnvironment().getPropertiesConfiguration().setProperty("dubbo.config-centers.configcenterA.timeout", "1234"); + ApplicationModel.defaultModel().modelEnvironment().getPropertiesConfiguration().setProperty("dubbo.config-centers.configcenterA.check", "false"); + ApplicationModel.defaultModel().modelEnvironment().getPropertiesConfiguration().setProperty("dubbo.config-centers.configcenterA.timeout", "1234"); try { // Config instance has id @@ -235,7 +235,7 @@ class ConfigCenterConfigTest { Assertions.assertEquals(3000L, configCenter.getTimeout()); Assertions.assertEquals(false, configCenter.isCheck()); } finally { - ApplicationModel.defaultModel().getModelEnvironment().getPropertiesConfiguration().refresh(); + ApplicationModel.defaultModel().modelEnvironment().getPropertiesConfiguration().refresh(); DubboBootstrap.getInstance().stop(); } } @@ -294,4 +294,4 @@ class ConfigCenterConfigTest { Assertions.assertEquals("pass123", cc.getPassword()); } -} \ No newline at end of file +} diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/ConsumerConfigTest.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/ConsumerConfigTest.java index 7f2283e47d..1a303ced7b 100644 --- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/ConsumerConfigTest.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/ConsumerConfigTest.java @@ -187,9 +187,9 @@ class ConsumerConfigTest { @Test void testOverrideConfigByDubboProps() { ApplicationModel.defaultModel().getDefaultModule(); - ApplicationModel.defaultModel().getModelEnvironment().getPropertiesConfiguration().setProperty("dubbo.consumers.consumerA.check", "false"); - ApplicationModel.defaultModel().getModelEnvironment().getPropertiesConfiguration().setProperty("dubbo.consumers.consumerA.group", "demo"); - ApplicationModel.defaultModel().getModelEnvironment().getPropertiesConfiguration().setProperty("dubbo.consumers.consumerA.threads", "10"); + ApplicationModel.defaultModel().modelEnvironment().getPropertiesConfiguration().setProperty("dubbo.consumers.consumerA.check", "false"); + ApplicationModel.defaultModel().modelEnvironment().getPropertiesConfiguration().setProperty("dubbo.consumers.consumerA.group", "demo"); + ApplicationModel.defaultModel().modelEnvironment().getPropertiesConfiguration().setProperty("dubbo.consumers.consumerA.threads", "10"); try { ConsumerConfig consumerConfig = new ConsumerConfig(); @@ -208,7 +208,7 @@ class ConsumerConfigTest { Assertions.assertEquals("groupA", consumerConfig.getGroup()); Assertions.assertEquals(10, consumerConfig.getThreads()); } finally { - ApplicationModel.defaultModel().getModelEnvironment().getPropertiesConfiguration().refresh(); + ApplicationModel.defaultModel().modelEnvironment().getPropertiesConfiguration().refresh(); DubboBootstrap.getInstance().destroy(); } } diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/bootstrap/DubboBootstrapTest.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/bootstrap/DubboBootstrapTest.java index f65b14d0ba..2852bf55d4 100644 --- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/bootstrap/DubboBootstrapTest.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/bootstrap/DubboBootstrapTest.java @@ -115,13 +115,13 @@ class DubboBootstrapTest { System.clearProperty(SHUTDOWN_WAIT_SECONDS_KEY); writeDubboProperties(SHUTDOWN_WAIT_KEY, "100"); - ApplicationModel.defaultModel().getModelEnvironment().getPropertiesConfiguration().refresh(); + ApplicationModel.defaultModel().modelEnvironment().getPropertiesConfiguration().refresh(); ConfigValidationUtils.validateApplicationConfig(new ApplicationConfig("demo")); Assertions.assertEquals("100", System.getProperty(SHUTDOWN_WAIT_KEY)); System.clearProperty(SHUTDOWN_WAIT_KEY); writeDubboProperties(SHUTDOWN_WAIT_SECONDS_KEY, "1000"); - ApplicationModel.defaultModel().getModelEnvironment().getPropertiesConfiguration().refresh(); + ApplicationModel.defaultModel().modelEnvironment().getPropertiesConfiguration().refresh(); ConfigValidationUtils.validateApplicationConfig(new ApplicationConfig("demo")); Assertions.assertEquals("1000", System.getProperty(SHUTDOWN_WAIT_SECONDS_KEY)); } finally { @@ -369,4 +369,4 @@ class DubboBootstrapTest { } -} \ No newline at end of file +} diff --git a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/context/DubboInfraBeanRegisterPostProcessor.java b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/context/DubboInfraBeanRegisterPostProcessor.java index d9f4f2b2ce..fcd759578e 100644 --- a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/context/DubboInfraBeanRegisterPostProcessor.java +++ b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/context/DubboInfraBeanRegisterPostProcessor.java @@ -85,7 +85,7 @@ public class DubboInfraBeanRegisterPostProcessor implements BeanDefinitionRegist // Extract dubbo props from Spring env and put them to app config ConfigurableEnvironment environment = (ConfigurableEnvironment) applicationContext.getEnvironment(); SortedMap dubboProperties = EnvironmentUtils.filterDubboProperties(environment); - applicationModel.getModelEnvironment().setAppConfigMap(dubboProperties); + applicationModel.modelEnvironment().setAppConfigMap(dubboProperties); // register ConfigManager singleton beanFactory.registerSingleton(ConfigManager.BEAN_NAME, applicationModel.getApplicationConfigManager()); diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/ServiceDiscoveryRegistryDirectory.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/ServiceDiscoveryRegistryDirectory.java index eac73aec83..baec948745 100644 --- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/ServiceDiscoveryRegistryDirectory.java +++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/ServiceDiscoveryRegistryDirectory.java @@ -124,7 +124,7 @@ public class ServiceDiscoveryRegistryDirectory extends DynamicDirectory { @Override public void subscribe(URL url) { - if (moduleModel.getModelEnvironment().getConfiguration().convert(Boolean.class, Constants.ENABLE_CONFIGURATION_LISTEN, true)) { + if (moduleModel.modelEnvironment().getConfiguration().convert(Boolean.class, Constants.ENABLE_CONFIGURATION_LISTEN, true)) { enableConfigurationListen = true; getConsumerConfigurationListener(moduleModel).addNotifyListener(this); referenceConfigurationListener = new ReferenceConfigurationListener(this.moduleModel, this, url); @@ -143,7 +143,7 @@ public class ServiceDiscoveryRegistryDirectory extends DynamicDirectory { public void unSubscribe(URL url) { super.unSubscribe(url); this.originalUrls = null; - if (moduleModel.getModelEnvironment().getConfiguration().convert(Boolean.class, Constants.ENABLE_CONFIGURATION_LISTEN, true)) { + if (moduleModel.modelEnvironment().getConfiguration().convert(Boolean.class, Constants.ENABLE_CONFIGURATION_LISTEN, true)) { getConsumerConfigurationListener(moduleModel).removeNotifyListener(this); referenceConfigurationListener.stop(); } @@ -152,7 +152,7 @@ public class ServiceDiscoveryRegistryDirectory extends DynamicDirectory { @Override public void destroy() { super.destroy(); - if (moduleModel.getModelEnvironment().getConfiguration().convert(Boolean.class, Constants.ENABLE_CONFIGURATION_LISTEN, true)) { + if (moduleModel.modelEnvironment().getConfiguration().convert(Boolean.class, Constants.ENABLE_CONFIGURATION_LISTEN, true)) { getConsumerConfigurationListener(moduleModel).removeNotifyListener(this); referenceConfigurationListener.stop(); } diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/migration/MigrationRuleListener.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/migration/MigrationRuleListener.java index 02e877ca89..de6abfd39b 100644 --- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/migration/MigrationRuleListener.java +++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/migration/MigrationRuleListener.java @@ -97,7 +97,7 @@ public class MigrationRuleListener implements RegistryProtocolListener, Configur private void init() { this.ruleKey = moduleModel.getApplicationModel().getApplicationName() + ".migration"; - this.configuration = moduleModel.getModelEnvironment().getDynamicConfiguration().orElse(null); + this.configuration = moduleModel.modelEnvironment().getDynamicConfiguration().orElse(null); if (this.configuration != null) { logger.info("Listening for migration rules on dataId " + ruleKey + ", group " + DUBBO_SERVICEDISCOVERY_MIGRATION); @@ -115,7 +115,7 @@ public class MigrationRuleListener implements RegistryProtocolListener, Configur setRawRule(INIT); } - String localRawRule = moduleModel.getModelEnvironment().getLocalMigrationRule(); + String localRawRule = moduleModel.modelEnvironment().getLocalMigrationRule(); if (!StringUtils.isEmpty(localRawRule)) { localRuleMigrationFuture = moduleModel.getApplicationModel().getFrameworkModel().getBeanFactory() .getBean(FrameworkExecutorRepository.class).getSharedScheduledExecutor() diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryDirectory.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryDirectory.java index 6405c75eab..2c58510507 100644 --- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryDirectory.java +++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryDirectory.java @@ -138,7 +138,7 @@ public class RegistryDirectory extends DynamicDirectory { return null; } ); - if (moduleModel.getModelEnvironment().getConfiguration().convert(Boolean.class, org.apache.dubbo.registry.Constants.ENABLE_CONFIGURATION_LISTEN, true)) { + if (moduleModel.modelEnvironment().getConfiguration().convert(Boolean.class, org.apache.dubbo.registry.Constants.ENABLE_CONFIGURATION_LISTEN, true)) { consumerConfigurationListener.addNotifyListener(this); referenceConfigurationListener = new ReferenceConfigurationListener(moduleModel, this, url); } @@ -152,7 +152,7 @@ public class RegistryDirectory extends DynamicDirectory { @Override public void unSubscribe(URL url) { super.unSubscribe(url); - if (moduleModel.getModelEnvironment().getConfiguration().convert(Boolean.class, org.apache.dubbo.registry.Constants.ENABLE_CONFIGURATION_LISTEN, true)) { + if (moduleModel.modelEnvironment().getConfiguration().convert(Boolean.class, org.apache.dubbo.registry.Constants.ENABLE_CONFIGURATION_LISTEN, true)) { consumerConfigurationListener.removeNotifyListener(this); if (referenceConfigurationListener != null) { referenceConfigurationListener.stop(); @@ -163,7 +163,7 @@ public class RegistryDirectory extends DynamicDirectory { @Override public void destroy() { super.destroy(); - if (moduleModel.getModelEnvironment().getConfiguration().convert(Boolean.class, org.apache.dubbo.registry.Constants.ENABLE_CONFIGURATION_LISTEN, true)) { + if (moduleModel.modelEnvironment().getConfiguration().convert(Boolean.class, org.apache.dubbo.registry.Constants.ENABLE_CONFIGURATION_LISTEN, true)) { consumerConfigurationListener.removeNotifyListener(this); if (referenceConfigurationListener != null) { referenceConfigurationListener.stop(); @@ -183,7 +183,7 @@ public class RegistryDirectory extends DynamicDirectory { .filter(this::isNotCompatibleFor26x) .collect(Collectors.groupingBy(this::judgeCategory)); - if (moduleModel.getModelEnvironment().getConfiguration().convert(Boolean.class, ENABLE_26X_CONFIGURATION_LISTEN, true)) { + if (moduleModel.modelEnvironment().getConfiguration().convert(Boolean.class, ENABLE_26X_CONFIGURATION_LISTEN, true)) { List configuratorURLs = categoryUrls.getOrDefault(CONFIGURATORS_CATEGORY, Collections.emptyList()); this.configurators = Configurator.toConfigurators(configuratorURLs).orElse(this.configurators); diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryProtocol.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryProtocol.java index 33f872ac75..a9e3b908c7 100644 --- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryProtocol.java +++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryProtocol.java @@ -276,7 +276,7 @@ public class RegistryProtocol implements Protocol, ScopeModelAware { exporter.setRegistered(register); ApplicationModel applicationModel = getApplicationModel(providerUrl.getScopeModel()); - if (applicationModel.getModelEnvironment().getConfiguration().convert(Boolean.class, ENABLE_26X_CONFIGURATION_LISTEN, true)) { + if (applicationModel.modelEnvironment().getConfiguration().convert(Boolean.class, ENABLE_26X_CONFIGURATION_LISTEN, true)) { if (!registry.isServiceDiscovery()) { // Deprecated! Subscribe to override rules in 2.6.x or before. registry.subscribe(overrideSubscribeUrl, overrideSubscribeListener); @@ -657,7 +657,7 @@ public class RegistryProtocol implements Protocol, ScopeModelAware { } for (ApplicationModel applicationModel : frameworkModel.getApplicationModels()) { - if (applicationModel.getModelEnvironment().getConfiguration().convert(Boolean.class, org.apache.dubbo.registry.Constants.ENABLE_CONFIGURATION_LISTEN, true)) { + if (applicationModel.modelEnvironment().getConfiguration().convert(Boolean.class, org.apache.dubbo.registry.Constants.ENABLE_CONFIGURATION_LISTEN, true)) { for (ModuleModel moduleModel : applicationModel.getPubModuleModels()) { String applicationName = applicationModel.tryGetApplicationName(); if (applicationName == null) { @@ -869,7 +869,7 @@ public class RegistryProtocol implements Protocol, ScopeModelAware { this.providerUrl = providerUrl; this.notifyListener = notifyListener; this.moduleModel = moduleModel; - if (moduleModel.getModelEnvironment().getConfiguration().convert(Boolean.class, ENABLE_CONFIGURATION_LISTEN, true)) { + if (moduleModel.modelEnvironment().getConfiguration().convert(Boolean.class, ENABLE_CONFIGURATION_LISTEN, true)) { this.initWith(DynamicConfiguration.getRuleKey(providerUrl) + CONFIGURATORS_SUFFIX); } } @@ -899,7 +899,7 @@ public class RegistryProtocol implements Protocol, ScopeModelAware { public ProviderConfigurationListener(ModuleModel moduleModel) { super(moduleModel); this.moduleModel = moduleModel; - if (moduleModel.getModelEnvironment().getConfiguration().convert(Boolean.class, ENABLE_CONFIGURATION_LISTEN, true)) { + if (moduleModel.modelEnvironment().getConfiguration().convert(Boolean.class, ENABLE_CONFIGURATION_LISTEN, true)) { this.initWith(moduleModel.getApplicationModel().getApplicationName() + CONFIGURATORS_SUFFIX); } } @@ -1009,12 +1009,12 @@ public class RegistryProtocol implements Protocol, ScopeModelAware { if (listeners != null) { if (listeners.remove(notifyListener)) { ApplicationModel applicationModel = getApplicationModel(registerUrl.getScopeModel()); - if (applicationModel.getModelEnvironment().getConfiguration().convert(Boolean.class, ENABLE_26X_CONFIGURATION_LISTEN, true)) { + if (applicationModel.modelEnvironment().getConfiguration().convert(Boolean.class, ENABLE_26X_CONFIGURATION_LISTEN, true)) { if (!registry.isServiceDiscovery()) { registry.unsubscribe(subscribeUrl, notifyListener); } } - if (applicationModel.getModelEnvironment().getConfiguration().convert(Boolean.class, ENABLE_CONFIGURATION_LISTEN, true)) { + if (applicationModel.modelEnvironment().getConfiguration().convert(Boolean.class, ENABLE_CONFIGURATION_LISTEN, true)) { for (ModuleModel moduleModel : applicationModel.getPubModuleModels()) { if (moduleModel.getServiceRepository().getExportedServices().size() > 0) { moduleModel.getExtensionLoader(GovernanceRuleRepository.class).getDefaultExtension() diff --git a/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/client/migration/MigrationRuleListenerTest.java b/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/client/migration/MigrationRuleListenerTest.java index 79c74a70dc..6b06bf0f9b 100644 --- a/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/client/migration/MigrationRuleListenerTest.java +++ b/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/client/migration/MigrationRuleListenerTest.java @@ -90,8 +90,8 @@ class MigrationRuleListenerTest { DynamicConfiguration dynamicConfiguration = Mockito.mock(DynamicConfiguration.class); ApplicationModel.reset(); - ApplicationModel.defaultModel().getDefaultModule().getModelEnvironment().setDynamicConfiguration(dynamicConfiguration); - ApplicationModel.defaultModel().getDefaultModule().getModelEnvironment().setLocalMigrationRule(localRule); + ApplicationModel.defaultModel().getDefaultModule().modelEnvironment().setDynamicConfiguration(dynamicConfiguration); + ApplicationModel.defaultModel().getDefaultModule().modelEnvironment().setLocalMigrationRule(localRule); ApplicationConfig applicationConfig = new ApplicationConfig(); applicationConfig.setName("demo-consumer"); ApplicationModel.defaultModel().getApplicationConfigManager().setApplication(applicationConfig); @@ -134,8 +134,8 @@ class MigrationRuleListenerTest { */ @Test void testWithInitAndNoLocalRule() { - ApplicationModel.defaultModel().getDefaultModule().getModelEnvironment().setDynamicConfiguration(null); - ApplicationModel.defaultModel().getDefaultModule().getModelEnvironment().setLocalMigrationRule(""); + ApplicationModel.defaultModel().getDefaultModule().modelEnvironment().setDynamicConfiguration(null); + ApplicationModel.defaultModel().getDefaultModule().modelEnvironment().setLocalMigrationRule(""); ApplicationConfig applicationConfig = new ApplicationConfig(); applicationConfig.setName("demo-consumer"); ApplicationModel.defaultModel().getApplicationConfigManager().setApplication(applicationConfig); @@ -170,8 +170,8 @@ class MigrationRuleListenerTest { DynamicConfiguration dynamicConfiguration = Mockito.mock(DynamicConfiguration.class); Mockito.doReturn(remoteRule).when(dynamicConfiguration).getConfig(Mockito.anyString(), Mockito.anyString()); - ApplicationModel.defaultModel().getDefaultModule().getModelEnvironment().setDynamicConfiguration(dynamicConfiguration); - ApplicationModel.defaultModel().getDefaultModule().getModelEnvironment().setLocalMigrationRule(localRule); + ApplicationModel.defaultModel().getDefaultModule().modelEnvironment().setDynamicConfiguration(dynamicConfiguration); + ApplicationModel.defaultModel().getDefaultModule().modelEnvironment().setLocalMigrationRule(localRule); ApplicationConfig applicationConfig = new ApplicationConfig(); applicationConfig.setName("demo-consumer"); ApplicationModel.defaultModel().getApplicationConfigManager().setApplication(applicationConfig); diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/GenericFilter.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/GenericFilter.java index b69ba505f0..00f23815cd 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/GenericFilter.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/GenericFilter.java @@ -115,7 +115,7 @@ public class GenericFilter implements Filter, Filter.Listener, ScopeModelAware { } else if (ProtocolUtils.isGsonGenericSerialization(generic)) { args = getGsonGenericArgs(args, method.getGenericParameterTypes()); } else if (ProtocolUtils.isJavaGenericSerialization(generic)) { - Configuration configuration = ApplicationModel.ofNullable(applicationModel).getModelEnvironment().getConfiguration(); + Configuration configuration = ApplicationModel.ofNullable(applicationModel).modelEnvironment().getConfiguration(); if (!configuration.getBoolean(CommonConstants.ENABLE_NATIVE_JAVA_GENERIC_SERIALIZE, false)) { String notice = "Trigger the safety barrier! " + "Native Java Serializer is not allowed by default." + From a4e9c9efa4ec79ca6e371141762c3da84718c65f Mon Sep 17 00:00:00 2001 From: Albumen Kevin Date: Mon, 19 Jun 2023 09:34:29 +0800 Subject: [PATCH 14/32] Fix local invoke consumer url override (#12553) --- .../support/wrapper/ScopeClusterInvoker.java | 14 ++++++++++---- .../dubbo/rpc/protocol/injvm/InjvmInvoker.java | 2 +- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/wrapper/ScopeClusterInvoker.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/wrapper/ScopeClusterInvoker.java index a0564c9b0a..98fd33bfef 100644 --- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/wrapper/ScopeClusterInvoker.java +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/support/wrapper/ScopeClusterInvoker.java @@ -20,6 +20,7 @@ package org.apache.dubbo.rpc.cluster.support.wrapper; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.logger.ErrorTypeAwareLogger; import org.apache.dubbo.common.logger.LoggerFactory; +import org.apache.dubbo.common.url.component.DubboServiceAddressURL; import org.apache.dubbo.common.url.component.ServiceConfigURL; import org.apache.dubbo.common.utils.NetUtils; import org.apache.dubbo.rpc.Exporter; @@ -179,7 +180,7 @@ public class ScopeClusterInvoker implements ClusterInvoker, ExporterChange } if (getUrl().getServiceKey().equals(exporter.getInvoker().getUrl().getServiceKey()) && exporter.getInvoker().getUrl().getProtocol().equalsIgnoreCase(LOCAL_PROTOCOL)) { - createInjvmInvoker(); + createInjvmInvoker(exporter); isExported.compareAndSet(false, true); } } @@ -275,14 +276,19 @@ public class ScopeClusterInvoker implements ClusterInvoker, ExporterChange /** * Creates a new Invoker for the current ScopeClusterInvoker and exports it to the local JVM. */ - private void createInjvmInvoker() { + private void createInjvmInvoker(Exporter exporter) { if (injvmInvoker == null) { synchronized (createLock) { if (injvmInvoker == null) { - URL url = new ServiceConfigURL(LOCAL_PROTOCOL, NetUtils.getLocalHost(), getUrl().getPort(), getInterface().getName(), getUrl().getParameters()); + URL url = new ServiceConfigURL(LOCAL_PROTOCOL, NetUtils.getLocalHost(), getUrl().getPort(), + getInterface().getName(), getUrl().getParameters()); url = url.setScopeModel(getUrl().getScopeModel()); url = url.setServiceModel(getUrl().getServiceModel()); - Invoker invoker = protocolSPI.refer(getInterface(), url); + + DubboServiceAddressURL consumerUrl = new DubboServiceAddressURL(url.getUrlAddress(), url.getUrlParam(), + exporter.getInvoker().getUrl(), null); + + Invoker invoker = protocolSPI.refer(getInterface(), consumerUrl); List> invokers = new ArrayList<>(); invokers.add(invoker); injvmInvoker = Cluster.getCluster(url.getScopeModel(), Cluster.DEFAULT, false).join(new StaticDirectory(url, invokers), true); diff --git a/dubbo-rpc/dubbo-rpc-injvm/src/main/java/org/apache/dubbo/rpc/protocol/injvm/InjvmInvoker.java b/dubbo-rpc/dubbo-rpc-injvm/src/main/java/org/apache/dubbo/rpc/protocol/injvm/InjvmInvoker.java index 7e3a1d11fb..971b4f7402 100644 --- a/dubbo-rpc/dubbo-rpc-injvm/src/main/java/org/apache/dubbo/rpc/protocol/injvm/InjvmInvoker.java +++ b/dubbo-rpc/dubbo-rpc-injvm/src/main/java/org/apache/dubbo/rpc/protocol/injvm/InjvmInvoker.java @@ -229,7 +229,7 @@ public class InjvmInvoker extends AbstractInvoker { 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(invoker.getUrl(), args[i], pts[i]); + realArgument[i] = paramDeepCopyUtil.copy(getUrl(), args[i], pts[i]); } } if (realArgument == null) { From 913e66e96586ee1fd30362f76c6d1ac6781bda32 Mon Sep 17 00:00:00 2001 From: wxbty <38374721+wxbty@users.noreply.github.com> Date: Mon, 19 Jun 2023 17:37:37 +0800 Subject: [PATCH 15/32] Supplementary dirctory metrics data push (#12539) * Supplementary dirctory metrics data push * puplish after publish --- .../dubbo/rpc/cluster/directory/AbstractDirectory.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/directory/AbstractDirectory.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/directory/AbstractDirectory.java index a1ea668291..c4561dfe4f 100644 --- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/directory/AbstractDirectory.java +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/directory/AbstractDirectory.java @@ -476,15 +476,21 @@ public abstract class AbstractDirectory implements Directory { } private boolean addValidInvoker(Invoker invoker) { + boolean result; synchronized (this.validInvokers) { - return this.validInvokers.add(invoker); + result = this.validInvokers.add(invoker); } + MetricsEventBus.publish(RegistryEvent.refreshDirectoryEvent(applicationModel, getSummary())); + return result; } private boolean removeValidInvoker(Invoker invoker) { + boolean result; synchronized (this.validInvokers) { - return this.validInvokers.remove(invoker); + result = this.validInvokers.remove(invoker); } + MetricsEventBus.publish(RegistryEvent.refreshDirectoryEvent(applicationModel, getSummary())); + return result; } protected abstract List> doList(SingleRouterChain singleRouterChain, From ddf3da46acfcc31a15c59e0eba489aec10acf23a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 19 Jun 2023 17:38:22 +0800 Subject: [PATCH 16/32] Bump micrometer-core from 1.11.0 to 1.11.1 (#12558) Bumps [micrometer-core](https://github.com/micrometer-metrics/micrometer) from 1.11.0 to 1.11.1. - [Release notes](https://github.com/micrometer-metrics/micrometer/releases) - [Commits](https://github.com/micrometer-metrics/micrometer/compare/v1.11.0...v1.11.1) --- updated-dependencies: - dependency-name: io.micrometer:micrometer-core dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- dubbo-demo/dubbo-demo-spring-boot/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dubbo-demo/dubbo-demo-spring-boot/pom.xml b/dubbo-demo/dubbo-demo-spring-boot/pom.xml index 230e3fc196..6a5f84e772 100644 --- a/dubbo-demo/dubbo-demo-spring-boot/pom.xml +++ b/dubbo-demo/dubbo-demo-spring-boot/pom.xml @@ -38,7 +38,7 @@ true 2.7.12 2.7.12 - 1.11.0 + 1.11.1 From d99bb3df364752cf5b182b6af96d014c421eb933 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 19 Jun 2023 17:38:30 +0800 Subject: [PATCH 17/32] Bump grpc.version from 1.55.1 to 1.56.0 (#12559) Bumps `grpc.version` from 1.55.1 to 1.56.0. Updates `grpc-core` from 1.55.1 to 1.56.0 - [Release notes](https://github.com/grpc/grpc-java/releases) - [Commits](https://github.com/grpc/grpc-java/compare/v1.55.1...v1.56.0) Updates `grpc-stub` from 1.55.1 to 1.56.0 - [Release notes](https://github.com/grpc/grpc-java/releases) - [Commits](https://github.com/grpc/grpc-java/compare/v1.55.1...v1.56.0) Updates `grpc-protobuf` from 1.55.1 to 1.56.0 - [Release notes](https://github.com/grpc/grpc-java/releases) - [Commits](https://github.com/grpc/grpc-java/compare/v1.55.1...v1.56.0) Updates `grpc-context` from 1.55.1 to 1.56.0 - [Release notes](https://github.com/grpc/grpc-java/releases) - [Commits](https://github.com/grpc/grpc-java/compare/v1.55.1...v1.56.0) Updates `grpc-netty-shaded` from 1.55.1 to 1.56.0 - [Release notes](https://github.com/grpc/grpc-java/releases) - [Commits](https://github.com/grpc/grpc-java/compare/v1.55.1...v1.56.0) Updates `grpc-netty` from 1.55.1 to 1.56.0 - [Release notes](https://github.com/grpc/grpc-java/releases) - [Commits](https://github.com/grpc/grpc-java/compare/v1.55.1...v1.56.0) Updates `grpc-grpclb` from 1.55.1 to 1.56.0 - [Release notes](https://github.com/grpc/grpc-java/releases) - [Commits](https://github.com/grpc/grpc-java/compare/v1.55.1...v1.56.0) --- updated-dependencies: - dependency-name: io.grpc:grpc-core dependency-type: direct:production update-type: version-update:semver-minor - dependency-name: io.grpc:grpc-stub dependency-type: direct:production update-type: version-update:semver-minor - dependency-name: io.grpc:grpc-protobuf dependency-type: direct:production update-type: version-update:semver-minor - dependency-name: io.grpc:grpc-context dependency-type: direct:production update-type: version-update:semver-minor - dependency-name: io.grpc:grpc-netty-shaded dependency-type: direct:production update-type: version-update:semver-minor - dependency-name: io.grpc:grpc-netty dependency-type: direct:production update-type: version-update:semver-minor - dependency-name: io.grpc:grpc-grpclb dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- dubbo-dependencies-bom/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dubbo-dependencies-bom/pom.xml b/dubbo-dependencies-bom/pom.xml index 1c3a7eec13..1fc4dfd9a1 100644 --- a/dubbo-dependencies-bom/pom.xml +++ b/dubbo-dependencies-bom/pom.xml @@ -150,7 +150,7 @@ 8.5.87 0.7.5 2.2.3 - 1.55.1 + 1.56.0 0.8.1 1.2.2 From de53cd8b0fd19fc0242b2b3fad43ed6f0aabc665 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 19 Jun 2023 17:38:39 +0800 Subject: [PATCH 18/32] Bump micrometer-bom from 1.11.0 to 1.11.1 (#12560) Bumps [micrometer-bom](https://github.com/micrometer-metrics/micrometer) from 1.11.0 to 1.11.1. - [Release notes](https://github.com/micrometer-metrics/micrometer/releases) - [Commits](https://github.com/micrometer-metrics/micrometer/compare/v1.11.0...v1.11.1) --- updated-dependencies: - dependency-name: io.micrometer:micrometer-bom dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- dubbo-dependencies-bom/pom.xml | 2 +- .../dubbo-spring-boot-starters/observability/pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dubbo-dependencies-bom/pom.xml b/dubbo-dependencies-bom/pom.xml index 1fc4dfd9a1..549ea92052 100644 --- a/dubbo-dependencies-bom/pom.xml +++ b/dubbo-dependencies-bom/pom.xml @@ -133,7 +133,7 @@ 3.12.0 1.8.0 0.1.35 - 1.11.0 + 1.11.1 1.26.0 2.16.4 1.1.1 diff --git a/dubbo-spring-boot/dubbo-spring-boot-starters/observability/pom.xml b/dubbo-spring-boot/dubbo-spring-boot-starters/observability/pom.xml index 17343de508..7bf154f7d7 100644 --- a/dubbo-spring-boot/dubbo-spring-boot-starters/observability/pom.xml +++ b/dubbo-spring-boot/dubbo-spring-boot-starters/observability/pom.xml @@ -38,7 +38,7 @@ - 1.11.0 + 1.11.1 1.1.1 1.27.0 2.16.4 From 5ee7d72a9313e98c208d7b42b7528bef9cc0655a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 19 Jun 2023 17:38:49 +0800 Subject: [PATCH 19/32] Bump native-maven-plugin from 0.9.22 to 0.9.23 (#12561) Bumps [native-maven-plugin](https://github.com/graalvm/native-build-tools) from 0.9.22 to 0.9.23. - [Release notes](https://github.com/graalvm/native-build-tools/releases) - [Commits](https://github.com/graalvm/native-build-tools/compare/0.9.22...0.9.23) --- updated-dependencies: - dependency-name: org.graalvm.buildtools:native-maven-plugin dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- dubbo-demo/dubbo-demo-native/dubbo-demo-native-consumer/pom.xml | 2 +- dubbo-demo/dubbo-demo-native/dubbo-demo-native-provider/pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dubbo-demo/dubbo-demo-native/dubbo-demo-native-consumer/pom.xml b/dubbo-demo/dubbo-demo-native/dubbo-demo-native-consumer/pom.xml index e86b1e5e49..ef128333bd 100644 --- a/dubbo-demo/dubbo-demo-native/dubbo-demo-native-consumer/pom.xml +++ b/dubbo-demo/dubbo-demo-native/dubbo-demo-native-consumer/pom.xml @@ -224,7 +224,7 @@ org.graalvm.buildtools native-maven-plugin - 0.9.22 + 0.9.23 ${project.build.outputDirectory} diff --git a/dubbo-demo/dubbo-demo-native/dubbo-demo-native-provider/pom.xml b/dubbo-demo/dubbo-demo-native/dubbo-demo-native-provider/pom.xml index 3649d381e2..1f2fc06b5b 100644 --- a/dubbo-demo/dubbo-demo-native/dubbo-demo-native-provider/pom.xml +++ b/dubbo-demo/dubbo-demo-native/dubbo-demo-native-provider/pom.xml @@ -222,7 +222,7 @@ org.graalvm.buildtools native-maven-plugin - 0.9.22 + 0.9.23 ${project.build.outputDirectory} From 9797e971fe1f45dd438f1dc3c58a15475666f71e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 19 Jun 2023 17:38:56 +0800 Subject: [PATCH 20/32] Bump reactor-core from 3.5.6 to 3.5.7 (#12562) Bumps [reactor-core](https://github.com/reactor/reactor-core) from 3.5.6 to 3.5.7. - [Release notes](https://github.com/reactor/reactor-core/releases) - [Commits](https://github.com/reactor/reactor-core/compare/v3.5.6...v3.5.7) --- updated-dependencies: - dependency-name: io.projectreactor:reactor-core dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- dubbo-dependencies-bom/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dubbo-dependencies-bom/pom.xml b/dubbo-dependencies-bom/pom.xml index 549ea92052..966bdd414f 100644 --- a/dubbo-dependencies-bom/pom.xml +++ b/dubbo-dependencies-bom/pom.xml @@ -140,7 +140,7 @@ 3.3 0.16.0 1.0.4 - 3.5.6 + 3.5.7 2.2.21 3.14.9 From 33edc4f17084c222368ac97761c07cf0d9d16948 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 19 Jun 2023 17:39:10 +0800 Subject: [PATCH 21/32] Bump protobuf-java_version from 3.23.2 to 3.23.3 (#12565) Bumps `protobuf-java_version` from 3.23.2 to 3.23.3. Updates `protobuf-java` from 3.23.2 to 3.23.3 - [Release notes](https://github.com/protocolbuffers/protobuf/releases) - [Changelog](https://github.com/protocolbuffers/protobuf/blob/main/generate_changelog.py) - [Commits](https://github.com/protocolbuffers/protobuf/compare/v3.23.2...v3.23.3) Updates `protobuf-java-util` from 3.23.2 to 3.23.3 --- updated-dependencies: - dependency-name: com.google.protobuf:protobuf-java dependency-type: direct:production update-type: version-update:semver-patch - dependency-name: com.google.protobuf:protobuf-java-util dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- dubbo-dependencies-bom/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dubbo-dependencies-bom/pom.xml b/dubbo-dependencies-bom/pom.xml index 966bdd414f..28309c8cb2 100644 --- a/dubbo-dependencies-bom/pom.xml +++ b/dubbo-dependencies-bom/pom.xml @@ -114,7 +114,7 @@ 3.5.5 0.18.1 4.0.66 - 3.23.2 + 3.23.3 1.3.2 3.1.0 9.4.51.v20230217 From f81c3f3a44d3bd634f4f63fce83b0bcbaae86040 Mon Sep 17 00:00:00 2001 From: Albumen Kevin Date: Mon, 19 Jun 2023 18:56:01 +0800 Subject: [PATCH 22/32] Cache interfaceClass in advance to prevent IndexOutOfBoundsException (#12567) --- .../apache/dubbo/rpc/cluster/directory/StaticDirectory.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/directory/StaticDirectory.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/directory/StaticDirectory.java index 8a17dc0fc0..36e3d3eb59 100644 --- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/directory/StaticDirectory.java +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/directory/StaticDirectory.java @@ -36,6 +36,7 @@ import static org.apache.dubbo.common.constants.LoggerCodeConstants.CLUSTER_FAIL */ public class StaticDirectory extends AbstractDirectory { private static final ErrorTypeAwareLogger logger = LoggerFactory.getErrorTypeAwareLogger(StaticDirectory.class); + private final Class interfaceClass; public StaticDirectory(List> invokers) { this(null, invokers, null); @@ -55,11 +56,12 @@ public class StaticDirectory extends AbstractDirectory { throw new IllegalArgumentException("invokers == null"); } this.setInvokers(new BitList<>(invokers)); + this.interfaceClass = invokers.get(0).getInterface(); } @Override public Class getInterface() { - return getInvokers().get(0).getInterface(); + return interfaceClass; } @Override From 85d45b959d70219c727b063d87ee7afc86cce492 Mon Sep 17 00:00:00 2001 From: Albumen Kevin Date: Mon, 19 Jun 2023 18:56:13 +0800 Subject: [PATCH 23/32] Check if jackson2 security dependency existed (#12568) --- .../filter/AuthenticationExceptionTranslatorFilter.java | 6 +++++- .../filter/ContextHolderAuthenticationPrepareFilter.java | 8 ++++++-- .../filter/ContextHolderAuthenticationResolverFilter.java | 6 +++++- .../security/model/SecurityScopeModelInitializer.java | 6 +++++- .../apache/dubbo/spring/security/utils/SecurityNames.java | 2 ++ 5 files changed, 23 insertions(+), 5 deletions(-) diff --git a/dubbo-plugin/dubbo-spring-security/src/main/java/org/apache/dubbo/spring/security/filter/AuthenticationExceptionTranslatorFilter.java b/dubbo-plugin/dubbo-spring-security/src/main/java/org/apache/dubbo/spring/security/filter/AuthenticationExceptionTranslatorFilter.java index 7885250782..00dadabf59 100644 --- a/dubbo-plugin/dubbo-spring-security/src/main/java/org/apache/dubbo/spring/security/filter/AuthenticationExceptionTranslatorFilter.java +++ b/dubbo-plugin/dubbo-spring-security/src/main/java/org/apache/dubbo/spring/security/filter/AuthenticationExceptionTranslatorFilter.java @@ -24,12 +24,16 @@ import org.apache.dubbo.rpc.Invocation; import org.apache.dubbo.rpc.Invoker; import org.apache.dubbo.rpc.Result; import org.apache.dubbo.rpc.RpcException; + import org.springframework.security.access.AccessDeniedException; import org.springframework.security.core.AuthenticationException; + import static org.apache.dubbo.rpc.RpcException.AUTHORIZATION_EXCEPTION; +import static org.apache.dubbo.spring.security.utils.SecurityNames.CORE_JACKSON_2_MODULE_CLASS_NAME; +import static org.apache.dubbo.spring.security.utils.SecurityNames.OBJECT_MAPPER_CLASS_NAME; import static org.apache.dubbo.spring.security.utils.SecurityNames.SECURITY_CONTEXT_HOLDER_CLASS_NAME; -@Activate(group = CommonConstants.PROVIDER, order =Integer.MAX_VALUE,onClass = SECURITY_CONTEXT_HOLDER_CLASS_NAME) +@Activate(group = CommonConstants.PROVIDER, order = Integer.MAX_VALUE, onClass = {SECURITY_CONTEXT_HOLDER_CLASS_NAME, CORE_JACKSON_2_MODULE_CLASS_NAME, OBJECT_MAPPER_CLASS_NAME}) public class AuthenticationExceptionTranslatorFilter implements Filter, Filter.Listener { diff --git a/dubbo-plugin/dubbo-spring-security/src/main/java/org/apache/dubbo/spring/security/filter/ContextHolderAuthenticationPrepareFilter.java b/dubbo-plugin/dubbo-spring-security/src/main/java/org/apache/dubbo/spring/security/filter/ContextHolderAuthenticationPrepareFilter.java index e2a8fe0bc6..6617f4be85 100644 --- a/dubbo-plugin/dubbo-spring-security/src/main/java/org/apache/dubbo/spring/security/filter/ContextHolderAuthenticationPrepareFilter.java +++ b/dubbo-plugin/dubbo-spring-security/src/main/java/org/apache/dubbo/spring/security/filter/ContextHolderAuthenticationPrepareFilter.java @@ -27,13 +27,17 @@ import org.apache.dubbo.rpc.cluster.filter.ClusterFilter; import org.apache.dubbo.rpc.model.ApplicationModel; import org.apache.dubbo.spring.security.jackson.ObjectMapperCodec; import org.apache.dubbo.spring.security.utils.SecurityNames; + import org.springframework.security.core.Authentication; import org.springframework.security.core.context.SecurityContext; import org.springframework.security.core.context.SecurityContextHolder; + +import static org.apache.dubbo.spring.security.utils.SecurityNames.CORE_JACKSON_2_MODULE_CLASS_NAME; +import static org.apache.dubbo.spring.security.utils.SecurityNames.OBJECT_MAPPER_CLASS_NAME; import static org.apache.dubbo.spring.security.utils.SecurityNames.SECURITY_CONTEXT_HOLDER_CLASS_NAME; -@Activate(group = CommonConstants.CONSUMER, order = -10000,onClass = SECURITY_CONTEXT_HOLDER_CLASS_NAME) -public class ContextHolderAuthenticationPrepareFilter implements ClusterFilter{ +@Activate(group = CommonConstants.CONSUMER, order = -10000, onClass = {SECURITY_CONTEXT_HOLDER_CLASS_NAME, CORE_JACKSON_2_MODULE_CLASS_NAME, OBJECT_MAPPER_CLASS_NAME}) +public class ContextHolderAuthenticationPrepareFilter implements ClusterFilter { private final ObjectMapperCodec mapper; diff --git a/dubbo-plugin/dubbo-spring-security/src/main/java/org/apache/dubbo/spring/security/filter/ContextHolderAuthenticationResolverFilter.java b/dubbo-plugin/dubbo-spring-security/src/main/java/org/apache/dubbo/spring/security/filter/ContextHolderAuthenticationResolverFilter.java index acd5026409..9f2567185a 100644 --- a/dubbo-plugin/dubbo-spring-security/src/main/java/org/apache/dubbo/spring/security/filter/ContextHolderAuthenticationResolverFilter.java +++ b/dubbo-plugin/dubbo-spring-security/src/main/java/org/apache/dubbo/spring/security/filter/ContextHolderAuthenticationResolverFilter.java @@ -27,11 +27,15 @@ import org.apache.dubbo.rpc.RpcException; import org.apache.dubbo.rpc.model.ApplicationModel; import org.apache.dubbo.spring.security.jackson.ObjectMapperCodec; import org.apache.dubbo.spring.security.utils.SecurityNames; + import org.springframework.security.core.Authentication; import org.springframework.security.core.context.SecurityContextHolder; + +import static org.apache.dubbo.spring.security.utils.SecurityNames.CORE_JACKSON_2_MODULE_CLASS_NAME; +import static org.apache.dubbo.spring.security.utils.SecurityNames.OBJECT_MAPPER_CLASS_NAME; import static org.apache.dubbo.spring.security.utils.SecurityNames.SECURITY_CONTEXT_HOLDER_CLASS_NAME; -@Activate(group = CommonConstants.PROVIDER, order = -10000,onClass = SECURITY_CONTEXT_HOLDER_CLASS_NAME) +@Activate(group = CommonConstants.PROVIDER, order = -10000, onClass = {SECURITY_CONTEXT_HOLDER_CLASS_NAME, CORE_JACKSON_2_MODULE_CLASS_NAME, OBJECT_MAPPER_CLASS_NAME}) public class ContextHolderAuthenticationResolverFilter implements Filter { private final ObjectMapperCodec mapper; diff --git a/dubbo-plugin/dubbo-spring-security/src/main/java/org/apache/dubbo/spring/security/model/SecurityScopeModelInitializer.java b/dubbo-plugin/dubbo-spring-security/src/main/java/org/apache/dubbo/spring/security/model/SecurityScopeModelInitializer.java index 9679334f6f..286adedb1d 100644 --- a/dubbo-plugin/dubbo-spring-security/src/main/java/org/apache/dubbo/spring/security/model/SecurityScopeModelInitializer.java +++ b/dubbo-plugin/dubbo-spring-security/src/main/java/org/apache/dubbo/spring/security/model/SecurityScopeModelInitializer.java @@ -25,10 +25,14 @@ import org.apache.dubbo.rpc.model.ModuleModel; import org.apache.dubbo.rpc.model.ScopeModelInitializer; import org.apache.dubbo.spring.security.jackson.ObjectMapperCodec; import org.apache.dubbo.spring.security.jackson.ObjectMapperCodecCustomer; + import java.util.Set; + +import static org.apache.dubbo.spring.security.utils.SecurityNames.CORE_JACKSON_2_MODULE_CLASS_NAME; +import static org.apache.dubbo.spring.security.utils.SecurityNames.OBJECT_MAPPER_CLASS_NAME; import static org.apache.dubbo.spring.security.utils.SecurityNames.SECURITY_CONTEXT_HOLDER_CLASS_NAME; -@Activate(onClass = SECURITY_CONTEXT_HOLDER_CLASS_NAME) +@Activate(onClass = {SECURITY_CONTEXT_HOLDER_CLASS_NAME, CORE_JACKSON_2_MODULE_CLASS_NAME, OBJECT_MAPPER_CLASS_NAME}) public class SecurityScopeModelInitializer implements ScopeModelInitializer { @Override diff --git a/dubbo-plugin/dubbo-spring-security/src/main/java/org/apache/dubbo/spring/security/utils/SecurityNames.java b/dubbo-plugin/dubbo-spring-security/src/main/java/org/apache/dubbo/spring/security/utils/SecurityNames.java index 010d8d4f17..97e167095b 100644 --- a/dubbo-plugin/dubbo-spring-security/src/main/java/org/apache/dubbo/spring/security/utils/SecurityNames.java +++ b/dubbo-plugin/dubbo-spring-security/src/main/java/org/apache/dubbo/spring/security/utils/SecurityNames.java @@ -22,6 +22,8 @@ final public class SecurityNames { public static final String SECURITY_AUTHENTICATION_CONTEXT_KEY = "security_authentication_context"; public static final String SECURITY_CONTEXT_HOLDER_CLASS_NAME = "org.springframework.security.core.context.SecurityContextHolder"; + public static final String CORE_JACKSON_2_MODULE_CLASS_NAME = "org.springframework.security.jackson2.CoreJackson2Module"; + public static final String OBJECT_MAPPER_CLASS_NAME = "com.fasterxml.jackson.databind.ObjectMapper"; private SecurityNames() {} From cb69b2eca149ea8e738a65ec4397a4556d09962f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 19 Jun 2023 18:56:28 +0800 Subject: [PATCH 24/32] Bump micrometer-tracing-bom from 1.1.1 to 1.1.2 (#12564) Bumps [micrometer-tracing-bom](https://github.com/micrometer-metrics/tracing) from 1.1.1 to 1.1.2. - [Release notes](https://github.com/micrometer-metrics/tracing/releases) - [Commits](https://github.com/micrometer-metrics/tracing/compare/v1.1.1...v1.1.2) --- updated-dependencies: - dependency-name: io.micrometer:micrometer-tracing-bom dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- dubbo-dependencies-bom/pom.xml | 2 +- .../dubbo-spring-boot-starters/observability/pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dubbo-dependencies-bom/pom.xml b/dubbo-dependencies-bom/pom.xml index 28309c8cb2..bf84ad10ac 100644 --- a/dubbo-dependencies-bom/pom.xml +++ b/dubbo-dependencies-bom/pom.xml @@ -136,7 +136,7 @@ 1.11.1 1.26.0 2.16.4 - 1.1.1 + 1.1.2 3.3 0.16.0 1.0.4 diff --git a/dubbo-spring-boot/dubbo-spring-boot-starters/observability/pom.xml b/dubbo-spring-boot/dubbo-spring-boot-starters/observability/pom.xml index 7bf154f7d7..77065023c9 100644 --- a/dubbo-spring-boot/dubbo-spring-boot-starters/observability/pom.xml +++ b/dubbo-spring-boot/dubbo-spring-boot-starters/observability/pom.xml @@ -39,7 +39,7 @@ 1.11.1 - 1.1.1 + 1.1.2 1.27.0 2.16.4 0.16.0 From 9a9b28bf098229dc912f2962178fef748577ff14 Mon Sep 17 00:00:00 2001 From: Albumen Kevin Date: Mon, 19 Jun 2023 21:28:45 +0800 Subject: [PATCH 25/32] Fix unable to getAppName in InjvmInvoker (#12574) --- .../rpc/protocol/injvm/InjvmInvoker.java | 31 +++++++++----- .../dubbo/rpc/protocol/injvm/DemoService.java | 4 ++ .../rpc/protocol/injvm/DemoServiceImpl.java | 9 +++++ .../rpc/protocol/injvm/InjvmProtocolTest.java | 40 ++++++++++++++++++- 4 files changed, 72 insertions(+), 12 deletions(-) diff --git a/dubbo-rpc/dubbo-rpc-injvm/src/main/java/org/apache/dubbo/rpc/protocol/injvm/InjvmInvoker.java b/dubbo-rpc/dubbo-rpc-injvm/src/main/java/org/apache/dubbo/rpc/protocol/injvm/InjvmInvoker.java index 971b4f7402..70cf0b3534 100644 --- a/dubbo-rpc/dubbo-rpc-injvm/src/main/java/org/apache/dubbo/rpc/protocol/injvm/InjvmInvoker.java +++ b/dubbo-rpc/dubbo-rpc-injvm/src/main/java/org/apache/dubbo/rpc/protocol/injvm/InjvmInvoker.java @@ -94,7 +94,6 @@ public class InjvmInvoker extends AbstractInvoker { if (exporter == null) { throw new RpcException("Service [" + key + "] not found."); } - RpcContext.getServiceContext().setRemoteAddress(LOCALHOST_VALUE, 0); // Solve local exposure, the server opens the token, and the client call fails. Invoker invoker = exporter.getInvoker(); URL serverURL = invoker.getUrl(); @@ -122,16 +121,24 @@ public class InjvmInvoker extends AbstractInvoker { // use consumer executor ExecutorService executor = executorRepository.createExecutorIfAbsent(ExecutorUtil.setThreadName(getUrl(), SERVER_THREAD_POOL_NAME)); CompletableFuture appResponseFuture = CompletableFuture.supplyAsync(() -> { - Result result = invoker.invoke(copiedInvocation); - if (result.hasException()) { - AppResponse appResponse = new AppResponse(result.getException()); - appResponse.setObjectAttachments(new HashMap<>(result.getObjectAttachments())); - return appResponse; - } else { - rebuildValue(invocation, desc, result); - AppResponse appResponse = new AppResponse(result.getValue()); - appResponse.setObjectAttachments(new HashMap<>(result.getObjectAttachments())); - return appResponse; + // clear thread local before child invocation, prevent context pollution + InternalThreadLocalMap originTL = InternalThreadLocalMap.getAndRemove(); + try { + RpcContext.getServiceContext().setRemoteAddress(LOCALHOST_VALUE, 0); + RpcContext.getServiceContext().setRemoteApplicationName(getUrl().getApplication()); + Result result = invoker.invoke(copiedInvocation); + if (result.hasException()) { + AppResponse appResponse = new AppResponse(result.getException()); + appResponse.setObjectAttachments(new HashMap<>(result.getObjectAttachments())); + return appResponse; + } else { + rebuildValue(invocation, desc, result); + AppResponse appResponse = new AppResponse(result.getValue()); + appResponse.setObjectAttachments(new HashMap<>(result.getObjectAttachments())); + return appResponse; + } + } finally { + InternalThreadLocalMap.set(originTL); } }, executor); // save for 2.6.x compatibility, for example, TraceFilter in Zipkin uses com.alibaba.xxx.FutureAdapter @@ -144,6 +151,8 @@ public class InjvmInvoker extends AbstractInvoker { // clear thread local before child invocation, prevent context pollution InternalThreadLocalMap originTL = InternalThreadLocalMap.getAndRemove(); try { + RpcContext.getServiceContext().setRemoteAddress(LOCALHOST_VALUE, 0); + RpcContext.getServiceContext().setRemoteApplicationName(getUrl().getApplication()); result = invoker.invoke(copiedInvocation); } finally { InternalThreadLocalMap.set(originTL); diff --git a/dubbo-rpc/dubbo-rpc-injvm/src/test/java/org/apache/dubbo/rpc/protocol/injvm/DemoService.java b/dubbo-rpc/dubbo-rpc-injvm/src/test/java/org/apache/dubbo/rpc/protocol/injvm/DemoService.java index c9d2e63d49..9a09ed9617 100644 --- a/dubbo-rpc/dubbo-rpc-injvm/src/test/java/org/apache/dubbo/rpc/protocol/injvm/DemoService.java +++ b/dubbo-rpc/dubbo-rpc-injvm/src/test/java/org/apache/dubbo/rpc/protocol/injvm/DemoService.java @@ -40,4 +40,8 @@ public interface DemoService { Type enumlength(Type... types); String getAsyncResult(); + + String getApplication(); + + String getRemoteAddress(); } diff --git a/dubbo-rpc/dubbo-rpc-injvm/src/test/java/org/apache/dubbo/rpc/protocol/injvm/DemoServiceImpl.java b/dubbo-rpc/dubbo-rpc-injvm/src/test/java/org/apache/dubbo/rpc/protocol/injvm/DemoServiceImpl.java index c59847b298..b4d2314a6d 100644 --- a/dubbo-rpc/dubbo-rpc-injvm/src/test/java/org/apache/dubbo/rpc/protocol/injvm/DemoServiceImpl.java +++ b/dubbo-rpc/dubbo-rpc-injvm/src/test/java/org/apache/dubbo/rpc/protocol/injvm/DemoServiceImpl.java @@ -80,4 +80,13 @@ public class DemoServiceImpl implements DemoService { return "DONE"; } + @Override + public String getApplication() { + return RpcContext.getServiceContext().getRemoteApplicationName(); + } + + @Override + public String getRemoteAddress() { + return RpcContext.getServiceContext().getRemoteAddressString(); + } } diff --git a/dubbo-rpc/dubbo-rpc-injvm/src/test/java/org/apache/dubbo/rpc/protocol/injvm/InjvmProtocolTest.java b/dubbo-rpc/dubbo-rpc-injvm/src/test/java/org/apache/dubbo/rpc/protocol/injvm/InjvmProtocolTest.java index 5d4103a840..3ef342e8ea 100644 --- a/dubbo-rpc/dubbo-rpc-injvm/src/test/java/org/apache/dubbo/rpc/protocol/injvm/InjvmProtocolTest.java +++ b/dubbo-rpc/dubbo-rpc-injvm/src/test/java/org/apache/dubbo/rpc/protocol/injvm/InjvmProtocolTest.java @@ -19,10 +19,13 @@ package org.apache.dubbo.rpc.protocol.injvm; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.extension.ExtensionLoader; +import org.apache.dubbo.common.utils.StringUtils; import org.apache.dubbo.rpc.Exporter; +import org.apache.dubbo.rpc.FutureContext; import org.apache.dubbo.rpc.Invoker; import org.apache.dubbo.rpc.Protocol; import org.apache.dubbo.rpc.ProxyFactory; +import org.apache.dubbo.rpc.RpcContext; import org.apache.dubbo.rpc.model.ApplicationModel; import org.apache.dubbo.rpc.model.FrameworkModel; @@ -32,7 +35,9 @@ import org.junit.jupiter.api.Test; import java.util.ArrayList; import java.util.HashMap; import java.util.List; +import java.util.concurrent.ExecutionException; +import static org.apache.dubbo.common.constants.CommonConstants.APPLICATION_KEY; import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY; import static org.apache.dubbo.common.constants.CommonConstants.INTERFACE_KEY; import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY; @@ -129,7 +134,7 @@ class InjvmProtocolTest { } @Test - void testLocalProtocolAsync() { + void testLocalProtocolAsync() throws ExecutionException, InterruptedException { DemoService service = new DemoServiceImpl(); URL url = URL.valueOf("injvm://127.0.0.1/TestService") .addParameter(ASYNC_KEY, true) @@ -141,6 +146,39 @@ class InjvmProtocolTest { exporters.add(exporter); service = proxy.getProxy(protocol.refer(DemoService.class, url)); assertNull(service.getAsyncResult()); + assertEquals("DONE", FutureContext.getContext().getCompletableFuture().get()); + } + + @Test + void testApplication() { + DemoService service = new DemoServiceImpl(); + URL url = URL.valueOf("injvm://127.0.0.1/TestService") + .addParameter(INTERFACE_KEY, DemoService.class.getName()).addParameter("application", "consumer") + .addParameter(APPLICATION_KEY, "test-app") + .setScopeModel(ApplicationModel.defaultModel().getDefaultModule()); + Invoker invoker = proxy.getInvoker(service, DemoService.class, url); + assertTrue(invoker.isAvailable()); + Exporter exporter = protocol.export(invoker); + exporters.add(exporter); + service = proxy.getProxy(protocol.refer(DemoService.class, url)); + assertEquals("test-app", service.getApplication()); + assertTrue(StringUtils.isEmpty(RpcContext.getServiceContext().getRemoteApplicationName())); + } + + @Test + void testRemoteAddress() { + DemoService service = new DemoServiceImpl(); + URL url = URL.valueOf("injvm://127.0.0.1/TestService") + .addParameter(INTERFACE_KEY, DemoService.class.getName()).addParameter("application", "consumer") + .addParameter(APPLICATION_KEY, "test-app") + .setScopeModel(ApplicationModel.defaultModel().getDefaultModule()); + Invoker invoker = proxy.getInvoker(service, DemoService.class, url); + assertTrue(invoker.isAvailable()); + Exporter exporter = protocol.export(invoker); + exporters.add(exporter); + service = proxy.getProxy(protocol.refer(DemoService.class, url)); + assertEquals("127.0.0.1:0", service.getRemoteAddress()); + assertNull(RpcContext.getServiceContext().getRemoteAddress()); } } From a941985c9938548fe70a1e3fcc7ef97705c8d530 Mon Sep 17 00:00:00 2001 From: Albumen Kevin Date: Mon, 19 Jun 2023 21:29:14 +0800 Subject: [PATCH 26/32] Skip check ignored extensions (#12571) --- .../common/extension/ExtensionLoader.java | 5 +++- .../common/extension/ExtensionLoaderTest.java | 29 +++++++++++++++++-- .../config/utils/ConfigValidationUtils.java | 3 +- .../dubbo/config/AbstractConfigTest.java | 19 +++++++++++- 4 files changed, 51 insertions(+), 5 deletions(-) diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/extension/ExtensionLoader.java b/dubbo-common/src/main/java/org/apache/dubbo/common/extension/ExtensionLoader.java index 5f000daa8a..be0f96d247 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/extension/ExtensionLoader.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/extension/ExtensionLoader.java @@ -73,6 +73,7 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import java.util.concurrent.atomic.AtomicBoolean; import java.util.regex.Pattern; +import java.util.stream.Collectors; import static java.util.Arrays.asList; import static java.util.ServiceLoader.load; @@ -346,7 +347,9 @@ public class ExtensionLoader { checkDestroyed(); // solve the bug of using @SPI's wrapper method to report a null pointer exception. Map, T> activateExtensionsMap = new TreeMap<>(activateComparator); - List names = values == null ? new ArrayList<>(0) : asList(values); + List names = values == null ? + new ArrayList<>(0) : + Arrays.stream(values).map(StringUtils::trim).collect(Collectors.toList()); Set namesSet = new HashSet<>(names); if (!namesSet.contains(REMOVE_VALUE_PREFIX + DEFAULT_KEY)) { if (cachedActivateGroups.size() == 0) { diff --git a/dubbo-common/src/test/java/org/apache/dubbo/common/extension/ExtensionLoaderTest.java b/dubbo-common/src/test/java/org/apache/dubbo/common/extension/ExtensionLoaderTest.java index 4f8f1474f1..2e2b2a0884 100644 --- a/dubbo-common/src/test/java/org/apache/dubbo/common/extension/ExtensionLoaderTest.java +++ b/dubbo-common/src/test/java/org/apache/dubbo/common/extension/ExtensionLoaderTest.java @@ -221,7 +221,7 @@ class ExtensionLoaderTest { } @Test - void test_getActivateExtension_WithWrapper() { + void test_getActivateExtension_WithWrapper1() { URL url = URL.valueOf("test://localhost/test"); List list = getExtensionLoader(ActivateExt1.class) .getActivateExtension(url, new String[]{}, "order"); @@ -596,7 +596,7 @@ class ExtensionLoaderTest { } @Test - void testLoadDefaultActivateExtension() { + void testLoadDefaultActivateExtension1() { // test default URL url = URL.valueOf("test://localhost/test?ext=order1,default"); List list = getExtensionLoader(ActivateExt1.class) @@ -620,6 +620,31 @@ class ExtensionLoaderTest { assertSame(list.get(1).getClass(), OrderActivateExtImpl1.class); } + @Test + void testLoadDefaultActivateExtension2() { + // test default + URL url = URL.valueOf("test://localhost/test?ext=order1 , default"); + List list = getExtensionLoader(ActivateExt1.class) + .getActivateExtension(url, "ext", "default_group"); + Assertions.assertEquals(2, list.size()); + assertSame(list.get(0).getClass(), OrderActivateExtImpl1.class); + assertSame(list.get(1).getClass(), ActivateExt1Impl1.class); + + url = URL.valueOf("test://localhost/test?ext=default, order1"); + list = getExtensionLoader(ActivateExt1.class) + .getActivateExtension(url, "ext", "default_group"); + Assertions.assertEquals(2, list.size()); + assertSame(list.get(0).getClass(), ActivateExt1Impl1.class); + assertSame(list.get(1).getClass(), OrderActivateExtImpl1.class); + + url = URL.valueOf("test://localhost/test?ext=order1"); + list = getExtensionLoader(ActivateExt1.class) + .getActivateExtension(url, "ext", "default_group"); + Assertions.assertEquals(2, list.size()); + assertSame(list.get(0).getClass(), ActivateExt1Impl1.class); + assertSame(list.get(1).getClass(), OrderActivateExtImpl1.class); + } + @Test void testInjectExtension() { // register bean for test ScopeBeanExtensionInjector diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/utils/ConfigValidationUtils.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/utils/ConfigValidationUtils.java index 70380568ef..4e9c20d415 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/utils/ConfigValidationUtils.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/utils/ConfigValidationUtils.java @@ -670,8 +670,9 @@ public class ConfigValidationUtils { if (isNotEmpty(value)) { String[] values = value.split("\\s*[,]+\\s*"); for (String v : values) { + v = StringUtils.trim(v); if (v.startsWith(REMOVE_VALUE_PREFIX)) { - v = v.substring(1); + continue; } if (DEFAULT_KEY.equals(v)) { continue; diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/AbstractConfigTest.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/AbstractConfigTest.java index 0a811bbae5..1a986a5884 100644 --- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/AbstractConfigTest.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/AbstractConfigTest.java @@ -207,8 +207,25 @@ class AbstractConfigTest { @Test void checkMultiExtension2() { + try { + ConfigValidationUtils.checkMultiExtension(ApplicationModel.defaultModel(), Greeting.class, "hello", "default,-world"); + } catch (Throwable t) { + Assertions.fail(t); + } + } + @Test + void checkMultiExtension3() { Assertions.assertThrows(IllegalStateException.class, - () -> ConfigValidationUtils.checkMultiExtension(ApplicationModel.defaultModel(), Greeting.class, "hello", "default,-world")); + () -> ConfigValidationUtils.checkMultiExtension(ApplicationModel.defaultModel(), Greeting.class, "hello", "default , world")); + } + + @Test + void checkMultiExtension4() { + try { + ConfigValidationUtils.checkMultiExtension(ApplicationModel.defaultModel(), Greeting.class, "hello", "default , -world "); + } catch (Throwable t) { + Assertions.fail(t); + } } @Test From 8ad792c2876abb5c94b3c6393ee0ffce2117992f Mon Sep 17 00:00:00 2001 From: Albumen Kevin Date: Mon, 19 Jun 2023 21:29:24 +0800 Subject: [PATCH 27/32] Add transient to some overrided field (#12570) --- .../apache/dubbo/config/AbstractReferenceConfig.java | 3 +++ .../java/org/apache/dubbo/config/ModuleConfig.java | 3 +++ .../org/apache/dubbo/config/ReferenceConfigBase.java | 1 + .../org/apache/dubbo/config/ServiceConfigBase.java | 1 + .../main/java/com/alibaba/dubbo/rpc/Invocation.java | 6 ++++-- .../java/com/alibaba/dubbo/rpc/RpcInvocation.java | 8 +++++--- .../dubbo/registry/client/ServiceInstance.java | 1 + .../main/java/org/apache/dubbo/rpc/Invocation.java | 12 +++++++----- 8 files changed, 25 insertions(+), 10 deletions(-) diff --git a/dubbo-common/src/main/java/org/apache/dubbo/config/AbstractReferenceConfig.java b/dubbo-common/src/main/java/org/apache/dubbo/config/AbstractReferenceConfig.java index e659b10b6f..058f1d1622 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/config/AbstractReferenceConfig.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/config/AbstractReferenceConfig.java @@ -21,6 +21,8 @@ import org.apache.dubbo.config.support.Parameter; import org.apache.dubbo.rpc.model.ModuleModel; import org.apache.dubbo.rpc.support.ProtocolUtils; +import java.beans.Transient; + import static org.apache.dubbo.common.constants.CommonConstants.INVOKER_LISTENER_KEY; import static org.apache.dubbo.common.constants.CommonConstants.REFERENCE_FILTER_KEY; import static org.apache.dubbo.common.constants.CommonConstants.REFER_ASYNC_KEY; @@ -184,6 +186,7 @@ public abstract class AbstractReferenceConfig extends AbstractInterfaceConfig { } @Override + @Transient protected boolean isNeedCheckMethod() { return StringUtils.isEmpty(getGeneric()); } diff --git a/dubbo-common/src/main/java/org/apache/dubbo/config/ModuleConfig.java b/dubbo-common/src/main/java/org/apache/dubbo/config/ModuleConfig.java index 511c6bbfb7..ef6eaf870d 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/config/ModuleConfig.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/config/ModuleConfig.java @@ -22,6 +22,7 @@ import org.apache.dubbo.rpc.model.ApplicationModel; import org.apache.dubbo.rpc.model.ModuleModel; import org.apache.dubbo.rpc.model.ScopeModel; +import java.beans.Transient; import java.util.ArrayList; import java.util.List; @@ -135,11 +136,13 @@ public class ModuleConfig extends AbstractConfig { } @Override + @Transient public ModuleModel getScopeModel() { return (ModuleModel) super.getScopeModel(); } @Override + @Transient protected ScopeModel getDefaultModel() { return ApplicationModel.defaultModel().getDefaultModule(); } diff --git a/dubbo-common/src/main/java/org/apache/dubbo/config/ReferenceConfigBase.java b/dubbo-common/src/main/java/org/apache/dubbo/config/ReferenceConfigBase.java index bfeacacba5..4b41ea2786 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/config/ReferenceConfigBase.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/config/ReferenceConfigBase.java @@ -150,6 +150,7 @@ public abstract class ReferenceConfigBase extends AbstractReferenceConfig { } @Override + @Transient public Map getMetaData() { return getMetaData(null); } diff --git a/dubbo-common/src/main/java/org/apache/dubbo/config/ServiceConfigBase.java b/dubbo-common/src/main/java/org/apache/dubbo/config/ServiceConfigBase.java index 0db03d0208..265779ed3f 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/config/ServiceConfigBase.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/config/ServiceConfigBase.java @@ -180,6 +180,7 @@ public abstract class ServiceConfigBase extends AbstractServiceConfig { } @Override + @Transient public Map getMetaData() { return getMetaData(null); } diff --git a/dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/Invocation.java b/dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/Invocation.java index 2eda40f495..85e5cfcfe5 100644 --- a/dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/Invocation.java +++ b/dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/Invocation.java @@ -17,14 +17,15 @@ package com.alibaba.dubbo.rpc; +import org.apache.dubbo.rpc.model.ServiceModel; + +import java.beans.Transient; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.function.Consumer; -import org.apache.dubbo.rpc.model.ServiceModel; - @Deprecated public interface Invocation extends org.apache.dubbo.rpc.Invocation { @@ -184,6 +185,7 @@ public interface Invocation extends org.apache.dubbo.rpc.Invocation { } @Override + @Transient public Invoker getInvoker() { return new Invoker.CompatibleInvoker(delegate.getInvoker()); } diff --git a/dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/RpcInvocation.java b/dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/RpcInvocation.java index 9035294927..d1cf40600d 100644 --- a/dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/RpcInvocation.java +++ b/dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/RpcInvocation.java @@ -17,6 +17,10 @@ package com.alibaba.dubbo.rpc; +import com.alibaba.dubbo.common.Constants; +import com.alibaba.dubbo.common.URL; + +import java.beans.Transient; import java.io.Serializable; import java.lang.reflect.Method; import java.util.Arrays; @@ -24,9 +28,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import com.alibaba.dubbo.common.Constants; -import com.alibaba.dubbo.common.URL; - public class RpcInvocation implements Invocation, Serializable { private static final long serialVersionUID = -4355285085441097045L; @@ -101,6 +102,7 @@ public class RpcInvocation implements Invocation, Serializable { this.invoker = invoker; } + @Transient public Invoker getInvoker() { return invoker; } diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/ServiceInstance.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/ServiceInstance.java index f1546815f8..9f9aaaa860 100644 --- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/ServiceInstance.java +++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/ServiceInstance.java @@ -103,6 +103,7 @@ public interface ServiceInstance extends Serializable { void setApplicationModel(ApplicationModel applicationModel); + @Transient ApplicationModel getApplicationModel(); @Transient diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/Invocation.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/Invocation.java index 1cb4177a90..b40fa05e8a 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/Invocation.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/Invocation.java @@ -16,16 +16,17 @@ */ package org.apache.dubbo.rpc; -import java.util.List; -import java.util.Map; -import java.util.function.Consumer; -import java.util.stream.Stream; - import org.apache.dubbo.common.Experimental; import org.apache.dubbo.rpc.model.ModuleModel; import org.apache.dubbo.rpc.model.ScopeModelUtil; import org.apache.dubbo.rpc.model.ServiceModel; +import java.beans.Transient; +import java.util.List; +import java.util.Map; +import java.util.function.Consumer; +import java.util.stream.Stream; + /** * Invocation. (API, Prototype, NonThreadSafe) * @@ -148,6 +149,7 @@ public interface Invocation { * @return invoker. * @transient */ + @Transient Invoker getInvoker(); void setServiceModel(ServiceModel serviceModel); From ea35f7ed5c1d6d2a6ede821f1481eb5088254d28 Mon Sep 17 00:00:00 2001 From: Albumen Kevin Date: Tue, 20 Jun 2023 10:02:30 +0800 Subject: [PATCH 28/32] Revert "refactor: migrate tracing core from boot-start to dubbo deployer (#12453)" This reverts commit a613cae2 --- .artifacts | 1 - dubbo-cluster/pom.xml | 5 + .../support}/ObservationSenderFilter.java | 23 +- ...che.dubbo.rpc.cluster.filter.ClusterFilter | 1 + .../filter/AbstractObservationFilterTest.java | 84 +++++++ .../filter/ObservationSenderFilterTest.java | 7 +- .../common/constants/LoggerCodeConstants.java | 2 - .../dubbo/config/nested/BaggageConfig.java | 25 --- .../dubbo/config/nested/ExporterConfig.java | 37 +-- .../config/nested/PropagationConfig.java | 7 - .../dubbo/config/nested/SamplingConfig.java | 7 - dubbo-config/dubbo-config-api/pom.xml | 6 - .../deploy/DefaultApplicationDeployer.java | 117 +++++----- .../DefaultApplicationDeployerTest.java | 6 +- dubbo-dependencies-bom/pom.xml | 17 +- dubbo-distribution/dubbo-all/pom.xml | 10 - dubbo-distribution/dubbo-bom/pom.xml | 7 - dubbo-distribution/dubbo-core-spi/pom.xml | 1 - dubbo-metrics/dubbo-metrics-api/pom.xml | 5 + .../apache/dubbo/metrics/aggregate/Pane.java | 0 .../metrics/aggregate/SlidingWindow.java | 0 ...ractDefaultDubboObservationConvention.java | 16 +- ...faultDubboClientObservationConvention.java | 7 +- ...faultDubboServerObservationConvention.java | 4 +- .../observation}/DubboClientContext.java | 9 +- .../DubboClientObservationConvention.java | 4 +- .../DubboObservationDocumentation.java | 2 +- .../observation}/DubboServerContext.java | 5 +- .../DubboServerObservationConvention.java | 4 +- .../metrics/utils/MetricsSupportUtil.java | 38 ---- .../aggregate/TimeWindowAggregatorTest.java | 3 +- ...tDubboClientObservationConventionTest.java | 5 +- ...tDubboServerObservationConventionTest.java | 6 +- .../utils/ObservationConventionUtils.java | 2 +- dubbo-metrics/dubbo-metrics-default/pom.xml | 5 + .../ObservationReceiverFilter.java | 19 +- .../internal/org.apache.dubbo.rpc.Filter | 2 + .../AbstractObservationFilterTest.java | 5 +- .../metrics/observation}/MockInvocation.java | 6 +- .../ObservationReceiverFilterTest.java | 12 +- dubbo-metrics/dubbo-tracing/pom.xml | 111 --------- .../tracing/DubboObservationRegistry.java | 90 -------- .../dubbo/tracing/exporter/TraceExporter.java | 37 --- .../exporter/TraceExporterFactory.java | 66 ------ .../tracing/exporter/otlp/OTlpExporter.java | 66 ------ .../exporter/zipkin/ZipkinExporter.java | 60 ----- .../tracing/tracer/PropagatorProvider.java | 29 --- .../tracer/PropagatorProviderFactory.java | 37 --- .../dubbo/tracing/tracer/TracerProvider.java | 30 --- .../tracing/tracer/TracerProviderFactory.java | 39 ---- .../tracer/brave/BravePropagatorProvider.java | 31 --- .../tracing/tracer/brave/BraveProvider.java | 41 ---- .../tracer/otel/OTelPropagatorProvider.java | 38 ---- .../tracer/otel/OpenTelemetryProvider.java | 212 ------------------ .../tracing/utils/ObservationSupportUtil.java | 49 ---- .../internal/org.apache.dubbo.rpc.Filter | 1 - ...che.dubbo.rpc.cluster.filter.ClusterFilter | 1 - .../tracer/PropagatorProviderFactoryTest.java | 34 --- .../otel/OTelPropagatorProviderTest.java | 39 ---- .../otel/OpenTelemetryProviderTest.java | 53 ----- .../utils/ObservationSupportUtilTest.java | 49 ---- dubbo-metrics/pom.xml | 1 - .../observability/autoconfigure/pom.xml | 6 - .../DubboObservationAutoConfiguration.java | 19 +- .../brave/BraveAutoConfiguration.java | 18 +- .../otel/OpenTelemetryAutoConfiguration.java | 17 +- dubbo-test/dubbo-dependencies-all/pom.xml | 6 +- 67 files changed, 250 insertions(+), 1452 deletions(-) rename {dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/filter => dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/filter/support}/ObservationSenderFilter.java (78%) create mode 100644 dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/filter/AbstractObservationFilterTest.java rename {dubbo-metrics/dubbo-tracing/src/test/java/org/apache/dubbo/tracing => dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster}/filter/ObservationSenderFilterTest.java (92%) mode change 100644 => 100755 dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/aggregate/Pane.java mode change 100644 => 100755 dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/aggregate/SlidingWindow.java rename dubbo-metrics/{dubbo-tracing/src/main/java/org/apache/dubbo/tracing => dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/observation}/AbstractDefaultDubboObservationConvention.java (87%) rename dubbo-metrics/{dubbo-tracing/src/main/java/org/apache/dubbo/tracing => dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/observation}/DefaultDubboClientObservationConvention.java (92%) rename dubbo-metrics/{dubbo-tracing/src/main/java/org/apache/dubbo/tracing => dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/observation}/DefaultDubboServerObservationConvention.java (94%) rename dubbo-metrics/{dubbo-tracing/src/main/java/org/apache/dubbo/tracing/context => dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/observation}/DubboClientContext.java (97%) rename dubbo-metrics/{dubbo-tracing/src/main/java/org/apache/dubbo/tracing => dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/observation}/DubboClientObservationConvention.java (92%) rename dubbo-metrics/{dubbo-tracing/src/main/java/org/apache/dubbo/tracing => dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/observation}/DubboObservationDocumentation.java (98%) rename dubbo-metrics/{dubbo-tracing/src/main/java/org/apache/dubbo/tracing/context => dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/observation}/DubboServerContext.java (97%) rename dubbo-metrics/{dubbo-tracing/src/main/java/org/apache/dubbo/tracing => dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/observation}/DubboServerObservationConvention.java (92%) delete mode 100644 dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/utils/MetricsSupportUtil.java rename dubbo-metrics/{dubbo-tracing/src/test/java/org/apache/dubbo/tracing => dubbo-metrics-api/src/test/java/org/apache/dubbo/metrics/observation}/DefaultDubboClientObservationConventionTest.java (94%) rename dubbo-metrics/{dubbo-tracing/src/test/java/org/apache/dubbo/tracing => dubbo-metrics-api/src/test/java/org/apache/dubbo/metrics/observation}/DefaultDubboServerObservationConventionTest.java (93%) rename dubbo-metrics/{dubbo-tracing/src/test/java/org/apache/dubbo/tracing => dubbo-metrics-api/src/test/java/org/apache/dubbo/metrics/observation}/utils/ObservationConventionUtils.java (97%) rename dubbo-metrics/{dubbo-tracing/src/main/java/org/apache/dubbo/tracing/filter => dubbo-metrics-default/src/main/java/org/apache/dubbo/metrics/observation}/ObservationReceiverFilter.java (80%) create mode 100644 dubbo-metrics/dubbo-metrics-default/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.Filter rename dubbo-metrics/{dubbo-tracing/src/test/java/org/apache/dubbo/tracing/filter => dubbo-metrics-default/src/test/java/org/apache/dubbo/metrics/observation}/AbstractObservationFilterTest.java (94%) rename dubbo-metrics/{dubbo-tracing/src/test/java/org/apache/dubbo/tracing => dubbo-metrics-default/src/test/java/org/apache/dubbo/metrics/observation}/MockInvocation.java (97%) rename dubbo-metrics/{dubbo-tracing/src/test/java/org/apache/dubbo/tracing/filter => dubbo-metrics-default/src/test/java/org/apache/dubbo/metrics/observation}/ObservationReceiverFilterTest.java (99%) delete mode 100644 dubbo-metrics/dubbo-tracing/pom.xml delete mode 100644 dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/DubboObservationRegistry.java delete mode 100644 dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/exporter/TraceExporter.java delete mode 100644 dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/exporter/TraceExporterFactory.java delete mode 100644 dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/exporter/otlp/OTlpExporter.java delete mode 100644 dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/exporter/zipkin/ZipkinExporter.java delete mode 100644 dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/tracer/PropagatorProvider.java delete mode 100644 dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/tracer/PropagatorProviderFactory.java delete mode 100644 dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/tracer/TracerProvider.java delete mode 100644 dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/tracer/TracerProviderFactory.java delete mode 100644 dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/tracer/brave/BravePropagatorProvider.java delete mode 100644 dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/tracer/brave/BraveProvider.java delete mode 100644 dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/tracer/otel/OTelPropagatorProvider.java delete mode 100644 dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/tracer/otel/OpenTelemetryProvider.java delete mode 100644 dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/utils/ObservationSupportUtil.java delete mode 100644 dubbo-metrics/dubbo-tracing/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.Filter delete mode 100644 dubbo-metrics/dubbo-tracing/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.cluster.filter.ClusterFilter delete mode 100644 dubbo-metrics/dubbo-tracing/src/test/java/org/apache/dubbo/tracing/tracer/PropagatorProviderFactoryTest.java delete mode 100644 dubbo-metrics/dubbo-tracing/src/test/java/org/apache/dubbo/tracing/tracer/otel/OTelPropagatorProviderTest.java delete mode 100644 dubbo-metrics/dubbo-tracing/src/test/java/org/apache/dubbo/tracing/tracer/otel/OpenTelemetryProviderTest.java delete mode 100644 dubbo-metrics/dubbo-tracing/src/test/java/org/apache/dubbo/tracing/utils/ObservationSupportUtilTest.java diff --git a/.artifacts b/.artifacts index e18fed5eb5..539c51deed 100644 --- a/.artifacts +++ b/.artifacts @@ -114,5 +114,4 @@ dubbo-nacos-spring-boot-starter dubbo-zookeeper-spring-boot-starter dubbo-zookeeper-curator5-spring-boot-starter dubbo-spring-security -dubbo-tracing dubbo-xds diff --git a/dubbo-cluster/pom.xml b/dubbo-cluster/pom.xml index 08b83b8cca..130b7e3f7e 100644 --- a/dubbo-cluster/pom.xml +++ b/dubbo-cluster/pom.xml @@ -86,5 +86,10 @@ ${project.parent.version} true
+ + io.micrometer + micrometer-tracing-integration-test + test + diff --git a/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/filter/ObservationSenderFilter.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/filter/support/ObservationSenderFilter.java similarity index 78% rename from dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/filter/ObservationSenderFilter.java rename to dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/filter/support/ObservationSenderFilter.java index bce47b7b9a..233a5ed35b 100644 --- a/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/filter/ObservationSenderFilter.java +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/filter/support/ObservationSenderFilter.java @@ -14,9 +14,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.tracing.filter; +package org.apache.dubbo.rpc.cluster.filter.support; import org.apache.dubbo.common.extension.Activate; +import org.apache.dubbo.metrics.observation.DefaultDubboClientObservationConvention; +import org.apache.dubbo.metrics.observation.DubboClientContext; +import org.apache.dubbo.metrics.observation.DubboClientObservationConvention; +import org.apache.dubbo.metrics.observation.DubboObservationDocumentation; import org.apache.dubbo.rpc.BaseFilter; import org.apache.dubbo.rpc.Filter; import org.apache.dubbo.rpc.Invocation; @@ -26,10 +30,6 @@ import org.apache.dubbo.rpc.RpcException; import org.apache.dubbo.rpc.cluster.filter.ClusterFilter; import org.apache.dubbo.rpc.model.ApplicationModel; import org.apache.dubbo.rpc.model.ScopeModelAware; -import org.apache.dubbo.tracing.DefaultDubboClientObservationConvention; -import org.apache.dubbo.tracing.DubboClientObservationConvention; -import org.apache.dubbo.tracing.DubboObservationDocumentation; -import org.apache.dubbo.tracing.context.DubboClientContext; import io.micrometer.observation.Observation; import io.micrometer.observation.ObservationRegistry; @@ -39,7 +39,7 @@ import static org.apache.dubbo.common.constants.CommonConstants.CONSUMER; /** * A {@link Filter} that creates an {@link Observation} around the outgoing message. */ -@Activate(group = CONSUMER, order = Integer.MIN_VALUE + 50, onClass = "io.micrometer.observation.NoopObservationRegistry") +@Activate(group = CONSUMER, order = -1, onClass = "io.micrometer.observation.NoopObservationRegistry") public class ObservationSenderFilter implements ClusterFilter, BaseFilter.Listener, ScopeModelAware { private ObservationRegistry observationRegistry; @@ -47,8 +47,12 @@ public class ObservationSenderFilter implements ClusterFilter, BaseFilter.Listen private DubboClientObservationConvention clientObservationConvention; public ObservationSenderFilter(ApplicationModel applicationModel) { - observationRegistry = applicationModel.getBeanFactory().getBean(ObservationRegistry.class); - clientObservationConvention = applicationModel.getBeanFactory().getBean(DubboClientObservationConvention.class); + applicationModel.getApplicationConfigManager().getTracing().ifPresent(cfg -> { + if (Boolean.TRUE.equals(cfg.getEnabled())) { + observationRegistry = applicationModel.getBeanFactory().getBean(ObservationRegistry.class); + clientObservationConvention = applicationModel.getBeanFactory().getBean(DubboClientObservationConvention.class); + } + }); } @Override @@ -71,9 +75,6 @@ public class ObservationSenderFilter implements ClusterFilter, BaseFilter.Listen if (observation == null) { return; } - if (appResponse != null && appResponse.hasException()) { - observation.error(appResponse.getException()); - } observation.stop(); } diff --git a/dubbo-cluster/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.cluster.filter.ClusterFilter b/dubbo-cluster/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.cluster.filter.ClusterFilter index 28a9e73853..cd0a2f44e8 100644 --- a/dubbo-cluster/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.cluster.filter.ClusterFilter +++ b/dubbo-cluster/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.cluster.filter.ClusterFilter @@ -1,4 +1,5 @@ consumercontext=org.apache.dubbo.rpc.cluster.filter.support.ConsumerContextFilter consumer-classloader=org.apache.dubbo.rpc.cluster.filter.support.ConsumerClassLoaderFilter router-snapshot=org.apache.dubbo.rpc.cluster.router.RouterSnapshotFilter +observationsender=org.apache.dubbo.rpc.cluster.filter.support.ObservationSenderFilter metricsClusterFilter=org.apache.dubbo.rpc.cluster.filter.support.MetricsClusterFilter \ No newline at end of file diff --git a/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/filter/AbstractObservationFilterTest.java b/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/filter/AbstractObservationFilterTest.java new file mode 100644 index 0000000000..567e9cab3b --- /dev/null +++ b/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/filter/AbstractObservationFilterTest.java @@ -0,0 +1,84 @@ +/* + * 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.rpc.cluster.filter; + +import org.apache.dubbo.config.ApplicationConfig; +import org.apache.dubbo.config.TracingConfig; +import org.apache.dubbo.rpc.AppResponse; +import org.apache.dubbo.rpc.BaseFilter; +import org.apache.dubbo.rpc.Invoker; +import org.apache.dubbo.rpc.RpcInvocation; +import org.apache.dubbo.rpc.model.ApplicationModel; + +import io.micrometer.tracing.test.SampleTestRunner; +import org.junit.jupiter.api.AfterEach; + +import static org.mockito.BDDMockito.given; +import static org.mockito.Mockito.mock; + +abstract class AbstractObservationFilterTest extends SampleTestRunner { + + ApplicationModel applicationModel; + RpcInvocation invocation; + + BaseFilter filter; + + Invoker invoker = mock(Invoker.class); + + static final String INTERFACE_NAME = "org.apache.dubbo.MockInterface"; + static final String METHOD_NAME = "mockMethod"; + static final String GROUP = "mockGroup"; + static final String VERSION = "1.0.0"; + + @AfterEach + public void teardown() { + if (applicationModel != null) { + applicationModel.destroy(); + } + } + + abstract BaseFilter createFilter(ApplicationModel applicationModel); + + void setupConfig() { + ApplicationConfig config = new ApplicationConfig(); + config.setName("MockObservations"); + + applicationModel = ApplicationModel.defaultModel(); + applicationModel.getApplicationConfigManager().setApplication(config); + + invocation = new RpcInvocation(new MockInvocation()); + invocation.addInvokedInvoker(invoker); + + applicationModel.getBeanFactory().registerBean(getObservationRegistry()); + TracingConfig tracingConfig = new TracingConfig(); + tracingConfig.setEnabled(true); + applicationModel.getApplicationConfigManager().setTracing(tracingConfig); + + filter = createFilter(applicationModel); + + given(invoker.invoke(invocation)).willReturn(new AppResponse("success")); + + initParam(); + } + + private void initParam() { + invocation.setTargetServiceUniqueName(GROUP + "/" + INTERFACE_NAME + ":" + VERSION); + invocation.setMethodName(METHOD_NAME); + invocation.setParameterTypes(new Class[] {String.class}); + } + +} diff --git a/dubbo-metrics/dubbo-tracing/src/test/java/org/apache/dubbo/tracing/filter/ObservationSenderFilterTest.java b/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/filter/ObservationSenderFilterTest.java similarity index 92% rename from dubbo-metrics/dubbo-tracing/src/test/java/org/apache/dubbo/tracing/filter/ObservationSenderFilterTest.java rename to dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/filter/ObservationSenderFilterTest.java index 071bc0e978..1315686740 100644 --- a/dubbo-metrics/dubbo-tracing/src/test/java/org/apache/dubbo/tracing/filter/ObservationSenderFilterTest.java +++ b/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/filter/ObservationSenderFilterTest.java @@ -15,22 +15,23 @@ * limitations under the License. */ -package org.apache.dubbo.tracing.filter; +package org.apache.dubbo.rpc.cluster.filter; import org.apache.dubbo.common.URL; import org.apache.dubbo.rpc.RpcContext; -import org.apache.dubbo.rpc.cluster.filter.ClusterFilter; +import org.apache.dubbo.rpc.cluster.filter.support.ObservationSenderFilter; import org.apache.dubbo.rpc.model.ApplicationModel; import io.micrometer.common.KeyValues; import io.micrometer.core.tck.MeterRegistryAssert; +import io.micrometer.tracing.test.SampleTestRunner; import io.micrometer.tracing.test.simple.SpansAssert; import org.assertj.core.api.BDDAssertions; class ObservationSenderFilterTest extends AbstractObservationFilterTest { @Override - public SampleTestRunnerConsumer yourCode() { + public SampleTestRunner.SampleTestRunnerConsumer yourCode() { return (buildingBlocks, meterRegistry) -> { setupConfig(); setupAttachments(); diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/constants/LoggerCodeConstants.java b/dubbo-common/src/main/java/org/apache/dubbo/common/constants/LoggerCodeConstants.java index 83e7b62dfa..0a3bfa2125 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/constants/LoggerCodeConstants.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/constants/LoggerCodeConstants.java @@ -92,8 +92,6 @@ public interface LoggerCodeConstants { String VULNERABILITY_WARNING = "0-28"; - String COMMON_NOT_FOUND_TRACER_DEPENDENCY = "0-29"; - // Registry module diff --git a/dubbo-common/src/main/java/org/apache/dubbo/config/nested/BaggageConfig.java b/dubbo-common/src/main/java/org/apache/dubbo/config/nested/BaggageConfig.java index b39f0ece30..beba9b5ddd 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/config/nested/BaggageConfig.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/config/nested/BaggageConfig.java @@ -39,19 +39,6 @@ public class BaggageConfig implements Serializable { */ private List remoteFields = new ArrayList<>(); - public BaggageConfig() { - } - - public BaggageConfig(Boolean enabled) { - this.enabled = enabled; - } - - public BaggageConfig(Boolean enabled, Correlation correlation, List remoteFields) { - this.enabled = enabled; - this.correlation = correlation; - this.remoteFields = remoteFields; - } - public Boolean getEnabled() { return enabled; } @@ -89,18 +76,6 @@ public class BaggageConfig implements Serializable { */ private List fields = new ArrayList<>(); - public Correlation() { - } - - public Correlation(boolean enabled) { - this.enabled = enabled; - } - - public Correlation(boolean enabled, List fields) { - this.enabled = enabled; - this.fields = fields; - } - public boolean isEnabled() { return this.enabled; } diff --git a/dubbo-common/src/main/java/org/apache/dubbo/config/nested/ExporterConfig.java b/dubbo-common/src/main/java/org/apache/dubbo/config/nested/ExporterConfig.java index 871a5afbab..58de4dcd80 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/config/nested/ExporterConfig.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/config/nested/ExporterConfig.java @@ -56,28 +56,15 @@ public class ExporterConfig implements Serializable { private String endpoint; /** - * Connection timeout for requests to Zipkin. (seconds) + * Connection timeout for requests to Zipkin. */ private Duration connectTimeout = Duration.ofSeconds(1); /** - * Read timeout for requests to Zipkin. (seconds) + * Read timeout for requests to Zipkin. */ private Duration readTimeout = Duration.ofSeconds(10); - public ZipkinConfig() { - } - - public ZipkinConfig(String endpoint) { - this.endpoint = endpoint; - } - - public ZipkinConfig(String endpoint, Duration connectTimeout, Duration readTimeout) { - this.endpoint = endpoint; - this.connectTimeout = connectTimeout; - this.readTimeout = readTimeout; - } - public String getEndpoint() { return endpoint; } @@ -111,7 +98,7 @@ public class ExporterConfig implements Serializable { private String endpoint; /** - * The maximum time to wait for the collector to process an exported batch of spans. (seconds) + * The maximum time to wait for the collector to process an exported batch of spans. */ private Duration timeout = Duration.ofSeconds(10); @@ -123,24 +110,6 @@ public class ExporterConfig implements Serializable { private Map headers = new HashMap<>(); - public OtlpConfig() { - } - - public OtlpConfig(String endpoint) { - this.endpoint = endpoint; - } - - public OtlpConfig(String endpoint, Duration timeout) { - this.endpoint = endpoint; - this.timeout = timeout; - } - - public OtlpConfig(String endpoint, Duration timeout, String compressionMethod) { - this.endpoint = endpoint; - this.timeout = timeout; - this.compressionMethod = compressionMethod; - } - public String getEndpoint() { return endpoint; } diff --git a/dubbo-common/src/main/java/org/apache/dubbo/config/nested/PropagationConfig.java b/dubbo-common/src/main/java/org/apache/dubbo/config/nested/PropagationConfig.java index c574bd0e6d..8e52353323 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/config/nested/PropagationConfig.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/config/nested/PropagationConfig.java @@ -29,13 +29,6 @@ public class PropagationConfig implements Serializable { */ private String type = W3C; - public PropagationConfig() { - } - - public PropagationConfig(String type) { - this.type = type; - } - public String getType() { return type; } diff --git a/dubbo-common/src/main/java/org/apache/dubbo/config/nested/SamplingConfig.java b/dubbo-common/src/main/java/org/apache/dubbo/config/nested/SamplingConfig.java index 0e98a98b5f..a605527190 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/config/nested/SamplingConfig.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/config/nested/SamplingConfig.java @@ -25,13 +25,6 @@ public class SamplingConfig implements Serializable { */ private float probability = 0.10f; - public SamplingConfig() { - } - - public SamplingConfig(float probability) { - this.probability = probability; - } - public float getProbability() { return this.probability; } diff --git a/dubbo-config/dubbo-config-api/pom.xml b/dubbo-config/dubbo-config-api/pom.xml index 7bd4234ebd..fec3459350 100644 --- a/dubbo-config/dubbo-config-api/pom.xml +++ b/dubbo-config/dubbo-config-api/pom.xml @@ -72,12 +72,6 @@ ${project.parent.version} - - org.apache.dubbo - dubbo-tracing - ${project.parent.version} - - org.apache.dubbo dubbo-monitor-api diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/deploy/DefaultApplicationDeployer.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/deploy/DefaultApplicationDeployer.java index 6302ee6eb3..ac012ee3d5 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/deploy/DefaultApplicationDeployer.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/deploy/DefaultApplicationDeployer.java @@ -38,6 +38,7 @@ import org.apache.dubbo.common.logger.LoggerFactory; import org.apache.dubbo.common.threadpool.manager.ExecutorRepository; import org.apache.dubbo.common.threadpool.manager.FrameworkExecutorRepository; import org.apache.dubbo.common.utils.ArrayUtils; +import org.apache.dubbo.common.utils.ClassUtils; import org.apache.dubbo.common.utils.CollectionUtils; import org.apache.dubbo.common.utils.StringUtils; import org.apache.dubbo.config.ApplicationConfig; @@ -46,7 +47,6 @@ import org.apache.dubbo.config.DubboShutdownHook; import org.apache.dubbo.config.MetadataReportConfig; import org.apache.dubbo.config.MetricsConfig; import org.apache.dubbo.config.RegistryConfig; -import org.apache.dubbo.config.TracingConfig; import org.apache.dubbo.config.context.ConfigManager; import org.apache.dubbo.config.utils.CompositeReferenceCache; import org.apache.dubbo.config.utils.ConfigValidationUtils; @@ -60,7 +60,6 @@ import org.apache.dubbo.metrics.report.DefaultMetricsReporterFactory; import org.apache.dubbo.metrics.report.MetricsReporter; import org.apache.dubbo.metrics.report.MetricsReporterFactory; import org.apache.dubbo.metrics.service.MetricsServiceExporter; -import org.apache.dubbo.metrics.utils.MetricsSupportUtil; import org.apache.dubbo.registry.Registry; import org.apache.dubbo.registry.RegistryFactory; import org.apache.dubbo.registry.client.metadata.ServiceInstanceMetadataUtils; @@ -71,8 +70,6 @@ import org.apache.dubbo.rpc.model.ModuleServiceRepository; import org.apache.dubbo.rpc.model.ProviderModel; import org.apache.dubbo.rpc.model.ScopeModel; import org.apache.dubbo.rpc.model.ScopeModelUtil; -import org.apache.dubbo.tracing.DubboObservationRegistry; -import org.apache.dubbo.tracing.utils.ObservationSupportUtil; import java.io.IOException; import java.util.ArrayList; @@ -155,7 +152,7 @@ public class DefaultApplicationDeployer extends AbstractDeployer deployListeners = applicationModel.getExtensionLoader(ApplicationDeployListener.class) - .getSupportedExtensionInstances(); + .getSupportedExtensionInstances(); for (ApplicationDeployListener listener : deployListeners) { this.addDeployListener(listener); } @@ -229,9 +226,6 @@ public class DefaultApplicationDeployer extends AbstractDeployer defaultRegistries = configManager.getDefaultRegistries(); if (defaultRegistries.size() > 0) { defaultRegistries - .stream() - .filter(this::isUsedRegistryAsConfigCenter) - .map(this::registryAsConfigCenter) - .forEach(configCenter -> { - if (configManager.getConfigCenter(configCenter.getId()).isPresent()) { - return; - } - configManager.addConfigCenter(configCenter); - logger.info("use registry as config-center: " + configCenter); + .stream() + .filter(this::isUsedRegistryAsConfigCenter) + .map(this::registryAsConfigCenter) + .forEach(configCenter -> { + if (configManager.getConfigCenter(configCenter.getId()).isPresent()) { + return; + } + configManager.addConfigCenter(configCenter); + logger.info("use registry as config-center: " + configCenter); - }); + }); } } @@ -378,16 +372,16 @@ public class DefaultApplicationDeployer extends AbstractDeployer configOptional = configManager.getMetrics(); //If no specific metrics type is configured and there is no Prometheus dependency in the dependencies. MetricsConfig metricsConfig = configOptional.orElse(new MetricsConfig(applicationModel)); if (StringUtils.isBlank(metricsConfig.getProtocol())) { - metricsConfig.setProtocol(MetricsSupportUtil.isSupportPrometheus() ? PROTOCOL_PROMETHEUS : PROTOCOL_DEFAULT); + metricsConfig.setProtocol(isSupportPrometheus() ? PROTOCOL_PROMETHEUS : PROTOCOL_DEFAULT); } collector.setCollectEnabled(true); collector.collectApplication(); @@ -415,35 +409,26 @@ public class DefaultApplicationDeployer extends AbstractDeployer 1.10.0"); - } - return; - } - if (!ObservationSupportUtil.isSupportTracing()) { - if (logger.isDebugEnabled()) { - logger.debug("Not found micrometer-tracing dependency, skip init ObservationRegistry."); - } - return; - } - Optional configOptional = configManager.getTracing(); - if (!configOptional.isPresent() || !configOptional.get().getEnabled()) { - return; - } + public boolean isSupportMetrics() { + return isClassPresent("io.micrometer.core.instrument.MeterRegistry"); + } - DubboObservationRegistry dubboObservationRegistry = new DubboObservationRegistry(applicationModel, configOptional.get()); - dubboObservationRegistry.initObservationRegistry(); + public static boolean isSupportPrometheus() { + return isClassPresent("io.micrometer.prometheus.PrometheusConfig") + && isClassPresent("io.prometheus.client.exporter.BasicAuthHttpConnectionFactory") + && isClassPresent("io.prometheus.client.exporter.HttpConnectionFactory") + && isClassPresent("io.prometheus.client.exporter.PushGateway"); + } + + + private static boolean isClassPresent(String className) { + return ClassUtils.isPresent(className, DefaultApplicationDeployer.class.getClassLoader()); } private boolean isUsedRegistryAsConfigCenter(RegistryConfig registryConfig) { return isUsedRegistryAsCenter(registryConfig, registryConfig::getUseAsConfigCenter, "config", - DynamicConfigurationFactory.class); + DynamicConfigurationFactory.class); } private ConfigCenterConfig registryAsConfigCenter(RegistryConfig registryConfig) { @@ -485,9 +470,9 @@ public class DefaultApplicationDeployer extends AbstractDeployer metadataConfigsToOverride = originMetadataConfigs - .stream() - .filter(m -> Objects.isNull(m.getAddress())) - .collect(Collectors.toList()); + .stream() + .filter(m -> Objects.isNull(m.getAddress())) + .collect(Collectors.toList()); if (metadataConfigsToOverride.size() > 1) { return; @@ -498,12 +483,12 @@ public class DefaultApplicationDeployer extends AbstractDeployer defaultRegistries = configManager.getDefaultRegistries(); if (!defaultRegistries.isEmpty()) { defaultRegistries - .stream() - .filter(this::isUsedRegistryAsMetadataCenter) - .map(registryConfig -> registryAsMetadataCenter(registryConfig, metadataConfigToOverride)) - .forEach(metadataReportConfig -> { - overrideMetadataReportConfig(metadataConfigToOverride, metadataReportConfig); - }); + .stream() + .filter(this::isUsedRegistryAsMetadataCenter) + .map(registryConfig -> registryAsMetadataCenter(registryConfig, metadataConfigToOverride)) + .forEach(metadataReportConfig -> { + overrideMetadataReportConfig(metadataConfigToOverride, metadataReportConfig); + }); } } @@ -532,7 +517,7 @@ public class DefaultApplicationDeployer extends AbstractDeployer { - ServiceInstanceMetadataUtils.registerMetadataAndInstance(applicationModel); - return null; - } + () -> { + ServiceInstanceMetadataUtils.registerMetadataAndInstance(applicationModel); + return null; + } ); } catch (Exception e) { logger.error(CONFIG_REGISTER_INSTANCE_ERROR, "configuration server disconnected", "", "Register instance error.", e); @@ -1032,7 +1017,7 @@ public class DefaultApplicationDeployer extends AbstractDeployer1.8.0 0.1.35 1.11.1 - 1.26.0 - 2.16.4 + 1.1.2 3.3 0.16.0 @@ -232,20 +231,6 @@ pom import - - io.opentelemetry - opentelemetry-bom - ${opentelemetry.version} - pom - import - - - io.zipkin.reporter2 - zipkin-reporter-bom - ${zipkin-reporter.version} - pom - import - io.netty netty-all diff --git a/dubbo-distribution/dubbo-all/pom.xml b/dubbo-distribution/dubbo-all/pom.xml index 76fc002d1c..3951a9fd9d 100644 --- a/dubbo-distribution/dubbo-all/pom.xml +++ b/dubbo-distribution/dubbo-all/pom.xml @@ -219,15 +219,6 @@ true - - - org.apache.dubbo - dubbo-tracing - ${project.version} - compile - true - - org.apache.dubbo @@ -539,7 +530,6 @@ org.apache.dubbo:dubbo-metrics-metadata org.apache.dubbo:dubbo-metrics-config-center org.apache.dubbo:dubbo-metrics-prometheus - org.apache.dubbo:dubbo-tracing org.apache.dubbo:dubbo-monitor-api org.apache.dubbo:dubbo-monitor-default org.apache.dubbo:dubbo-qos diff --git a/dubbo-distribution/dubbo-bom/pom.xml b/dubbo-distribution/dubbo-bom/pom.xml index dac1366414..2d163f10e8 100644 --- a/dubbo-distribution/dubbo-bom/pom.xml +++ b/dubbo-distribution/dubbo-bom/pom.xml @@ -256,13 +256,6 @@ ${project.version} - - - org.apache.dubbo - dubbo-tracing - ${project.version} - - org.apache.dubbo diff --git a/dubbo-distribution/dubbo-core-spi/pom.xml b/dubbo-distribution/dubbo-core-spi/pom.xml index 2a441485f8..88939753e9 100644 --- a/dubbo-distribution/dubbo-core-spi/pom.xml +++ b/dubbo-distribution/dubbo-core-spi/pom.xml @@ -134,7 +134,6 @@ org.apache.dubbo:dubbo-metadata-api org.apache.dubbo:dubbo-metrics-api org.apache.dubbo:dubbo-metrics-default - org.apache.dubbo:dubbo-tracing org.apache.dubbo:dubbo-monitor-api org.apache.dubbo:dubbo-registry-api org.apache.dubbo:dubbo-remoting-api diff --git a/dubbo-metrics/dubbo-metrics-api/pom.xml b/dubbo-metrics/dubbo-metrics-api/pom.xml index 3c31ae389c..a35c238395 100644 --- a/dubbo-metrics/dubbo-metrics-api/pom.xml +++ b/dubbo-metrics/dubbo-metrics-api/pom.xml @@ -49,5 +49,10 @@ com.tdunning t-digest + + io.micrometer + micrometer-tracing-integration-test + test + diff --git a/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/aggregate/Pane.java b/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/aggregate/Pane.java old mode 100644 new mode 100755 diff --git a/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/aggregate/SlidingWindow.java b/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/aggregate/SlidingWindow.java old mode 100644 new mode 100755 diff --git a/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/AbstractDefaultDubboObservationConvention.java b/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/observation/AbstractDefaultDubboObservationConvention.java similarity index 87% rename from dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/AbstractDefaultDubboObservationConvention.java rename to dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/observation/AbstractDefaultDubboObservationConvention.java index a688a4c826..410af9d674 100644 --- a/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/AbstractDefaultDubboObservationConvention.java +++ b/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/observation/AbstractDefaultDubboObservationConvention.java @@ -14,20 +14,20 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.tracing; - -import io.micrometer.common.KeyValues; -import io.micrometer.common.docs.KeyName; -import io.micrometer.common.lang.Nullable; +package org.apache.dubbo.metrics.observation; import org.apache.dubbo.common.constants.CommonConstants; import org.apache.dubbo.common.utils.StringUtils; import org.apache.dubbo.rpc.Invocation; import org.apache.dubbo.rpc.support.RpcUtils; -import static org.apache.dubbo.tracing.DubboObservationDocumentation.LowCardinalityKeyNames.RPC_METHOD; -import static org.apache.dubbo.tracing.DubboObservationDocumentation.LowCardinalityKeyNames.RPC_SERVICE; -import static org.apache.dubbo.tracing.DubboObservationDocumentation.LowCardinalityKeyNames.RPC_SYSTEM; +import io.micrometer.common.KeyValues; +import io.micrometer.common.docs.KeyName; +import io.micrometer.common.lang.Nullable; + +import static org.apache.dubbo.metrics.observation.DubboObservationDocumentation.LowCardinalityKeyNames.RPC_METHOD; +import static org.apache.dubbo.metrics.observation.DubboObservationDocumentation.LowCardinalityKeyNames.RPC_SERVICE; +import static org.apache.dubbo.metrics.observation.DubboObservationDocumentation.LowCardinalityKeyNames.RPC_SYSTEM; class AbstractDefaultDubboObservationConvention { KeyValues getLowCardinalityKeyValues(Invocation invocation) { diff --git a/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/DefaultDubboClientObservationConvention.java b/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/observation/DefaultDubboClientObservationConvention.java similarity index 92% rename from dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/DefaultDubboClientObservationConvention.java rename to dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/observation/DefaultDubboClientObservationConvention.java index 481861d1f9..91e88da2a3 100644 --- a/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/DefaultDubboClientObservationConvention.java +++ b/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/observation/DefaultDubboClientObservationConvention.java @@ -14,20 +14,19 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.tracing; +package org.apache.dubbo.metrics.observation; import org.apache.dubbo.common.URL; import org.apache.dubbo.rpc.Invoker; import org.apache.dubbo.rpc.RpcContext; import org.apache.dubbo.rpc.RpcContextAttachment; -import org.apache.dubbo.tracing.context.DubboClientContext; import io.micrometer.common.KeyValues; import java.util.List; -import static org.apache.dubbo.tracing.DubboObservationDocumentation.LowCardinalityKeyNames.NET_PEER_NAME; -import static org.apache.dubbo.tracing.DubboObservationDocumentation.LowCardinalityKeyNames.NET_PEER_PORT; +import static org.apache.dubbo.metrics.observation.DubboObservationDocumentation.LowCardinalityKeyNames.NET_PEER_NAME; +import static org.apache.dubbo.metrics.observation.DubboObservationDocumentation.LowCardinalityKeyNames.NET_PEER_PORT; /** * Default implementation of the {@link DubboClientObservationConvention}. diff --git a/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/DefaultDubboServerObservationConvention.java b/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/observation/DefaultDubboServerObservationConvention.java similarity index 94% rename from dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/DefaultDubboServerObservationConvention.java rename to dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/observation/DefaultDubboServerObservationConvention.java index c78be59806..adcebdbdac 100644 --- a/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/DefaultDubboServerObservationConvention.java +++ b/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/observation/DefaultDubboServerObservationConvention.java @@ -14,9 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.tracing; - -import org.apache.dubbo.tracing.context.DubboServerContext; +package org.apache.dubbo.metrics.observation; import io.micrometer.common.KeyValues; diff --git a/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/context/DubboClientContext.java b/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/observation/DubboClientContext.java similarity index 97% rename from dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/context/DubboClientContext.java rename to dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/observation/DubboClientContext.java index f1998bc91a..910d6f74c0 100644 --- a/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/context/DubboClientContext.java +++ b/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/observation/DubboClientContext.java @@ -14,14 +14,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.tracing.context; +package org.apache.dubbo.metrics.observation; -import java.util.Objects; - -import io.micrometer.observation.transport.SenderContext; import org.apache.dubbo.rpc.Invocation; import org.apache.dubbo.rpc.Invoker; +import io.micrometer.observation.transport.SenderContext; + +import java.util.Objects; + /** * Provider context for RPC. */ diff --git a/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/DubboClientObservationConvention.java b/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/observation/DubboClientObservationConvention.java similarity index 92% rename from dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/DubboClientObservationConvention.java rename to dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/observation/DubboClientObservationConvention.java index 5bd74dec50..d33164294d 100644 --- a/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/DubboClientObservationConvention.java +++ b/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/observation/DubboClientObservationConvention.java @@ -14,9 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.tracing; - -import org.apache.dubbo.tracing.context.DubboClientContext; +package org.apache.dubbo.metrics.observation; import io.micrometer.observation.Observation; import io.micrometer.observation.ObservationConvention; diff --git a/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/DubboObservationDocumentation.java b/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/observation/DubboObservationDocumentation.java similarity index 98% rename from dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/DubboObservationDocumentation.java rename to dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/observation/DubboObservationDocumentation.java index cd0dfe3d61..855a2e01e1 100644 --- a/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/DubboObservationDocumentation.java +++ b/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/observation/DubboObservationDocumentation.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.tracing; +package org.apache.dubbo.metrics.observation; import io.micrometer.common.docs.KeyName; import io.micrometer.common.lang.NonNullApi; diff --git a/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/context/DubboServerContext.java b/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/observation/DubboServerContext.java similarity index 97% rename from dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/context/DubboServerContext.java rename to dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/observation/DubboServerContext.java index 3e5bd13fae..bb1d7005d7 100644 --- a/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/context/DubboServerContext.java +++ b/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/observation/DubboServerContext.java @@ -14,12 +14,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.tracing.context; +package org.apache.dubbo.metrics.observation; -import io.micrometer.observation.transport.ReceiverContext; import org.apache.dubbo.rpc.Invocation; import org.apache.dubbo.rpc.Invoker; +import io.micrometer.observation.transport.ReceiverContext; + /** * Consumer context for RPC. */ diff --git a/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/DubboServerObservationConvention.java b/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/observation/DubboServerObservationConvention.java similarity index 92% rename from dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/DubboServerObservationConvention.java rename to dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/observation/DubboServerObservationConvention.java index 0f7917aded..678226ee7f 100644 --- a/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/DubboServerObservationConvention.java +++ b/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/observation/DubboServerObservationConvention.java @@ -14,9 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.tracing; - -import org.apache.dubbo.tracing.context.DubboServerContext; +package org.apache.dubbo.metrics.observation; import io.micrometer.observation.Observation; import io.micrometer.observation.ObservationConvention; diff --git a/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/utils/MetricsSupportUtil.java b/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/utils/MetricsSupportUtil.java deleted file mode 100644 index e0a02f5f04..0000000000 --- a/dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/utils/MetricsSupportUtil.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * 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.utils; - -import org.apache.dubbo.common.utils.ClassUtils; - -public class MetricsSupportUtil { - - public static boolean isSupportMetrics() { - return isClassPresent("io.micrometer.core.instrument.MeterRegistry"); - } - - public static boolean isSupportPrometheus() { - return isClassPresent("io.micrometer.prometheus.PrometheusConfig") - && isClassPresent("io.prometheus.client.exporter.BasicAuthHttpConnectionFactory") - && isClassPresent("io.prometheus.client.exporter.HttpConnectionFactory") - && isClassPresent("io.prometheus.client.exporter.PushGateway"); - } - - private static boolean isClassPresent(String className) { - return ClassUtils.isPresent(className, MetricsSupportUtil.class.getClassLoader()); - } -} diff --git a/dubbo-metrics/dubbo-metrics-api/src/test/java/org/apache/dubbo/metrics/aggregate/TimeWindowAggregatorTest.java b/dubbo-metrics/dubbo-metrics-api/src/test/java/org/apache/dubbo/metrics/aggregate/TimeWindowAggregatorTest.java index 2a660a5dd4..e0db96730f 100644 --- a/dubbo-metrics/dubbo-metrics-api/src/test/java/org/apache/dubbo/metrics/aggregate/TimeWindowAggregatorTest.java +++ b/dubbo-metrics/dubbo-metrics-api/src/test/java/org/apache/dubbo/metrics/aggregate/TimeWindowAggregatorTest.java @@ -17,9 +17,8 @@ package org.apache.dubbo.metrics.aggregate; - +import org.junit.Test; import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; import java.util.concurrent.TimeUnit; diff --git a/dubbo-metrics/dubbo-tracing/src/test/java/org/apache/dubbo/tracing/DefaultDubboClientObservationConventionTest.java b/dubbo-metrics/dubbo-metrics-api/src/test/java/org/apache/dubbo/metrics/observation/DefaultDubboClientObservationConventionTest.java similarity index 94% rename from dubbo-metrics/dubbo-tracing/src/test/java/org/apache/dubbo/tracing/DefaultDubboClientObservationConventionTest.java rename to dubbo-metrics/dubbo-metrics-api/src/test/java/org/apache/dubbo/metrics/observation/DefaultDubboClientObservationConventionTest.java index 0f1e641c4a..ce83f9e886 100644 --- a/dubbo-metrics/dubbo-tracing/src/test/java/org/apache/dubbo/tracing/DefaultDubboClientObservationConventionTest.java +++ b/dubbo-metrics/dubbo-metrics-api/src/test/java/org/apache/dubbo/metrics/observation/DefaultDubboClientObservationConventionTest.java @@ -14,12 +14,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.tracing; +package org.apache.dubbo.metrics.observation; +import org.apache.dubbo.metrics.observation.utils.ObservationConventionUtils; import org.apache.dubbo.rpc.Invoker; import org.apache.dubbo.rpc.RpcInvocation; -import org.apache.dubbo.tracing.context.DubboClientContext; -import org.apache.dubbo.tracing.utils.ObservationConventionUtils; import io.micrometer.common.KeyValues; import org.junit.jupiter.api.Assertions; diff --git a/dubbo-metrics/dubbo-tracing/src/test/java/org/apache/dubbo/tracing/DefaultDubboServerObservationConventionTest.java b/dubbo-metrics/dubbo-metrics-api/src/test/java/org/apache/dubbo/metrics/observation/DefaultDubboServerObservationConventionTest.java similarity index 93% rename from dubbo-metrics/dubbo-tracing/src/test/java/org/apache/dubbo/tracing/DefaultDubboServerObservationConventionTest.java rename to dubbo-metrics/dubbo-metrics-api/src/test/java/org/apache/dubbo/metrics/observation/DefaultDubboServerObservationConventionTest.java index 95a755cd98..7ca6398c9e 100644 --- a/dubbo-metrics/dubbo-tracing/src/test/java/org/apache/dubbo/tracing/DefaultDubboServerObservationConventionTest.java +++ b/dubbo-metrics/dubbo-metrics-api/src/test/java/org/apache/dubbo/metrics/observation/DefaultDubboServerObservationConventionTest.java @@ -14,13 +14,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.tracing; +package org.apache.dubbo.metrics.observation; +import org.apache.dubbo.metrics.observation.utils.ObservationConventionUtils; import org.apache.dubbo.rpc.Invoker; import org.apache.dubbo.rpc.RpcInvocation; -import org.apache.dubbo.tracing.context.DubboClientContext; -import org.apache.dubbo.tracing.context.DubboServerContext; -import org.apache.dubbo.tracing.utils.ObservationConventionUtils; import io.micrometer.common.KeyValues; import org.junit.jupiter.api.Assertions; diff --git a/dubbo-metrics/dubbo-tracing/src/test/java/org/apache/dubbo/tracing/utils/ObservationConventionUtils.java b/dubbo-metrics/dubbo-metrics-api/src/test/java/org/apache/dubbo/metrics/observation/utils/ObservationConventionUtils.java similarity index 97% rename from dubbo-metrics/dubbo-tracing/src/test/java/org/apache/dubbo/tracing/utils/ObservationConventionUtils.java rename to dubbo-metrics/dubbo-metrics-api/src/test/java/org/apache/dubbo/metrics/observation/utils/ObservationConventionUtils.java index f0b75c8c2c..e6de96f069 100644 --- a/dubbo-metrics/dubbo-tracing/src/test/java/org/apache/dubbo/tracing/utils/ObservationConventionUtils.java +++ b/dubbo-metrics/dubbo-metrics-api/src/test/java/org/apache/dubbo/metrics/observation/utils/ObservationConventionUtils.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.tracing.utils; +package org.apache.dubbo.metrics.observation.utils; import org.apache.dubbo.common.URL; import org.apache.dubbo.rpc.Invoker; diff --git a/dubbo-metrics/dubbo-metrics-default/pom.xml b/dubbo-metrics/dubbo-metrics-default/pom.xml index 0d2fd8a6bf..71be413c6a 100644 --- a/dubbo-metrics/dubbo-metrics-default/pom.xml +++ b/dubbo-metrics/dubbo-metrics-default/pom.xml @@ -41,5 +41,10 @@ micrometer-test test + + io.micrometer + micrometer-tracing-integration-test + test + diff --git a/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/filter/ObservationReceiverFilter.java b/dubbo-metrics/dubbo-metrics-default/src/main/java/org/apache/dubbo/metrics/observation/ObservationReceiverFilter.java similarity index 80% rename from dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/filter/ObservationReceiverFilter.java rename to dubbo-metrics/dubbo-metrics-default/src/main/java/org/apache/dubbo/metrics/observation/ObservationReceiverFilter.java index 25b7008c67..5a33ced437 100644 --- a/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/filter/ObservationReceiverFilter.java +++ b/dubbo-metrics/dubbo-metrics-default/src/main/java/org/apache/dubbo/metrics/observation/ObservationReceiverFilter.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.tracing.filter; +package org.apache.dubbo.metrics.observation; import org.apache.dubbo.common.extension.Activate; import org.apache.dubbo.rpc.BaseFilter; @@ -25,10 +25,6 @@ import org.apache.dubbo.rpc.Result; import org.apache.dubbo.rpc.RpcException; import org.apache.dubbo.rpc.model.ApplicationModel; import org.apache.dubbo.rpc.model.ScopeModelAware; -import org.apache.dubbo.tracing.DefaultDubboServerObservationConvention; -import org.apache.dubbo.tracing.DubboObservationDocumentation; -import org.apache.dubbo.tracing.DubboServerObservationConvention; -import org.apache.dubbo.tracing.context.DubboServerContext; import io.micrometer.observation.Observation; import io.micrometer.observation.ObservationRegistry; @@ -38,7 +34,7 @@ import static org.apache.dubbo.common.constants.CommonConstants.PROVIDER; /** * A {@link Filter} that creates an {@link Observation} around the incoming message. */ -@Activate(group = PROVIDER, order = Integer.MIN_VALUE + 50, onClass = "io.micrometer.observation.NoopObservationRegistry") +@Activate(group = PROVIDER, order = -1, onClass = "io.micrometer.observation.NoopObservationRegistry") public class ObservationReceiverFilter implements Filter, BaseFilter.Listener, ScopeModelAware { private ObservationRegistry observationRegistry; @@ -46,8 +42,12 @@ public class ObservationReceiverFilter implements Filter, BaseFilter.Listener, S private DubboServerObservationConvention serverObservationConvention; public ObservationReceiverFilter(ApplicationModel applicationModel) { - observationRegistry = applicationModel.getBeanFactory().getBean(ObservationRegistry.class); - serverObservationConvention = applicationModel.getBeanFactory().getBean(DubboServerObservationConvention.class); + applicationModel.getApplicationConfigManager().getTracing().ifPresent(cfg -> { + if (Boolean.TRUE.equals(cfg.getEnabled())) { + observationRegistry = applicationModel.getBeanFactory().getBean(ObservationRegistry.class); + serverObservationConvention = applicationModel.getBeanFactory().getBean(DubboServerObservationConvention.class); + } + }); } @Override @@ -70,9 +70,6 @@ public class ObservationReceiverFilter implements Filter, BaseFilter.Listener, S if (observation == null) { return; } - if (appResponse != null && appResponse.hasException()) { - observation.error(appResponse.getException()); - } observation.stop(); } diff --git a/dubbo-metrics/dubbo-metrics-default/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.Filter b/dubbo-metrics/dubbo-metrics-default/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.Filter new file mode 100644 index 0000000000..5ee6c1d455 --- /dev/null +++ b/dubbo-metrics/dubbo-metrics-default/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.Filter @@ -0,0 +1,2 @@ +metrics-beta=org.apache.dubbo.metrics.filter.MetricsFilter +observationreceiver=org.apache.dubbo.metrics.observation.ObservationReceiverFilter \ No newline at end of file diff --git a/dubbo-metrics/dubbo-tracing/src/test/java/org/apache/dubbo/tracing/filter/AbstractObservationFilterTest.java b/dubbo-metrics/dubbo-metrics-default/src/test/java/org/apache/dubbo/metrics/observation/AbstractObservationFilterTest.java similarity index 94% rename from dubbo-metrics/dubbo-tracing/src/test/java/org/apache/dubbo/tracing/filter/AbstractObservationFilterTest.java rename to dubbo-metrics/dubbo-metrics-default/src/test/java/org/apache/dubbo/metrics/observation/AbstractObservationFilterTest.java index 046a0f1f95..31715ca94b 100644 --- a/dubbo-metrics/dubbo-tracing/src/test/java/org/apache/dubbo/tracing/filter/AbstractObservationFilterTest.java +++ b/dubbo-metrics/dubbo-metrics-default/src/test/java/org/apache/dubbo/metrics/observation/AbstractObservationFilterTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.dubbo.tracing.filter; +package org.apache.dubbo.metrics.observation; import org.apache.dubbo.config.ApplicationConfig; import org.apache.dubbo.config.TracingConfig; @@ -24,7 +24,6 @@ import org.apache.dubbo.rpc.BaseFilter; import org.apache.dubbo.rpc.Invoker; import org.apache.dubbo.rpc.RpcInvocation; import org.apache.dubbo.rpc.model.ApplicationModel; -import org.apache.dubbo.tracing.MockInvocation; import io.micrometer.tracing.test.SampleTestRunner; import org.junit.jupiter.api.AfterEach; @@ -80,7 +79,7 @@ abstract class AbstractObservationFilterTest extends SampleTestRunner { private void initParam() { invocation.setTargetServiceUniqueName(GROUP + "/" + INTERFACE_NAME + ":" + VERSION); invocation.setMethodName(METHOD_NAME); - invocation.setParameterTypes(new Class[]{String.class}); + invocation.setParameterTypes(new Class[] {String.class}); } } diff --git a/dubbo-metrics/dubbo-tracing/src/test/java/org/apache/dubbo/tracing/MockInvocation.java b/dubbo-metrics/dubbo-metrics-default/src/test/java/org/apache/dubbo/metrics/observation/MockInvocation.java similarity index 97% rename from dubbo-metrics/dubbo-tracing/src/test/java/org/apache/dubbo/tracing/MockInvocation.java rename to dubbo-metrics/dubbo-metrics-default/src/test/java/org/apache/dubbo/metrics/observation/MockInvocation.java index cd9c0335dd..8cb43471d8 100644 --- a/dubbo-metrics/dubbo-tracing/src/test/java/org/apache/dubbo/tracing/MockInvocation.java +++ b/dubbo-metrics/dubbo-metrics-default/src/test/java/org/apache/dubbo/metrics/observation/MockInvocation.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.tracing; +package org.apache.dubbo.metrics.observation; import org.apache.dubbo.rpc.AttachmentsAdapter; import org.apache.dubbo.rpc.Invoker; @@ -68,11 +68,11 @@ public class MockInvocation extends RpcInvocation { } public Class[] getParameterTypes() { - return new Class[]{String.class}; + return new Class[] {String.class}; } public Object[] getArguments() { - return new Object[]{"aa"}; + return new Object[] {"aa"}; } public Map getAttachments() { diff --git a/dubbo-metrics/dubbo-tracing/src/test/java/org/apache/dubbo/tracing/filter/ObservationReceiverFilterTest.java b/dubbo-metrics/dubbo-metrics-default/src/test/java/org/apache/dubbo/metrics/observation/ObservationReceiverFilterTest.java similarity index 99% rename from dubbo-metrics/dubbo-tracing/src/test/java/org/apache/dubbo/tracing/filter/ObservationReceiverFilterTest.java rename to dubbo-metrics/dubbo-metrics-default/src/test/java/org/apache/dubbo/metrics/observation/ObservationReceiverFilterTest.java index 4cb0282430..91101e1aa0 100644 --- a/dubbo-metrics/dubbo-tracing/src/test/java/org/apache/dubbo/tracing/filter/ObservationReceiverFilterTest.java +++ b/dubbo-metrics/dubbo-metrics-default/src/test/java/org/apache/dubbo/metrics/observation/ObservationReceiverFilterTest.java @@ -15,13 +15,8 @@ * limitations under the License. */ -package org.apache.dubbo.tracing.filter; +package org.apache.dubbo.metrics.observation; -import io.micrometer.common.KeyValues; -import io.micrometer.core.tck.MeterRegistryAssert; -import io.micrometer.tracing.Span; -import io.micrometer.tracing.Tracer; -import io.micrometer.tracing.test.simple.SpansAssert; import org.apache.dubbo.common.URL; import org.apache.dubbo.rpc.AppResponse; import org.apache.dubbo.rpc.Filter; @@ -32,6 +27,11 @@ import org.apache.dubbo.rpc.RpcContext; import org.apache.dubbo.rpc.RpcException; import org.apache.dubbo.rpc.model.ApplicationModel; +import io.micrometer.common.KeyValues; +import io.micrometer.core.tck.MeterRegistryAssert; +import io.micrometer.tracing.Span; +import io.micrometer.tracing.Tracer; +import io.micrometer.tracing.test.simple.SpansAssert; import org.assertj.core.api.BDDAssertions; class ObservationReceiverFilterTest extends AbstractObservationFilterTest { diff --git a/dubbo-metrics/dubbo-tracing/pom.xml b/dubbo-metrics/dubbo-tracing/pom.xml deleted file mode 100644 index e50dae23bd..0000000000 --- a/dubbo-metrics/dubbo-tracing/pom.xml +++ /dev/null @@ -1,111 +0,0 @@ - - - 4.0.0 - - org.apache.dubbo - dubbo-metrics - ${revision} - ../pom.xml - - - dubbo-tracing - jar - ${project.artifactId} - The tracing module of dubbo project - - - 11 - 11 - UTF-8 - false - - - - - org.apache.dubbo - dubbo-common - ${project.parent.version} - - - org.apache.dubbo - dubbo-cluster - ${project.parent.version} - - - org.apache.dubbo - dubbo-rpc-api - ${project.parent.version} - - - org.apache.dubbo - dubbo-metrics-default - ${project.parent.version} - - - - - io.micrometer - micrometer-core - - - io.micrometer - micrometer-tracing - - - io.micrometer - micrometer-test - test - - - io.micrometer - micrometer-tracing-integration-test - test - - - - - io.micrometer - micrometer-tracing-bridge-otel - true - - - io.micrometer - micrometer-tracing-bridge-brave - true - - - - - io.opentelemetry - opentelemetry-exporter-zipkin - true - - - io.opentelemetry - opentelemetry-exporter-otlp - true - - - io.zipkin.reporter2 - zipkin-reporter-brave - true - - - \ No newline at end of file diff --git a/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/DubboObservationRegistry.java b/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/DubboObservationRegistry.java deleted file mode 100644 index a8497d998b..0000000000 --- a/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/DubboObservationRegistry.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * 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.tracing; - -import org.apache.dubbo.common.logger.ErrorTypeAwareLogger; -import org.apache.dubbo.common.logger.LoggerFactory; -import org.apache.dubbo.common.utils.JsonUtils; -import org.apache.dubbo.config.TracingConfig; -import org.apache.dubbo.metrics.MetricsGlobalRegistry; -import org.apache.dubbo.metrics.utils.MetricsSupportUtil; -import org.apache.dubbo.rpc.model.ApplicationModel; -import org.apache.dubbo.tracing.tracer.PropagatorProvider; -import org.apache.dubbo.tracing.tracer.PropagatorProviderFactory; -import org.apache.dubbo.tracing.tracer.TracerProvider; -import org.apache.dubbo.tracing.tracer.TracerProviderFactory; - -import static org.apache.dubbo.common.constants.LoggerCodeConstants.COMMON_NOT_FOUND_TRACER_DEPENDENCY; - -public class DubboObservationRegistry { - - private static final ErrorTypeAwareLogger logger = LoggerFactory.getErrorTypeAwareLogger(DubboObservationRegistry.class); - - private final ApplicationModel applicationModel; - - private final TracingConfig tracingConfig; - - public DubboObservationRegistry(ApplicationModel applicationModel, TracingConfig tracingConfig) { - this.applicationModel = applicationModel; - this.tracingConfig = tracingConfig; - } - - public void initObservationRegistry() { - // If get ObservationRegistry.class from external(eg Spring.), use external. - io.micrometer.observation.ObservationRegistry externalObservationRegistry = applicationModel.getBeanFactory().getBean(io.micrometer.observation.ObservationRegistry.class); - if (externalObservationRegistry != null) { - if (logger.isDebugEnabled()) { - logger.debug("ObservationRegistry.class from external is existed."); - } - return; - } - - if (logger.isDebugEnabled()) { - logger.debug("Tracing config is: " + JsonUtils.toJson(tracingConfig)); - } - - TracerProvider tracerProvider = TracerProviderFactory.getProvider(applicationModel, tracingConfig); - if (tracerProvider == null) { - logger.warn(COMMON_NOT_FOUND_TRACER_DEPENDENCY, "", "", "Can not found OpenTelemetry/Brave tracer dependencies, skip init ObservationRegistry."); - return; - } - // The real tracer will come from tracer implementation (OTel / Brave) - io.micrometer.tracing.Tracer tracer = tracerProvider.getTracer(); - - // The real propagator will come from tracer implementation (OTel / Brave) - PropagatorProvider propagatorProvider = PropagatorProviderFactory.getPropagatorProvider(); - io.micrometer.tracing.propagation.Propagator propagator = propagatorProvider != null ? propagatorProvider.getPropagator() : io.micrometer.tracing.propagation.Propagator.NOOP; - - io.micrometer.observation.ObservationRegistry registry = io.micrometer.observation.ObservationRegistry.create(); - registry.observationConfig() - // set up a first matching handler that creates spans - it comes from Micrometer Tracing. - // set up spans for sending and receiving data over the wire and a default one. - .observationHandler(new io.micrometer.observation.ObservationHandler.FirstMatchingCompositeObservationHandler( - new io.micrometer.tracing.handler.PropagatingSenderTracingObservationHandler<>(tracer, propagator), - new io.micrometer.tracing.handler.PropagatingReceiverTracingObservationHandler<>(tracer, propagator), - new io.micrometer.tracing.handler.DefaultTracingObservationHandler(tracer))); - - if (MetricsSupportUtil.isSupportMetrics()) { - io.micrometer.core.instrument.MeterRegistry meterRegistry = MetricsGlobalRegistry.getCompositeRegistry(applicationModel); - registry.observationConfig().observationHandler(new io.micrometer.core.instrument.observation.DefaultMeterObservationHandler(meterRegistry)); - } - - applicationModel.getBeanFactory().registerBean(registry); - applicationModel.getBeanFactory().registerBean(tracer); - applicationModel.getBeanFactory().registerBean(propagator); - } -} diff --git a/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/exporter/TraceExporter.java b/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/exporter/TraceExporter.java deleted file mode 100644 index 9b8f12ee4b..0000000000 --- a/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/exporter/TraceExporter.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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.tracing.exporter; - -import brave.handler.SpanHandler; -import io.opentelemetry.sdk.trace.export.SpanExporter; - -public interface TraceExporter { - - /** - * for otel - * - * @return - */ - SpanExporter getSpanExporter(); - - /** - * for brave - * - * @return - */ - SpanHandler getSpanHandler(); -} diff --git a/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/exporter/TraceExporterFactory.java b/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/exporter/TraceExporterFactory.java deleted file mode 100644 index 7327cf038e..0000000000 --- a/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/exporter/TraceExporterFactory.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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.tracing.exporter; - -import org.apache.dubbo.common.logger.ErrorTypeAwareLogger; -import org.apache.dubbo.common.logger.LoggerFactory; -import org.apache.dubbo.common.utils.StringUtils; -import org.apache.dubbo.config.nested.ExporterConfig; -import org.apache.dubbo.rpc.model.ApplicationModel; -import org.apache.dubbo.tracing.exporter.otlp.OTlpExporter; -import org.apache.dubbo.tracing.exporter.zipkin.ZipkinExporter; - -import brave.handler.SpanHandler; -import io.opentelemetry.sdk.trace.export.SpanExporter; - -import java.util.ArrayList; -import java.util.List; - -public class TraceExporterFactory { - - private final static ErrorTypeAwareLogger LOGGER = LoggerFactory.getErrorTypeAwareLogger(TraceExporterFactory.class); - - /** - * for OTel - */ - public static List getSpanExporters(ApplicationModel applicationModel, ExporterConfig exporterConfig) { - ExporterConfig.ZipkinConfig zipkinConfig = exporterConfig.getZipkinConfig(); - ExporterConfig.OtlpConfig otlpConfig = exporterConfig.getOtlpConfig(); - List res = new ArrayList<>(); - if (zipkinConfig != null && StringUtils.isNotEmpty(zipkinConfig.getEndpoint())) { - ZipkinExporter zipkinExporter = new ZipkinExporter(applicationModel, zipkinConfig); - LOGGER.info("Create zipkin span exporter."); - res.add(zipkinExporter.getSpanExporter()); - } - if (otlpConfig != null && StringUtils.isNotEmpty(otlpConfig.getEndpoint())) { - OTlpExporter otlpExporter = new OTlpExporter(applicationModel, otlpConfig); - LOGGER.info("Create OTlp span exporter."); - res.add(otlpExporter.getSpanExporter()); - } - - return res; - } - - /** - * for Brave - */ - public static List getSpanHandlers(ApplicationModel applicationModel, ExporterConfig exporterConfig) { - List res = new ArrayList<>(); - // TODO brave SpanHandler impl - return res; - } -} diff --git a/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/exporter/otlp/OTlpExporter.java b/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/exporter/otlp/OTlpExporter.java deleted file mode 100644 index 72da78a795..0000000000 --- a/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/exporter/otlp/OTlpExporter.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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.tracing.exporter.otlp; - -import org.apache.dubbo.config.nested.ExporterConfig; -import org.apache.dubbo.rpc.model.ApplicationModel; -import org.apache.dubbo.tracing.exporter.TraceExporter; - -import brave.handler.SpanHandler; -import io.opentelemetry.exporter.otlp.http.trace.OtlpHttpSpanExporter; -import io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporter; -import io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporterBuilder; -import io.opentelemetry.sdk.trace.export.SpanExporter; - -import java.util.Map; - -public class OTlpExporter implements TraceExporter { - - private final ApplicationModel applicationModel; - private final ExporterConfig.OtlpConfig otlpConfig; - - public OTlpExporter(ApplicationModel applicationModel, ExporterConfig.OtlpConfig otlpConfig) { - this.applicationModel = applicationModel; - this.otlpConfig = otlpConfig; - } - - @Override - public SpanExporter getSpanExporter() { - OtlpGrpcSpanExporter externalOTlpGrpcSpanExporter = applicationModel.getBeanFactory().getBean(OtlpGrpcSpanExporter.class); - if (externalOTlpGrpcSpanExporter != null) { - return externalOTlpGrpcSpanExporter; - } - OtlpHttpSpanExporter externalOtlpHttpSpanExporter = applicationModel.getBeanFactory().getBean(OtlpHttpSpanExporter.class); - if (externalOtlpHttpSpanExporter != null) { - return externalOtlpHttpSpanExporter; - } - OtlpGrpcSpanExporterBuilder builder = OtlpGrpcSpanExporter.builder() - .setEndpoint(otlpConfig.getEndpoint()) - .setTimeout(otlpConfig.getTimeout()) - .setCompression(otlpConfig.getCompressionMethod()); - for (Map.Entry entry : otlpConfig.getHeaders().entrySet()) { - builder.addHeader(entry.getKey(), entry.getValue()); - } - return builder.build(); - } - - @Override - public SpanHandler getSpanHandler() { - // OTlp is only belong to OTel. - return null; - } -} diff --git a/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/exporter/zipkin/ZipkinExporter.java b/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/exporter/zipkin/ZipkinExporter.java deleted file mode 100644 index c0c00c6fa8..0000000000 --- a/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/exporter/zipkin/ZipkinExporter.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * 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.tracing.exporter.zipkin; - -import org.apache.dubbo.config.nested.ExporterConfig; -import org.apache.dubbo.rpc.model.ApplicationModel; -import org.apache.dubbo.tracing.exporter.TraceExporter; - -import brave.handler.SpanHandler; -import io.opentelemetry.exporter.zipkin.ZipkinSpanExporter; -import io.opentelemetry.sdk.trace.export.SpanExporter; -import zipkin2.Span; -import zipkin2.codec.BytesEncoder; -import zipkin2.codec.SpanBytesEncoder; - -public class ZipkinExporter implements TraceExporter { - - private final ApplicationModel applicationModel; - private final ExporterConfig.ZipkinConfig zipkinConfig; - - public ZipkinExporter(ApplicationModel applicationModel, ExporterConfig.ZipkinConfig zipkinConfig) { - this.applicationModel = applicationModel; - this.zipkinConfig = zipkinConfig; - } - - @Override - public SpanExporter getSpanExporter() { - BytesEncoder encoder = getSpanBytesEncoder(); - return ZipkinSpanExporter.builder() - .setEncoder(encoder) - .setEndpoint(zipkinConfig.getEndpoint()) - .setReadTimeout(zipkinConfig.getReadTimeout()) - .build(); - } - - @Override - public SpanHandler getSpanHandler() { - // TODO SpanHandler of Brave impl - return null; - } - - private BytesEncoder getSpanBytesEncoder() { - BytesEncoder encoder = applicationModel.getBeanFactory().getBean(BytesEncoder.class); - return encoder == null ? SpanBytesEncoder.JSON_V2 : encoder; - } -} diff --git a/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/tracer/PropagatorProvider.java b/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/tracer/PropagatorProvider.java deleted file mode 100644 index dc9b58f4e0..0000000000 --- a/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/tracer/PropagatorProvider.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * 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.tracing.tracer; - -import io.micrometer.tracing.propagation.Propagator; - -public interface PropagatorProvider { - - /** - * The real propagator will come from tracer implementation (OTel / Brave) - * - * @return Propagator - */ - Propagator getPropagator(); -} diff --git a/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/tracer/PropagatorProviderFactory.java b/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/tracer/PropagatorProviderFactory.java deleted file mode 100644 index 066cb7ad63..0000000000 --- a/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/tracer/PropagatorProviderFactory.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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.tracing.tracer; - -import org.apache.dubbo.tracing.tracer.brave.BravePropagatorProvider; -import org.apache.dubbo.tracing.tracer.otel.OTelPropagatorProvider; -import org.apache.dubbo.tracing.utils.ObservationSupportUtil; - -public class PropagatorProviderFactory { - - public static PropagatorProvider getPropagatorProvider() { - // If support OTel firstly, return OTel, then Brave. - if (ObservationSupportUtil.isSupportOTelTracer()) { - return new OTelPropagatorProvider(); - } - - if (ObservationSupportUtil.isSupportBraveTracer()) { - return new BravePropagatorProvider(); - } - - return null; - } -} diff --git a/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/tracer/TracerProvider.java b/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/tracer/TracerProvider.java deleted file mode 100644 index 05305ada67..0000000000 --- a/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/tracer/TracerProvider.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * 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.tracing.tracer; - -import io.micrometer.tracing.Tracer; - -public interface TracerProvider { - - /** - * Tracer of Micrometer. The real tracer will come from tracer implementation (OTel / Brave) - * - * @return Tracer - */ - Tracer getTracer(); - -} diff --git a/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/tracer/TracerProviderFactory.java b/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/tracer/TracerProviderFactory.java deleted file mode 100644 index 7e325809cb..0000000000 --- a/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/tracer/TracerProviderFactory.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * 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.tracing.tracer; - -import org.apache.dubbo.config.TracingConfig; -import org.apache.dubbo.rpc.model.ApplicationModel; -import org.apache.dubbo.tracing.tracer.brave.BraveProvider; -import org.apache.dubbo.tracing.tracer.otel.OpenTelemetryProvider; -import org.apache.dubbo.tracing.utils.ObservationSupportUtil; - -public class TracerProviderFactory { - - public static TracerProvider getProvider(ApplicationModel applicationModel, TracingConfig tracingConfig) { - // If support OTel firstly, return OTel, then Brave. - if (ObservationSupportUtil.isSupportOTelTracer()) { - return new OpenTelemetryProvider(applicationModel, tracingConfig); - } - - if (ObservationSupportUtil.isSupportBraveTracer()) { - return new BraveProvider(applicationModel, tracingConfig); - } - - return null; - } -} diff --git a/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/tracer/brave/BravePropagatorProvider.java b/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/tracer/brave/BravePropagatorProvider.java deleted file mode 100644 index 8560a5b149..0000000000 --- a/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/tracer/brave/BravePropagatorProvider.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * 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.tracing.tracer.brave; - -import org.apache.dubbo.tracing.tracer.PropagatorProvider; - -import io.micrometer.tracing.propagation.Propagator; - - -public class BravePropagatorProvider implements PropagatorProvider { - - @Override - public Propagator getPropagator() { - // TODO impl - return null; - } -} diff --git a/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/tracer/brave/BraveProvider.java b/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/tracer/brave/BraveProvider.java deleted file mode 100644 index 9ab8172b02..0000000000 --- a/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/tracer/brave/BraveProvider.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * 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.tracing.tracer.brave; - -import org.apache.dubbo.config.TracingConfig; -import org.apache.dubbo.rpc.model.ApplicationModel; -import org.apache.dubbo.tracing.tracer.TracerProvider; - -import io.micrometer.tracing.Tracer; - - -public class BraveProvider implements TracerProvider { - - private final ApplicationModel applicationModel; - private final TracingConfig tracingConfig; - - public BraveProvider(ApplicationModel applicationModel, TracingConfig tracingConfig) { - this.applicationModel = applicationModel; - this.tracingConfig = tracingConfig; - } - - @Override - public Tracer getTracer() { - // TODO impl - return null; - } -} diff --git a/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/tracer/otel/OTelPropagatorProvider.java b/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/tracer/otel/OTelPropagatorProvider.java deleted file mode 100644 index 9f537f1e4d..0000000000 --- a/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/tracer/otel/OTelPropagatorProvider.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * 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.tracing.tracer.otel; - -import org.apache.dubbo.tracing.tracer.PropagatorProvider; - -import io.micrometer.tracing.otel.bridge.OtelPropagator; -import io.micrometer.tracing.propagation.Propagator; -import io.opentelemetry.api.trace.Tracer; -import io.opentelemetry.context.propagation.ContextPropagators; - -public class OTelPropagatorProvider implements PropagatorProvider { - - private static Propagator propagator; - - @Override - public Propagator getPropagator() { - return propagator; - } - - protected static void createMicrometerPropagator(ContextPropagators contextPropagators, Tracer tracer) { - propagator = new OtelPropagator(contextPropagators, tracer); - } -} diff --git a/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/tracer/otel/OpenTelemetryProvider.java b/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/tracer/otel/OpenTelemetryProvider.java deleted file mode 100644 index 36b3c3f191..0000000000 --- a/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/tracer/otel/OpenTelemetryProvider.java +++ /dev/null @@ -1,212 +0,0 @@ -/* - * 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.tracing.tracer.otel; - -import org.apache.dubbo.common.Version; -import org.apache.dubbo.common.lang.Nullable; -import org.apache.dubbo.config.ApplicationConfig; -import org.apache.dubbo.config.TracingConfig; -import org.apache.dubbo.config.nested.BaggageConfig; -import org.apache.dubbo.config.nested.PropagationConfig; -import org.apache.dubbo.rpc.model.ApplicationModel; -import org.apache.dubbo.tracing.exporter.TraceExporterFactory; -import org.apache.dubbo.tracing.tracer.TracerProvider; - -import io.micrometer.tracing.Tracer; -import io.micrometer.tracing.otel.bridge.CompositeSpanExporter; -import io.micrometer.tracing.otel.bridge.EventListener; -import io.micrometer.tracing.otel.bridge.EventPublishingContextWrapper; -import io.micrometer.tracing.otel.bridge.OtelBaggageManager; -import io.micrometer.tracing.otel.bridge.OtelCurrentTraceContext; -import io.micrometer.tracing.otel.bridge.OtelTracer; -import io.micrometer.tracing.otel.bridge.Slf4JBaggageEventListener; -import io.micrometer.tracing.otel.bridge.Slf4JEventListener; -import io.micrometer.tracing.otel.propagation.BaggageTextMapPropagator; -import io.opentelemetry.api.baggage.propagation.W3CBaggagePropagator; -import io.opentelemetry.api.common.Attributes; -import io.opentelemetry.api.trace.propagation.W3CTraceContextPropagator; -import io.opentelemetry.context.ContextStorage; -import io.opentelemetry.context.propagation.ContextPropagators; -import io.opentelemetry.context.propagation.TextMapPropagator; -import io.opentelemetry.extension.trace.propagation.B3Propagator; -import io.opentelemetry.sdk.OpenTelemetrySdk; -import io.opentelemetry.sdk.resources.Resource; -import io.opentelemetry.sdk.trace.SdkTracerProvider; -import io.opentelemetry.sdk.trace.export.BatchSpanProcessor; -import io.opentelemetry.sdk.trace.export.SpanExporter; -import io.opentelemetry.sdk.trace.samplers.Sampler; -import io.opentelemetry.semconv.resource.attributes.ResourceAttributes; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -public class OpenTelemetryProvider implements TracerProvider { - - private static final String DEFAULT_APPLICATION_NAME = "dubbo-application"; - private final ApplicationModel applicationModel; - private final TracingConfig tracingConfig; - - private OTelEventPublisher publisher; - private OtelCurrentTraceContext otelCurrentTraceContext; - - public OpenTelemetryProvider(ApplicationModel applicationModel, TracingConfig tracingConfig) { - this.applicationModel = applicationModel; - this.tracingConfig = tracingConfig; - } - - @Override - public Tracer getTracer() { - // [OTel component] SpanExporter is a component that gets called when a span is finished. - List spanExporters = TraceExporterFactory.getSpanExporters(applicationModel, tracingConfig.getTracingExporter()); - - String applicationName = applicationModel.getApplicationConfigManager().getApplication() - .map(ApplicationConfig::getName) - .orElse(DEFAULT_APPLICATION_NAME); - - this.publisher = new OTelEventPublisher(getEventListeners()); - - // [Micrometer Tracing component] A Micrometer Tracing wrapper for OTel - this.otelCurrentTraceContext = createCurrentTraceContext(); - - // [OTel component] SdkTracerProvider is an SDK implementation for TracerProvider - SdkTracerProvider sdkTracerProvider = SdkTracerProvider.builder() - .setSampler(getSampler()) - .setResource(Resource.create(Attributes.of(ResourceAttributes.SERVICE_NAME, applicationName))) - .addSpanProcessor(BatchSpanProcessor - .builder(new CompositeSpanExporter(spanExporters, null, null, null)) - .build()) - .build(); - - ContextPropagators otelContextPropagators = createOtelContextPropagators(); - - // [OTel component] The SDK implementation of OpenTelemetry - OpenTelemetrySdk openTelemetrySdk = OpenTelemetrySdk.builder() - .setTracerProvider(sdkTracerProvider) - .setPropagators(otelContextPropagators) - .build(); - - // [OTel component] Tracer is a component that handles the life-cycle of a span - io.opentelemetry.api.trace.Tracer otelTracer = openTelemetrySdk.getTracerProvider() - .get("org.apache.dubbo", Version.getVersion()); - - OTelPropagatorProvider.createMicrometerPropagator(otelContextPropagators, otelTracer); - - // [Micrometer Tracing component] A Micrometer Tracing wrapper for OTel's Tracer. - return new OtelTracer(otelTracer, otelCurrentTraceContext, publisher, - new OtelBaggageManager(otelCurrentTraceContext, - tracingConfig.getBaggage().getRemoteFields(), - Collections.emptyList())); - } - - /** - * sampler with probability - * - * @return sampler - */ - private Sampler getSampler() { - Sampler rootSampler = Sampler.traceIdRatioBased(tracingConfig.getSampling().getProbability()); - return Sampler.parentBased(rootSampler); - } - - private List getEventListeners() { - List listeners = new ArrayList<>(); - - // [Micrometer Tracing component] A Micrometer Tracing listener for setting up MDC. - Slf4JEventListener slf4JEventListener = new Slf4JEventListener(); - listeners.add(slf4JEventListener); - - if (tracingConfig.getBaggage().getEnabled()) { - // [Micrometer Tracing component] A Micrometer Tracing listener for setting Baggage in MDC. - // Customizable with correlation fields. - Slf4JBaggageEventListener slf4JBaggageEventListener = new Slf4JBaggageEventListener(tracingConfig.getBaggage().getCorrelation().getFields()); - listeners.add(slf4JBaggageEventListener); - } - - return listeners; - } - - private OtelCurrentTraceContext createCurrentTraceContext() { - ContextStorage.addWrapper(new EventPublishingContextWrapper(publisher)); - return new OtelCurrentTraceContext(); - } - - private ContextPropagators createOtelContextPropagators() { - return ContextPropagators.create( - TextMapPropagator.composite( - PropagatorFactory.getPropagator(tracingConfig.getPropagation(), - tracingConfig.getBaggage(), - otelCurrentTraceContext - ))); - } - - static class OTelEventPublisher implements OtelTracer.EventPublisher { - - private final List listeners; - - OTelEventPublisher(List listeners) { - this.listeners = listeners; - } - - @Override - public void publishEvent(Object event) { - for (EventListener listener : this.listeners) { - listener.onEvent(event); - } - } - } - - static class PropagatorFactory { - - public static TextMapPropagator getPropagator(PropagationConfig propagationConfig, - @Nullable BaggageConfig baggageConfig, - @Nullable OtelCurrentTraceContext currentTraceContext) { - if (baggageConfig == null || !baggageConfig.getEnabled()) { - return getPropagatorWithoutBaggage(propagationConfig); - } - return getPropagatorWithBaggage(propagationConfig, baggageConfig, currentTraceContext); - } - - private static TextMapPropagator getPropagatorWithoutBaggage(PropagationConfig propagationConfig) { - String type = propagationConfig.getType(); - if ("B3".equals(type)) { - return B3Propagator.injectingSingleHeader(); - } else if ("W3C".equals(type)) { - return W3CTraceContextPropagator.getInstance(); - } - return TextMapPropagator.noop(); - } - - private static TextMapPropagator getPropagatorWithBaggage(PropagationConfig propagationConfig, - BaggageConfig baggageConfig, - OtelCurrentTraceContext currentTraceContext) { - String type = propagationConfig.getType(); - if ("B3".equals(type)) { - List remoteFields = baggageConfig.getRemoteFields(); - return TextMapPropagator.composite(B3Propagator.injectingSingleHeader(), - new BaggageTextMapPropagator(remoteFields, - new OtelBaggageManager(currentTraceContext, remoteFields, Collections.emptyList()))); - } else if ("W3C".equals(type)) { - List remoteFields = baggageConfig.getRemoteFields(); - return TextMapPropagator.composite(W3CTraceContextPropagator.getInstance(), - W3CBaggagePropagator.getInstance(), new BaggageTextMapPropagator(remoteFields, - new OtelBaggageManager(currentTraceContext, remoteFields, Collections.emptyList()))); - } - return TextMapPropagator.noop(); - } - } -} diff --git a/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/utils/ObservationSupportUtil.java b/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/utils/ObservationSupportUtil.java deleted file mode 100644 index 4cf8e05edf..0000000000 --- a/dubbo-metrics/dubbo-tracing/src/main/java/org/apache/dubbo/tracing/utils/ObservationSupportUtil.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * 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.tracing.utils; - -import org.apache.dubbo.common.utils.ClassUtils; - -public class ObservationSupportUtil { - - public static boolean isSupportObservation() { - return isClassPresent("io.micrometer.observation.Observation") - && isClassPresent("io.micrometer.observation.ObservationRegistry") - && isClassPresent("io.micrometer.observation.ObservationHandler"); - } - - public static boolean isSupportTracing() { - return isClassPresent("io.micrometer.tracing.Tracer") - && isClassPresent("io.micrometer.tracing.propagation.Propagator"); - } - - public static boolean isSupportOTelTracer() { - return isClassPresent("io.micrometer.tracing.otel.bridge.OtelTracer") - && isClassPresent("io.opentelemetry.sdk.trace.SdkTracerProvider") - && isClassPresent("io.opentelemetry.api.OpenTelemetry"); - } - - public static boolean isSupportBraveTracer() { - return isClassPresent("io.micrometer.tracing.Tracer") - && isClassPresent("io.micrometer.tracing.brave.bridge.BraveTracer") - && isClassPresent("brave.Tracing"); - } - - private static boolean isClassPresent(String className) { - return ClassUtils.isPresent(className, ObservationSupportUtil.class.getClassLoader()); - } -} diff --git a/dubbo-metrics/dubbo-tracing/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.Filter b/dubbo-metrics/dubbo-tracing/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.Filter deleted file mode 100644 index a7efac7c5e..0000000000 --- a/dubbo-metrics/dubbo-tracing/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.Filter +++ /dev/null @@ -1 +0,0 @@ -observationreceiver=org.apache.dubbo.tracing.filter.ObservationReceiverFilter \ No newline at end of file diff --git a/dubbo-metrics/dubbo-tracing/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.cluster.filter.ClusterFilter b/dubbo-metrics/dubbo-tracing/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.cluster.filter.ClusterFilter deleted file mode 100644 index f13199c666..0000000000 --- a/dubbo-metrics/dubbo-tracing/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.cluster.filter.ClusterFilter +++ /dev/null @@ -1 +0,0 @@ -observationsender=org.apache.dubbo.tracing.filter.ObservationSenderFilter \ No newline at end of file diff --git a/dubbo-metrics/dubbo-tracing/src/test/java/org/apache/dubbo/tracing/tracer/PropagatorProviderFactoryTest.java b/dubbo-metrics/dubbo-tracing/src/test/java/org/apache/dubbo/tracing/tracer/PropagatorProviderFactoryTest.java deleted file mode 100644 index 18f1a74e0e..0000000000 --- a/dubbo-metrics/dubbo-tracing/src/test/java/org/apache/dubbo/tracing/tracer/PropagatorProviderFactoryTest.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * 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.tracing.tracer; - -import org.apache.dubbo.common.utils.Assert; -import org.apache.dubbo.tracing.tracer.otel.OTelPropagatorProvider; - -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -class PropagatorProviderFactoryTest { - - @Test - void testPropagatorProviderFactory() { - PropagatorProvider propagatorProvider = PropagatorProviderFactory.getPropagatorProvider(); - Assert.notNull(propagatorProvider, "PropagatorProvider should not be null"); - assertEquals(OTelPropagatorProvider.class, propagatorProvider.getClass()); - } -} \ No newline at end of file diff --git a/dubbo-metrics/dubbo-tracing/src/test/java/org/apache/dubbo/tracing/tracer/otel/OTelPropagatorProviderTest.java b/dubbo-metrics/dubbo-tracing/src/test/java/org/apache/dubbo/tracing/tracer/otel/OTelPropagatorProviderTest.java deleted file mode 100644 index 83f2cd2df0..0000000000 --- a/dubbo-metrics/dubbo-tracing/src/test/java/org/apache/dubbo/tracing/tracer/otel/OTelPropagatorProviderTest.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * 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.tracing.tracer.otel; - -import org.apache.dubbo.common.utils.Assert; - -import io.micrometer.tracing.propagation.Propagator; -import io.opentelemetry.api.trace.Tracer; -import io.opentelemetry.context.propagation.ContextPropagators; -import org.junit.jupiter.api.Test; - -import static org.mockito.Mockito.mock; - -class OTelPropagatorProviderTest { - - @Test - void testOTelPropagatorProvider() { - ContextPropagators contextPropagators = mock(ContextPropagators.class); - Tracer tracer = mock(Tracer.class); - OTelPropagatorProvider.createMicrometerPropagator(contextPropagators, tracer); - OTelPropagatorProvider oTelPropagatorProvider = new OTelPropagatorProvider(); - Propagator propagator = oTelPropagatorProvider.getPropagator(); - Assert.notNull(propagator, "Propagator don't be null."); - } -} \ No newline at end of file diff --git a/dubbo-metrics/dubbo-tracing/src/test/java/org/apache/dubbo/tracing/tracer/otel/OpenTelemetryProviderTest.java b/dubbo-metrics/dubbo-tracing/src/test/java/org/apache/dubbo/tracing/tracer/otel/OpenTelemetryProviderTest.java deleted file mode 100644 index 0374912c3a..0000000000 --- a/dubbo-metrics/dubbo-tracing/src/test/java/org/apache/dubbo/tracing/tracer/otel/OpenTelemetryProviderTest.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * 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.tracing.tracer.otel; - -import org.apache.dubbo.common.utils.Assert; -import org.apache.dubbo.config.TracingConfig; -import org.apache.dubbo.config.nested.BaggageConfig; -import org.apache.dubbo.config.nested.ExporterConfig; -import org.apache.dubbo.rpc.model.ApplicationModel; -import org.apache.dubbo.tracing.tracer.TracerProvider; -import org.apache.dubbo.tracing.tracer.TracerProviderFactory; - -import io.micrometer.tracing.Tracer; -import io.micrometer.tracing.otel.bridge.OtelTracer; -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -class OpenTelemetryProviderTest { - - @Test - void testGetTracer() { - TracingConfig tracingConfig = new TracingConfig(); - tracingConfig.setEnabled(true); - ExporterConfig exporterConfig = new ExporterConfig(); - exporterConfig.setZipkinConfig(new ExporterConfig.ZipkinConfig("")); - tracingConfig.setTracingExporter(exporterConfig); - TracerProvider tracerProvider1 = TracerProviderFactory.getProvider(ApplicationModel.defaultModel(), tracingConfig); - Assert.notNull(tracerProvider1, "TracerProvider should not be null."); - Tracer tracer1 = tracerProvider1.getTracer(); - assertEquals(OtelTracer.class, tracer1.getClass()); - - tracingConfig.setBaggage(new BaggageConfig(false)); - TracerProvider tracerProvider2 = TracerProviderFactory.getProvider(ApplicationModel.defaultModel(), tracingConfig); - Assert.notNull(tracerProvider2, "TracerProvider should not be null."); - Tracer tracer2 = tracerProvider2.getTracer(); - assertEquals(OtelTracer.class, tracer2.getClass()); - } -} \ No newline at end of file diff --git a/dubbo-metrics/dubbo-tracing/src/test/java/org/apache/dubbo/tracing/utils/ObservationSupportUtilTest.java b/dubbo-metrics/dubbo-tracing/src/test/java/org/apache/dubbo/tracing/utils/ObservationSupportUtilTest.java deleted file mode 100644 index 3903053ca8..0000000000 --- a/dubbo-metrics/dubbo-tracing/src/test/java/org/apache/dubbo/tracing/utils/ObservationSupportUtilTest.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * 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.tracing.utils; - -import org.apache.dubbo.common.utils.Assert; - -import org.junit.jupiter.api.Test; - -public class ObservationSupportUtilTest { - - @Test - void testIsSupportObservation() { - boolean supportObservation = ObservationSupportUtil.isSupportObservation(); - Assert.assertTrue(supportObservation, "ObservationSupportUtil.isSupportObservation() should return true"); - } - - @Test - void testIsSupportTracing() { - boolean supportTracing = ObservationSupportUtil.isSupportTracing(); - Assert.assertTrue(supportTracing, "ObservationSupportUtil.isSupportTracing() should return true"); - } - - @Test - void testIsSupportOTelTracer() { - boolean supportOTelTracer = ObservationSupportUtil.isSupportOTelTracer(); - Assert.assertTrue(supportOTelTracer, "ObservationSupportUtil.isSupportOTelTracer() should return true"); - } - - @Test - void testIsSupportBraveTracer() { - boolean supportBraveTracer = ObservationSupportUtil.isSupportBraveTracer(); - Assert.assertTrue(supportBraveTracer, "ObservationSupportUtil.isSupportOTelTracer() should return true"); - } -} diff --git a/dubbo-metrics/pom.xml b/dubbo-metrics/pom.xml index c10defb8d6..04abd6e077 100644 --- a/dubbo-metrics/pom.xml +++ b/dubbo-metrics/pom.xml @@ -24,7 +24,6 @@ dubbo-metrics-metadata dubbo-metrics-prometheus dubbo-metrics-config-center - dubbo-tracing org.apache.dubbo diff --git a/dubbo-spring-boot/dubbo-spring-boot-starters/observability/autoconfigure/pom.xml b/dubbo-spring-boot/dubbo-spring-boot-starters/observability/autoconfigure/pom.xml index e8d997bda9..b9e1369556 100644 --- a/dubbo-spring-boot/dubbo-spring-boot-starters/observability/autoconfigure/pom.xml +++ b/dubbo-spring-boot/dubbo-spring-boot-starters/observability/autoconfigure/pom.xml @@ -137,12 +137,6 @@ ${project.version} true - - org.apache.dubbo - dubbo-config-spring - ${project.version} - true - diff --git a/dubbo-spring-boot/dubbo-spring-boot-starters/observability/autoconfigure/src/main/java/org/apache/dubbo/spring/boot/observability/autoconfigure/DubboObservationAutoConfiguration.java b/dubbo-spring-boot/dubbo-spring-boot-starters/observability/autoconfigure/src/main/java/org/apache/dubbo/spring/boot/observability/autoconfigure/DubboObservationAutoConfiguration.java index 10ffaa9be1..37f552fadf 100644 --- a/dubbo-spring-boot/dubbo-spring-boot-starters/observability/autoconfigure/src/main/java/org/apache/dubbo/spring/boot/observability/autoconfigure/DubboObservationAutoConfiguration.java +++ b/dubbo-spring-boot/dubbo-spring-boot-starters/observability/autoconfigure/src/main/java/org/apache/dubbo/spring/boot/observability/autoconfigure/DubboObservationAutoConfiguration.java @@ -18,7 +18,6 @@ package org.apache.dubbo.spring.boot.observability.autoconfigure; import org.apache.dubbo.common.logger.ErrorTypeAwareLogger; import org.apache.dubbo.common.logger.LoggerFactory; -import org.apache.dubbo.config.spring.context.event.DubboConfigInitEvent; import org.apache.dubbo.qos.protocol.QosProtocolWrapper; import org.apache.dubbo.rpc.model.ApplicationModel; import org.apache.dubbo.spring.boot.observability.autoconfigure.annotation.ConditionalOnDubboTracingEnable; @@ -29,15 +28,14 @@ import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactoryAware; import org.springframework.beans.factory.NoSuchBeanDefinitionException; import org.springframework.beans.factory.ObjectProvider; +import org.springframework.beans.factory.SmartInitializingSingleton; import org.springframework.boot.autoconfigure.AutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass; -import org.springframework.context.ApplicationListener; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.core.Ordered; import java.util.Arrays; @@ -48,7 +46,7 @@ import java.util.Arrays; @AutoConfiguration(after = DubboMicrometerTracingAutoConfiguration.class, afterName = "org.springframework.boot.actuate.autoconfigure.observation.ObservationAutoConfiguration") @ConditionalOnDubboTracingEnable @ConditionalOnClass(name = {"io.micrometer.observation.Observation", "io.micrometer.tracing.Tracer"}) -public class DubboObservationAutoConfiguration implements BeanFactoryAware, ApplicationListener, Ordered { +public class DubboObservationAutoConfiguration implements BeanFactoryAware, SmartInitializingSingleton { private final ErrorTypeAwareLogger logger = LoggerFactory.getErrorTypeAwareLogger(QosProtocolWrapper.class); @@ -81,21 +79,16 @@ public class DubboObservationAutoConfiguration implements BeanFactoryAware, Appl } @Override - public void onApplicationEvent(DubboConfigInitEvent event) { + public void afterSingletonsInstantiated() { try { applicationModel.getBeanFactory().registerBean(beanFactory.getBean(io.micrometer.observation.ObservationRegistry.class)); - applicationModel.getBeanFactory().registerBean(beanFactory.getBean(io.micrometer.tracing.Tracer.class)); - applicationModel.getBeanFactory().registerBean(beanFactory.getBean(io.micrometer.tracing.propagation.Propagator.class)); + io.micrometer.tracing.Tracer bean = beanFactory.getBean(io.micrometer.tracing.Tracer.class); + applicationModel.getBeanFactory().registerBean(bean); } catch (NoSuchBeanDefinitionException e) { - logger.info("Please use a version of micrometer higher than 1.10.0: " + e.getMessage()); + logger.info("Please use a version of micrometer higher than 1.10.0 :{}" + e.getMessage()); } } - @Override - public int getOrder() { - return HIGHEST_PRECEDENCE; - } - @Configuration(proxyBeanMethods = false) @ConditionalOnClass(MeterRegistry.class) @ConditionalOnMissingClass("io.micrometer.tracing.Tracer") diff --git a/dubbo-spring-boot/dubbo-spring-boot-starters/observability/autoconfigure/src/main/java/org/apache/dubbo/spring/boot/observability/autoconfigure/brave/BraveAutoConfiguration.java b/dubbo-spring-boot/dubbo-spring-boot-starters/observability/autoconfigure/src/main/java/org/apache/dubbo/spring/boot/observability/autoconfigure/brave/BraveAutoConfiguration.java index 8894b890cb..24be95c4ec 100644 --- a/dubbo-spring-boot/dubbo-spring-boot-starters/observability/autoconfigure/src/main/java/org/apache/dubbo/spring/boot/observability/autoconfigure/brave/BraveAutoConfiguration.java +++ b/dubbo-spring-boot/dubbo-spring-boot-starters/observability/autoconfigure/src/main/java/org/apache/dubbo/spring/boot/observability/autoconfigure/brave/BraveAutoConfiguration.java @@ -16,7 +16,8 @@ */ package org.apache.dubbo.spring.boot.observability.autoconfigure.brave; -import org.apache.dubbo.common.utils.StringUtils; +import org.apache.dubbo.config.ApplicationConfig; +import org.apache.dubbo.rpc.model.ModuleModel; import org.apache.dubbo.spring.boot.autoconfigure.DubboConfigurationProperties; import org.apache.dubbo.spring.boot.observability.autoconfigure.DubboMicrometerTracingAutoConfiguration; import org.apache.dubbo.spring.boot.observability.autoconfigure.ObservabilityUtils; @@ -52,12 +53,12 @@ public class BraveAutoConfiguration { /** * Default value for application name if {@code spring.application.name} is not set. */ - private static final String DEFAULT_APPLICATION_NAME = "dubbo-application"; + private static final String DEFAULT_APPLICATION_NAME = "application"; - private final DubboConfigurationProperties dubboConfigProperties; + private final ModuleModel moduleModel; - public BraveAutoConfiguration(DubboConfigurationProperties dubboConfigProperties) { - this.dubboConfigProperties = dubboConfigProperties; + public BraveAutoConfiguration(ModuleModel moduleModel) { + this.moduleModel = moduleModel; } @Bean @@ -75,10 +76,9 @@ public class BraveAutoConfiguration { public brave.Tracing braveTracing(List spanHandlers, List tracingCustomizers, brave.propagation.CurrentTraceContext currentTraceContext, brave.propagation.Propagation.Factory propagationFactory, brave.sampler.Sampler sampler) { - String applicationName = dubboConfigProperties.getApplication().getName(); - if (StringUtils.isEmpty(applicationName)) { - applicationName = DEFAULT_APPLICATION_NAME; - } + String applicationName = moduleModel.getApplicationModel().getApplicationConfigManager().getApplication() + .map(ApplicationConfig::getName) + .orElse(DEFAULT_APPLICATION_NAME); brave.Tracing.Builder builder = brave.Tracing.newBuilder().currentTraceContext(currentTraceContext).traceId128Bit(true) .supportsJoin(false).propagationFactory(propagationFactory).sampler(sampler) .localServiceName(applicationName); diff --git a/dubbo-spring-boot/dubbo-spring-boot-starters/observability/autoconfigure/src/main/java/org/apache/dubbo/spring/boot/observability/autoconfigure/otel/OpenTelemetryAutoConfiguration.java b/dubbo-spring-boot/dubbo-spring-boot-starters/observability/autoconfigure/src/main/java/org/apache/dubbo/spring/boot/observability/autoconfigure/otel/OpenTelemetryAutoConfiguration.java index 6b4e38f7c9..85babb77f8 100644 --- a/dubbo-spring-boot/dubbo-spring-boot-starters/observability/autoconfigure/src/main/java/org/apache/dubbo/spring/boot/observability/autoconfigure/otel/OpenTelemetryAutoConfiguration.java +++ b/dubbo-spring-boot/dubbo-spring-boot-starters/observability/autoconfigure/src/main/java/org/apache/dubbo/spring/boot/observability/autoconfigure/otel/OpenTelemetryAutoConfiguration.java @@ -18,7 +18,8 @@ package org.apache.dubbo.spring.boot.observability.autoconfigure.otel; import org.apache.dubbo.common.Version; -import org.apache.dubbo.common.utils.StringUtils; +import org.apache.dubbo.config.ApplicationConfig; +import org.apache.dubbo.rpc.model.ModuleModel; import org.apache.dubbo.spring.boot.autoconfigure.DubboConfigurationProperties; import org.apache.dubbo.spring.boot.observability.autoconfigure.DubboMicrometerTracingAutoConfiguration; import org.apache.dubbo.spring.boot.observability.autoconfigure.ObservabilityUtils; @@ -51,12 +52,15 @@ public class OpenTelemetryAutoConfiguration { /** * Default value for application name if {@code spring.application.name} is not set. */ - private static final String DEFAULT_APPLICATION_NAME = "dubbo-application"; + private static final String DEFAULT_APPLICATION_NAME = "application"; private final DubboConfigurationProperties dubboConfigProperties; - OpenTelemetryAutoConfiguration(DubboConfigurationProperties dubboConfigProperties) { + private final ModuleModel moduleModel; + + OpenTelemetryAutoConfiguration(DubboConfigurationProperties dubboConfigProperties, ModuleModel moduleModel) { this.dubboConfigProperties = dubboConfigProperties; + this.moduleModel = moduleModel; } @Bean @@ -70,10 +74,9 @@ public class OpenTelemetryAutoConfiguration { @ConditionalOnMissingBean io.opentelemetry.sdk.trace.SdkTracerProvider otelSdkTracerProvider(ObjectProvider spanProcessors, io.opentelemetry.sdk.trace.samplers.Sampler sampler) { - String applicationName = dubboConfigProperties.getApplication().getName(); - if (StringUtils.isEmpty(applicationName)) { - applicationName = DEFAULT_APPLICATION_NAME; - } + String applicationName = moduleModel.getApplicationModel().getApplicationConfigManager().getApplication() + .map(ApplicationConfig::getName) + .orElse(DEFAULT_APPLICATION_NAME); io.opentelemetry.sdk.trace.SdkTracerProviderBuilder builder = io.opentelemetry.sdk.trace.SdkTracerProvider.builder().setSampler(sampler) .setResource(io.opentelemetry.sdk.resources.Resource.create(io.opentelemetry.api.common.Attributes.of(io.opentelemetry.semconv.resource.attributes.ResourceAttributes.SERVICE_NAME, applicationName))); spanProcessors.orderedStream().forEach(builder::addSpanProcessor); diff --git a/dubbo-test/dubbo-dependencies-all/pom.xml b/dubbo-test/dubbo-dependencies-all/pom.xml index 991154acbb..526743f360 100644 --- a/dubbo-test/dubbo-dependencies-all/pom.xml +++ b/dubbo-test/dubbo-dependencies-all/pom.xml @@ -193,11 +193,6 @@ dubbo-metrics-prometheus ${project.version} - - org.apache.dubbo - dubbo-tracing - ${project.version} - @@ -210,6 +205,7 @@ dubbo-monitor-default ${project.version} + org.apache.dubbo From 25c2b3808a03a42c9d2cb2ca3e715b5f9ac043e5 Mon Sep 17 00:00:00 2001 From: Albumen Kevin Date: Wed, 21 Jun 2023 09:23:40 +0800 Subject: [PATCH 29/32] Disable register if registry disable register (#12579) * Disable register if registry disable register * Fix tag * Fix tag --- .../dubbo/config/ServiceConfigBase.java | 20 ++++++++++++++++++- .../apache/dubbo/config/ServiceConfig.java | 10 +++++++--- .../config/deploy/DefaultModuleDeployer.java | 2 +- .../org/apache/dubbo/registry/Constants.java | 1 + .../registry/support/AbstractRegistry.java | 10 +++++----- 5 files changed, 33 insertions(+), 10 deletions(-) diff --git a/dubbo-common/src/main/java/org/apache/dubbo/config/ServiceConfigBase.java b/dubbo-common/src/main/java/org/apache/dubbo/config/ServiceConfigBase.java index 265779ed3f..60c5c641ec 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/config/ServiceConfigBase.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/config/ServiceConfigBase.java @@ -426,7 +426,25 @@ public abstract class ServiceConfigBase extends AbstractServiceConfig { public abstract boolean isUnexported(); + /** + * Export service to network + * + * @param register Whether register service to registry. If false, can be registered manually + * through the {@link ServiceConfigBase#register(boolean)} API. + */ public abstract void export(boolean register); - public abstract void register(); + /** + * Register delay published service to registry. + */ + public final void register() { + register(false); + } + + /** + * Register delay published service to registry. + * + * @param onlyDefault only register those services that export with configured register false + */ + public abstract void register(boolean onlyDefault); } diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ServiceConfig.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ServiceConfig.java index a382c2fdb4..b22b0d2ab3 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ServiceConfig.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ServiceConfig.java @@ -57,10 +57,10 @@ import java.beans.Transient; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Arrays; -import java.util.TreeSet; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.TreeSet; import java.util.UUID; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; @@ -99,6 +99,7 @@ import static org.apache.dubbo.config.Constants.DUBBO_PORT_TO_BIND; import static org.apache.dubbo.config.Constants.DUBBO_PORT_TO_REGISTRY; import static org.apache.dubbo.config.Constants.SCOPE_NONE; import static org.apache.dubbo.registry.Constants.REGISTER_KEY; +import static org.apache.dubbo.registry.Constants.REGISTER_ORIGIN_KEY; import static org.apache.dubbo.remoting.Constants.BIND_IP_KEY; import static org.apache.dubbo.remoting.Constants.BIND_PORT_KEY; import static org.apache.dubbo.remoting.Constants.IS_PU_SERVER_KEY; @@ -310,7 +311,7 @@ public class ServiceConfig extends ServiceConfigBase { } @Override - public void register() { + public void register(boolean onlyDefault) { if (!this.exported) { return; } @@ -321,7 +322,9 @@ public class ServiceConfig extends ServiceConfigBase { } for (Exporter exporter : exporters) { - exporter.register(); + if (!onlyDefault || exporter.getInvoker().getUrl().getParameter(REGISTER_ORIGIN_KEY, true)) { + exporter.register(); + } } } } @@ -813,6 +816,7 @@ public class ServiceConfig extends ServiceConfigBase { @SuppressWarnings({"unchecked", "rawtypes"}) private void doExportUrl(URL url, boolean withMetaData, boolean register) { if (!register) { + url = url.addParameter(REGISTER_ORIGIN_KEY, url.getParameter(REGISTER_KEY, true)); url = url.addParameter(REGISTER_KEY, false); } Invoker invoker = proxyFactory.getInvoker(ref, (Class) interfaceClass, url); diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/deploy/DefaultModuleDeployer.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/deploy/DefaultModuleDeployer.java index 6bde316558..004be0e224 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/deploy/DefaultModuleDeployer.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/deploy/DefaultModuleDeployer.java @@ -441,7 +441,7 @@ public class DefaultModuleDeployer extends AbstractDeployer impleme if (!sc.isExported()) { return; } - sc.register(); + sc.register(true); } private void unexportServices() { diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/Constants.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/Constants.java index d21534436c..be991b256e 100644 --- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/Constants.java +++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/Constants.java @@ -21,6 +21,7 @@ public interface Constants { String REGISTER_IP_KEY = "register.ip"; String REGISTER_KEY = "register"; + String REGISTER_ORIGIN_KEY = "register_origin"; String SUBSCRIBE_KEY = "subscribe"; diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/AbstractRegistry.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/AbstractRegistry.java index 3a68a26433..1ba9b330b8 100644 --- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/AbstractRegistry.java +++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/AbstractRegistry.java @@ -61,12 +61,12 @@ import static org.apache.dubbo.common.constants.CommonConstants.ANY_VALUE; import static org.apache.dubbo.common.constants.CommonConstants.COMMA_SPLIT_PATTERN; import static org.apache.dubbo.common.constants.CommonConstants.FILE_KEY; import static org.apache.dubbo.common.constants.CommonConstants.REGISTRY_LOCAL_FILE_CACHE_ENABLED; -import static org.apache.dubbo.common.constants.LoggerCodeConstants.REGISTRY_EMPTY_ADDRESS; -import static org.apache.dubbo.common.constants.LoggerCodeConstants.REGISTRY_FAILED_NOTIFY_EVENT; -import static org.apache.dubbo.common.constants.LoggerCodeConstants.REGISTRY_FAILED_DESTROY_UNREGISTER_URL; -import static org.apache.dubbo.common.constants.LoggerCodeConstants.REGISTRY_FAILED_READ_WRITE_CACHE_FILE; -import static org.apache.dubbo.common.constants.LoggerCodeConstants.REGISTRY_FAILED_DELETE_LOCKFILE; import static org.apache.dubbo.common.constants.LoggerCodeConstants.INTERNAL_ERROR; +import static org.apache.dubbo.common.constants.LoggerCodeConstants.REGISTRY_EMPTY_ADDRESS; +import static org.apache.dubbo.common.constants.LoggerCodeConstants.REGISTRY_FAILED_DELETE_LOCKFILE; +import static org.apache.dubbo.common.constants.LoggerCodeConstants.REGISTRY_FAILED_DESTROY_UNREGISTER_URL; +import static org.apache.dubbo.common.constants.LoggerCodeConstants.REGISTRY_FAILED_NOTIFY_EVENT; +import static org.apache.dubbo.common.constants.LoggerCodeConstants.REGISTRY_FAILED_READ_WRITE_CACHE_FILE; import static org.apache.dubbo.common.constants.RegistryConstants.ACCEPTS_KEY; import static org.apache.dubbo.common.constants.RegistryConstants.DEFAULT_CATEGORY; import static org.apache.dubbo.common.constants.RegistryConstants.DYNAMIC_KEY; From 3b7934f5122833685acc6cd9bcff208f92ee9a6b Mon Sep 17 00:00:00 2001 From: Albumen Kevin Date: Wed, 21 Jun 2023 11:29:54 +0800 Subject: [PATCH 30/32] Fix registry repeat export same service (#12578) * Fix registry repeat export same service * fix uts * Fix export * Fix export --- ...ryCenterExportProviderIntegrationTest.java | 2 +- ...ryCenterExportProviderIntegrationTest.java | 2 +- .../RegistryScopeModelInitializer.java | 4 +- .../registry/integration/ExporterFactory.java | 42 +++++++++++++ .../integration/ReferenceCountExporter.java | 62 +++++++++++++++++++ .../integration/RegistryProtocol.java | 13 ++-- 6 files changed, 118 insertions(+), 7 deletions(-) create mode 100644 dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/ExporterFactory.java create mode 100644 dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/ReferenceCountExporter.java diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/exportprovider/MultipleRegistryCenterExportProviderIntegrationTest.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/exportprovider/MultipleRegistryCenterExportProviderIntegrationTest.java index 445ddb6dfc..d2f9b7ee2d 100644 --- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/exportprovider/MultipleRegistryCenterExportProviderIntegrationTest.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/exportprovider/MultipleRegistryCenterExportProviderIntegrationTest.java @@ -188,7 +188,7 @@ class MultipleRegistryCenterExportProviderIntegrationTest implements Integration // 1. InjvmExporter // 2. DubboExporter with service-discovery-registry protocol // 3. DubboExporter with registry protocol - Assertions.assertEquals(exporterListener.getExportedExporters().size(), 7); + Assertions.assertEquals(exporterListener.getExportedExporters().size(), 4); // The exported exporter contains MultipleRegistryCenterExportProviderFilter Assertions.assertTrue(exporterListener.getFilters().contains(filter)); diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/exportprovider/SingleRegistryCenterExportProviderIntegrationTest.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/exportprovider/SingleRegistryCenterExportProviderIntegrationTest.java index 3ab4bf7b53..41de19efcb 100644 --- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/exportprovider/SingleRegistryCenterExportProviderIntegrationTest.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/exportprovider/SingleRegistryCenterExportProviderIntegrationTest.java @@ -195,7 +195,7 @@ class SingleRegistryCenterExportProviderIntegrationTest implements IntegrationTe // 1. InjvmExporter // 2. DubboExporter with service-discovery-registry protocol // 3. DubboExporter with registry protocol - Assertions.assertEquals(exporterListener.getExportedExporters().size(), 5); + Assertions.assertEquals(exporterListener.getExportedExporters().size(), 4); // The exported exporter contains SingleRegistryCenterExportProviderFilter Assertions.assertTrue(exporterListener.getFilters().contains(filter)); // The consumer can be notified and get provider's metadata through metadata mapping info. diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/RegistryScopeModelInitializer.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/RegistryScopeModelInitializer.java index 6be4e29947..40c788985c 100644 --- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/RegistryScopeModelInitializer.java +++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/RegistryScopeModelInitializer.java @@ -17,6 +17,7 @@ package org.apache.dubbo.registry; import org.apache.dubbo.common.beans.factory.ScopeBeanFactory; +import org.apache.dubbo.registry.integration.ExporterFactory; import org.apache.dubbo.registry.support.RegistryManager; import org.apache.dubbo.rpc.model.ApplicationModel; import org.apache.dubbo.rpc.model.FrameworkModel; @@ -26,7 +27,8 @@ import org.apache.dubbo.rpc.model.ScopeModelInitializer; public class RegistryScopeModelInitializer implements ScopeModelInitializer { @Override public void initializeFrameworkModel(FrameworkModel frameworkModel) { - + ScopeBeanFactory beanFactory = frameworkModel.getBeanFactory(); + beanFactory.registerBean(ExporterFactory.class); } @Override diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/ExporterFactory.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/ExporterFactory.java new file mode 100644 index 0000000000..5eebc1bcaa --- /dev/null +++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/ExporterFactory.java @@ -0,0 +1,42 @@ +/* + * 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.registry.integration; + +import org.apache.dubbo.rpc.Exporter; + +import java.util.Map; +import java.util.concurrent.Callable; +import java.util.concurrent.ConcurrentHashMap; + +public class ExporterFactory { + private final Map> exporters = new ConcurrentHashMap<>(); + + protected ReferenceCountExporter createExporter(String providerKey, Callable> exporterProducer) { + return exporters.computeIfAbsent(providerKey, + key -> { + try { + return new ReferenceCountExporter<>(exporterProducer.call(), key, this); + } catch (Exception e) { + throw new RuntimeException(e); + } + }); + } + + protected void remove(String key, ReferenceCountExporter exporter) { + exporters.remove(key, exporter); + } +} diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/ReferenceCountExporter.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/ReferenceCountExporter.java new file mode 100644 index 0000000000..bcdce7172f --- /dev/null +++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/ReferenceCountExporter.java @@ -0,0 +1,62 @@ +/* + * 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.registry.integration; + +import org.apache.dubbo.rpc.Exporter; +import org.apache.dubbo.rpc.Invoker; + +import java.util.concurrent.atomic.AtomicInteger; + +public class ReferenceCountExporter implements Exporter { + private final Exporter exporter; + private final String providerKey; + private final ExporterFactory exporterFactory; + private final AtomicInteger count = new AtomicInteger(0); + + public ReferenceCountExporter(Exporter exporter, String providerKey, ExporterFactory exporterFactory) { + this.exporter = exporter; + this.providerKey = providerKey; + this.exporterFactory = exporterFactory; + } + + @Override + public Invoker getInvoker() { + return exporter.getInvoker(); + } + + public void increaseCount() { + count.incrementAndGet(); + } + + @Override + public void unexport() { + if (count.decrementAndGet() == 0) { + exporter.unexport(); + } + exporterFactory.remove(providerKey, this); + } + + @Override + public void register() { + + } + + @Override + public void unregister() { + + } +} diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryProtocol.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryProtocol.java index a9e3b908c7..b69376e784 100644 --- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryProtocol.java +++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryProtocol.java @@ -171,6 +171,7 @@ public class RegistryProtocol implements Protocol, ScopeModelAware { private ConcurrentMap reExportFailedTasks = new ConcurrentHashMap<>(); private HashedWheelTimer retryTimer = new HashedWheelTimer(new NamedThreadFactory("DubboReexportTimer", true), DEFAULT_REGISTRY_RETRY_PERIOD, TimeUnit.MILLISECONDS, 128); private FrameworkModel frameworkModel; + private ExporterFactory exporterFactory; //Filter the parameters that do not need to be output in url(Starting with .) private static String[] getFilteredKeys(URL url) { @@ -190,6 +191,7 @@ public class RegistryProtocol implements Protocol, ScopeModelAware { @Override public void setFrameworkModel(FrameworkModel frameworkModel) { this.frameworkModel = frameworkModel; + this.exporterFactory = frameworkModel.getBeanFactory().getBean(ExporterFactory.class); } public void setProtocol(Protocol protocol) { @@ -312,11 +314,13 @@ public class RegistryProtocol implements Protocol, ScopeModelAware { private ExporterChangeableWrapper doLocalExport(final Invoker originInvoker, URL providerUrl) { String providerUrlKey = getProviderUrlKey(originInvoker); String registryUrlKey = getRegistryUrlKey(originInvoker); + Invoker invokerDelegate = new InvokerDelegate<>(originInvoker, providerUrl); + ReferenceCountExporter exporter = exporterFactory.createExporter(providerUrlKey, () -> protocol.export(invokerDelegate)); return (ExporterChangeableWrapper) bounds.computeIfAbsent(providerUrlKey, _k -> new ConcurrentHashMap<>()) - .computeIfAbsent(registryUrlKey, s ->{ - Invoker invokerDelegate = new InvokerDelegate<>(originInvoker, providerUrl); - return new ExporterChangeableWrapper<>((Exporter) protocol.export(invokerDelegate), originInvoker); + .computeIfAbsent(registryUrlKey, s -> { + return new ExporterChangeableWrapper<>( + (ReferenceCountExporter) exporter, originInvoker); }); } @@ -953,8 +957,9 @@ public class RegistryProtocol implements Protocol, ScopeModelAware { private NotifyListener notifyListener; private final AtomicBoolean registered = new AtomicBoolean(false); - public ExporterChangeableWrapper(Exporter exporter, Invoker originInvoker) { + public ExporterChangeableWrapper(ReferenceCountExporter exporter, Invoker originInvoker) { this.exporter = exporter; + exporter.increaseCount(); this.originInvoker = originInvoker; FrameworkExecutorRepository frameworkExecutorRepository = originInvoker.getUrl().getOrDefaultFrameworkModel().getBeanFactory() .getBean(FrameworkExecutorRepository.class); From 9577d464a092596085bdc8f7c78ea3f482767246 Mon Sep 17 00:00:00 2001 From: Albumen Kevin Date: Wed, 21 Jun 2023 13:22:27 +0800 Subject: [PATCH 31/32] Triple set resolve fallback enable as default (#12575) * Triple set resolve fallback enable as default * use throw --- .../org/apache/dubbo/rpc/PathResolver.java | 4 ++- .../rpc/protocol/tri/TriplePathResolver.java | 9 ++++-- .../rpc/protocol/tri/TripleProtocol.java | 28 +++++++++++++++---- 3 files changed, 33 insertions(+), 8 deletions(-) diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/PathResolver.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/PathResolver.java index c3e910a56d..83c5979cb8 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/PathResolver.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/PathResolver.java @@ -27,7 +27,9 @@ import org.apache.dubbo.common.extension.SPI; @SPI(value = CommonConstants.TRIPLE, scope = ExtensionScope.FRAMEWORK) public interface PathResolver { - void add(String path, Invoker invoker); + Invoker add(String path, Invoker invoker); + + Invoker addIfAbsent(String path, Invoker invoker); Invoker resolve(String path); diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/TriplePathResolver.java b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/TriplePathResolver.java index a508e936cf..f3f9ebbc68 100644 --- a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/TriplePathResolver.java +++ b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/TriplePathResolver.java @@ -28,8 +28,13 @@ public class TriplePathResolver implements PathResolver { private final ConcurrentHashMap nativeStub = new ConcurrentHashMap<>(); @Override - public void add(String path, Invoker invoker) { - path2Invoker.put(path, invoker); + public Invoker add(String path, Invoker invoker) { + return path2Invoker.put(path, invoker); + } + + @Override + public Invoker addIfAbsent(String path, Invoker invoker) { + return path2Invoker.putIfAbsent(path, invoker); } @Override diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/TripleProtocol.java b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/TripleProtocol.java index 49650083be..4ec09e4a56 100644 --- a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/TripleProtocol.java +++ b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/TripleProtocol.java @@ -44,9 +44,9 @@ import java.util.Objects; import java.util.Set; import java.util.concurrent.ExecutorService; +import static org.apache.dubbo.config.Constants.SERVER_THREAD_POOL_NAME; import static org.apache.dubbo.rpc.Constants.H2_IGNORE_1_0_0_KEY; import static org.apache.dubbo.rpc.Constants.H2_RESOLVE_FALLBACK_TO_DEFAULT_KEY; -import static org.apache.dubbo.config.Constants.SERVER_THREAD_POOL_NAME; import static org.apache.dubbo.rpc.Constants.H2_SUPPORT_NO_LOWER_HEADER_KEY; public class TripleProtocol extends AbstractProtocol { @@ -65,7 +65,7 @@ public class TripleProtocol extends AbstractProtocol { public static boolean IGNORE_1_0_0_VERSION = false; - public static boolean RESOLVE_FALLBACK_TO_DEFAULT = false; + public static boolean RESOLVE_FALLBACK_TO_DEFAULT = true; public TripleProtocol(FrameworkModel frameworkModel) { this.frameworkModel = frameworkModel; @@ -77,7 +77,7 @@ public class TripleProtocol extends AbstractProtocol { IGNORE_1_0_0_VERSION = ConfigurationUtils.getEnvConfiguration(ApplicationModel.defaultModel()) .getBoolean(H2_IGNORE_1_0_0_KEY, false); RESOLVE_FALLBACK_TO_DEFAULT = ConfigurationUtils.getEnvConfiguration(ApplicationModel.defaultModel()) - .getBoolean(H2_RESOLVE_FALLBACK_TO_DEFAULT_KEY, false); + .getBoolean(H2_RESOLVE_FALLBACK_TO_DEFAULT_KEY, true); Set supported = frameworkModel.getExtensionLoader(DeCompressor.class) .getSupportedExtensions(); this.acceptEncodings = String.join(",", supported); @@ -113,9 +113,27 @@ public class TripleProtocol extends AbstractProtocol { invokers.add(invoker); - pathResolver.add(url.getServiceKey(), invoker); + Invoker previous = pathResolver.add(url.getServiceKey(), invoker); + if (previous != null) { + if (url.getServiceKey().equals(url.getServiceModel().getServiceModel().getInterfaceName())) { + logger.info("Already exists an invoker[" + previous.getUrl() + "] on path[" + url.getServiceKey() + + "], dubbo will override with invoker[" + url + "]"); + } else { + throw new IllegalStateException("Already exists an invoker[" + previous.getUrl() + "] on path[" + + url.getServiceKey() + "], failed to add invoker[" + url + + "] , please use unique serviceKey."); + } + } if (RESOLVE_FALLBACK_TO_DEFAULT) { - pathResolver.add(url.getServiceModel().getServiceModel().getInterfaceName(), invoker); + previous = pathResolver.addIfAbsent(url.getServiceModel().getServiceModel().getInterfaceName(), invoker); + if (previous != null) { + logger.info("Already exists an invoker[" + previous.getUrl() + "] on path[" + + url.getServiceModel().getServiceModel().getInterfaceName() + + "], dubbo will skip override with invoker[" + url + "]"); + } else { + logger.info("Add fallback triple invoker[" + url + "] to path[" + + url.getServiceModel().getServiceModel().getInterfaceName() + "] with invoker[" + url + "]"); + } } // set service status From f28c2fec72c16c6b77be1b6ad7615562f5a5eecc Mon Sep 17 00:00:00 2001 From: Albumen Kevin Date: Thu, 22 Jun 2023 08:49:23 +0800 Subject: [PATCH 32/32] Fix alibaba Rpc compact (#12581) * Fix alibaba Rpc compact * Fix alibaba Rpc compact * Fix alibaba Rpc compact * Fix alibaba Rpc compact --- .../com/alibaba/dubbo/common/Constants.java | 541 +++++++++++++++++- .../com/alibaba/dubbo/rpc/RpcContext.java | 20 + .../com/alibaba/dubbo/rpc/RpcException.java | 6 +- 3 files changed, 551 insertions(+), 16 deletions(-) diff --git a/dubbo-compatible/src/main/java/com/alibaba/dubbo/common/Constants.java b/dubbo-compatible/src/main/java/com/alibaba/dubbo/common/Constants.java index f62a9bd177..4ed46e5e23 100644 --- a/dubbo-compatible/src/main/java/com/alibaba/dubbo/common/Constants.java +++ b/dubbo-compatible/src/main/java/com/alibaba/dubbo/common/Constants.java @@ -23,21 +23,532 @@ import org.apache.dubbo.common.constants.QosConstants; import org.apache.dubbo.common.constants.RegistryConstants; import org.apache.dubbo.common.constants.RemotingConstants; +import java.util.concurrent.ExecutorService; +import java.util.regex.Pattern; + @Deprecated public class Constants implements CommonConstants, - QosConstants, - FilterConstants, - RegistryConstants, - RemotingConstants, - org.apache.dubbo.config.Constants, - org.apache.dubbo.remoting.Constants, - org.apache.dubbo.rpc.cluster.Constants, - org.apache.dubbo.monitor.Constants, - org.apache.dubbo.rpc.Constants, - org.apache.dubbo.rpc.protocol.dubbo.Constants, - org.apache.dubbo.common.serialize.Constants, - org.apache.dubbo.common.config.configcenter.Constants, - org.apache.dubbo.metadata.report.support.Constants , - org.apache.dubbo.rpc.protocol.rest.Constants, - org.apache.dubbo.registry.Constants { + QosConstants, + FilterConstants, + RegistryConstants, + RemotingConstants, + org.apache.dubbo.config.Constants, + org.apache.dubbo.remoting.Constants, + org.apache.dubbo.rpc.cluster.Constants, + org.apache.dubbo.monitor.Constants, + org.apache.dubbo.rpc.Constants, + org.apache.dubbo.rpc.protocol.dubbo.Constants, + org.apache.dubbo.common.serialize.Constants, + org.apache.dubbo.common.config.configcenter.Constants, + org.apache.dubbo.metadata.report.support.Constants, + org.apache.dubbo.rpc.protocol.rest.Constants, + org.apache.dubbo.registry.Constants { + public static final String PROVIDER = "provider"; + + public static final String CONSUMER = "consumer"; + + public static final String REGISTER = "register"; + + public static final String UNREGISTER = "unregister"; + + public static final String SUBSCRIBE = "subscribe"; + + public static final String UNSUBSCRIBE = "unsubscribe"; + + public static final String CATEGORY_KEY = "category"; + + public static final String PROVIDERS_CATEGORY = "providers"; + + public static final String CONSUMERS_CATEGORY = "consumers"; + + public static final String ROUTERS_CATEGORY = "routers"; + + public static final String CONFIGURATORS_CATEGORY = "configurators"; + + public static final String DEFAULT_CATEGORY = PROVIDERS_CATEGORY; + + public static final String ENABLED_KEY = "enabled"; + + public static final String DISABLED_KEY = "disabled"; + + public static final String VALIDATION_KEY = "validation"; + + public static final String CACHE_KEY = "cache"; + + public static final String DYNAMIC_KEY = "dynamic"; + + public static final String DUBBO_PROPERTIES_KEY = "dubbo.properties.file"; + + public static final String DEFAULT_DUBBO_PROPERTIES = "dubbo.properties"; + + public static final String SENT_KEY = "sent"; + + public static final boolean DEFAULT_SENT = false; + + public static final String REGISTRY_PROTOCOL = "registry"; + + public static final String $INVOKE = "$invoke"; + + public static final String $ECHO = "$echo"; + + public static final int DEFAULT_IO_THREADS = Runtime.getRuntime() + .availableProcessors() + 1; + + public static final String DEFAULT_PROXY = "javassist"; + + public static final int DEFAULT_PAYLOAD = 8 * 1024 * 1024; + + public static final String DEFAULT_CLUSTER = "failover"; + + public static final String DEFAULT_DIRECTORY = "dubbo"; + + public static final String DEFAULT_LOADBALANCE = "random"; + + public static final String DEFAULT_PROTOCOL = "dubbo"; + + public static final String DEFAULT_EXCHANGER = "header"; + + public static final String DEFAULT_TRANSPORTER = "netty"; + + public static final String DEFAULT_REMOTING_SERVER = "netty"; + + public static final String DEFAULT_REMOTING_CLIENT = "netty"; + + public static final String DEFAULT_REMOTING_CODEC = "dubbo"; + + public static final String DEFAULT_REMOTING_SERIALIZATION = "hessian2"; + + public static final String DEFAULT_HTTP_SERVER = "servlet"; + + public static final String DEFAULT_HTTP_CLIENT = "jdk"; + + public static final String DEFAULT_HTTP_SERIALIZATION = "json"; + + public static final String DEFAULT_CHARSET = "UTF-8"; + + public static final int DEFAULT_WEIGHT = 100; + + public static final int DEFAULT_FORKS = 2; + + public static final String DEFAULT_THREAD_NAME = "Dubbo"; + + public static final int DEFAULT_CORE_THREADS = 0; + + public static final int DEFAULT_THREADS = 200; + + public static final int DEFAULT_QUEUES = 0; + + public static final int DEFAULT_ALIVE = 60 * 1000; + + public static final int DEFAULT_CONNECTIONS = 0; + + public static final int DEFAULT_ACCEPTS = 0; + + public static final int DEFAULT_IDLE_TIMEOUT = 600 * 1000; + + public static final int DEFAULT_HEARTBEAT = 60 * 1000; + + public static final int DEFAULT_TIMEOUT = 1000; + + public static final int DEFAULT_CONNECT_TIMEOUT = 3000; + + public static final int DEFAULT_RETRIES = 2; + + public static final int DEFAULT_BUFFER_SIZE = 8 * 1024; + + public static final int MAX_BUFFER_SIZE = 16 * 1024; + + public static final int MIN_BUFFER_SIZE = 1 * 1024; + + public static final String REMOVE_VALUE_PREFIX = "-"; + + public static final String HIDE_KEY_PREFIX = "."; + + public static final String DEFAULT_KEY_PREFIX = "default."; + + public static final String DEFAULT_KEY = "default"; + + public static final String LOADBALANCE_KEY = "loadbalance"; + + public static final String ROUTER_KEY = "router"; + + public static final String CLUSTER_KEY = "cluster"; + + public static final String REGISTRY_KEY = "registry"; + + public static final String MONITOR_KEY = "monitor"; + + public static final String SIDE_KEY = "side"; + + public static final String PROVIDER_SIDE = "provider"; + + public static final String CONSUMER_SIDE = "consumer"; + + public static final String DEFAULT_REGISTRY = "dubbo"; + + public static final String BACKUP_KEY = "backup"; + + public static final String DIRECTORY_KEY = "directory"; + + public static final String DEPRECATED_KEY = "deprecated"; + + public static final String ANYHOST_KEY = "anyhost"; + + public static final String ANYHOST_VALUE = "0.0.0.0"; + + public static final String LOCALHOST_KEY = "localhost"; + + public static final String LOCALHOST_VALUE = "127.0.0.1"; + + public static final String APPLICATION_KEY = "application"; + + public static final String LOCAL_KEY = "local"; + + public static final String STUB_KEY = "stub"; + + public static final String MOCK_KEY = "mock"; + + public static final String PROTOCOL_KEY = "protocol"; + + public static final String PROXY_KEY = "proxy"; + + public static final String WEIGHT_KEY = "weight"; + + public static final String FORKS_KEY = "forks"; + + public static final String DEFAULT_THREADPOOL = "limited"; + + public static final String DEFAULT_CLIENT_THREADPOOL = "cached"; + + public static final String THREADPOOL_KEY = "threadpool"; + + public static final String THREAD_NAME_KEY = "threadname"; + + public static final String IO_THREADS_KEY = "iothreads"; + + public static final String CORE_THREADS_KEY = "corethreads"; + + public static final String THREADS_KEY = "threads"; + + public static final String QUEUES_KEY = "queues"; + + public static final String ALIVE_KEY = "alive"; + + public static final String EXECUTES_KEY = "executes"; + + public static final String BUFFER_KEY = "buffer"; + + public static final String PAYLOAD_KEY = "payload"; + + public static final String REFERENCE_FILTER_KEY = "reference.filter"; + + public static final String INVOKER_LISTENER_KEY = "invoker.listener"; + + public static final String SERVICE_FILTER_KEY = "service.filter"; + + public static final String EXPORTER_LISTENER_KEY = "exporter.listener"; + + public static final String ACCESS_LOG_KEY = "accesslog"; + + public static final String ACTIVES_KEY = "actives"; + + public static final String CONNECTIONS_KEY = "connections"; + + public static final String ACCEPTS_KEY = "accepts"; + + public static final String IDLE_TIMEOUT_KEY = "idle.timeout"; + + public static final String HEARTBEAT_KEY = "heartbeat"; + + public static final String HEARTBEAT_TIMEOUT_KEY = "heartbeat.timeout"; + + public static final String CONNECT_TIMEOUT_KEY = "connect.timeout"; + + public static final String TIMEOUT_KEY = "timeout"; + + public static final String RETRIES_KEY = "retries"; + + public static final String PROMPT_KEY = "prompt"; + + public static final String DEFAULT_PROMPT = "dubbo>"; + + public static final String CODEC_KEY = "codec"; + + public static final String SERIALIZATION_KEY = "serialization"; + + public static final String EXCHANGER_KEY = "exchanger"; + + public static final String TRANSPORTER_KEY = "transporter"; + + public static final String SERVER_KEY = "server"; + + public static final String CLIENT_KEY = "client"; + + public static final String ID_KEY = "id"; + + public static final String ASYNC_KEY = "async"; + + public static final String RETURN_KEY = "return"; + + public static final String TOKEN_KEY = "token"; + + public static final String METHOD_KEY = "method"; + + public static final String METHODS_KEY = "methods"; + + public static final String CHARSET_KEY = "charset"; + + public static final String RECONNECT_KEY = "reconnect"; + + public static final String SEND_RECONNECT_KEY = "send.reconnect"; + + public static final int DEFAULT_RECONNECT_PERIOD = 2000; + + public static final String SHUTDOWN_TIMEOUT_KEY = "shutdown.timeout"; + + public static final int DEFAULT_SHUTDOWN_TIMEOUT = 1000 * 60 * 15; + + public static final String PID_KEY = "pid"; + + public static final String TIMESTAMP_KEY = "timestamp"; + + public static final String WARMUP_KEY = "warmup"; + + public static final int DEFAULT_WARMUP = 10 * 60 * 1000; + + public static final String CHECK_KEY = "check"; + + public static final String REGISTER_KEY = "register"; + + public static final String SUBSCRIBE_KEY = "subscribe"; + + public static final String GROUP_KEY = "group"; + + public static final String PATH_KEY = "path"; + + public static final String INTERFACE_KEY = "interface"; + + public static final String GENERIC_KEY = "generic"; + + public static final String FILE_KEY = "file"; + + public static final String WAIT_KEY = "wait"; + + public static final String CLASSIFIER_KEY = "classifier"; + + public static final String VERSION_KEY = "version"; + + public static final String REVISION_KEY = "revision"; + + public static final String DUBBO_VERSION_KEY = "dubbo"; + + public static final String HESSIAN_VERSION_KEY = "hessian.version"; + + public static final String DISPATCHER_KEY = "dispatcher"; + + public static final String CHANNEL_HANDLER_KEY = "channel.handler"; + + public static final String DEFAULT_CHANNEL_HANDLER = "default"; + + public static final String ANY_VALUE = "*"; + + public static final String COMMA_SEPARATOR = ","; + + public static final Pattern COMMA_SPLIT_PATTERN = Pattern + .compile("\\s*[,]+\\s*"); + + public final static String PATH_SEPARATOR = "/"; + + public static final String REGISTRY_SEPARATOR = "|"; + + public static final Pattern REGISTRY_SPLIT_PATTERN = Pattern + .compile("\\s*[|;]+\\s*"); + + public static final String SEMICOLON_SEPARATOR = ";"; + + public static final Pattern SEMICOLON_SPLIT_PATTERN = Pattern + .compile("\\s*[;]+\\s*"); + + public static final String CONNECT_QUEUE_CAPACITY = "connect.queue.capacity"; + + public static final String CONNECT_QUEUE_WARNING_SIZE = "connect.queue.warning.size"; + + public static final int DEFAULT_CONNECT_QUEUE_WARNING_SIZE = 1000; + + public static final String CHANNEL_ATTRIBUTE_READONLY_KEY = "channel.readonly"; + + public static final String CHANNEL_READONLYEVENT_SENT_KEY = "channel.readonly.sent"; + + public static final String CHANNEL_SEND_READONLYEVENT_KEY = "channel.readonly.send"; + + public static final String COUNT_PROTOCOL = "count"; + + public static final String TRACE_PROTOCOL = "trace"; + + public static final String EMPTY_PROTOCOL = "empty"; + + public static final String ADMIN_PROTOCOL = "admin"; + + public static final String PROVIDER_PROTOCOL = "provider"; + + public static final String CONSUMER_PROTOCOL = "consumer"; + + public static final String ROUTE_PROTOCOL = "route"; + + public static final String SCRIPT_PROTOCOL = "script"; + + public static final String CONDITION_PROTOCOL = "condition"; + + public static final String MOCK_PROTOCOL = "mock"; + + public static final String RETURN_PREFIX = "return "; + + public static final String THROW_PREFIX = "throw"; + + public static final String FAIL_PREFIX = "fail:"; + + public static final String FORCE_PREFIX = "force:"; + + public static final String FORCE_KEY = "force"; + + public static final String MERGER_KEY = "merger"; + + public static final String CLUSTER_AVAILABLE_CHECK_KEY = "cluster.availablecheck"; + + public static final boolean DEFAULT_CLUSTER_AVAILABLE_CHECK = true; + + public static final String CLUSTER_STICKY_KEY = "sticky"; + + public static final boolean DEFAULT_CLUSTER_STICKY = false; + + public static final String LAZY_CONNECT_KEY = "lazy"; + + public static final String LAZY_CONNECT_INITIAL_STATE_KEY = "connect.lazy.initial.state"; + + public static final boolean DEFAULT_LAZY_CONNECT_INITIAL_STATE = true; + + public static final String REGISTRY_FILESAVE_SYNC_KEY = "save.file"; + + public static final String REGISTRY_RETRY_PERIOD_KEY = "retry.period"; + + public static final int DEFAULT_REGISTRY_RETRY_PERIOD = 5 * 1000; + + public static final String REGISTRY_RECONNECT_PERIOD_KEY = "reconnect.period"; + + public static final int DEFAULT_REGISTRY_RECONNECT_PERIOD = 3 * 1000; + + public static final String SESSION_TIMEOUT_KEY = "session"; + + public static final int DEFAULT_SESSION_TIMEOUT = 60 * 1000; + + public static final String EXPORT_KEY = "export"; + + public static final String REFER_KEY = "refer"; + + public static final String CALLBACK_SERVICE_KEY = "callback.service.instid"; + + public static final String CALLBACK_INSTANCES_LIMIT_KEY = "callbacks"; + + public static final int DEFAULT_CALLBACK_INSTANCES = 1; + + public static final String CALLBACK_SERVICE_PROXY_KEY = "callback.service.proxy"; + + public static final String IS_CALLBACK_SERVICE = "is_callback_service"; + + public static final String CHANNEL_CALLBACK_KEY = "channel.callback.invokers.key"; + + @Deprecated + public static final String SHUTDOWN_WAIT_SECONDS_KEY = "dubbo.service.shutdown.wait.seconds"; + + public static final String SHUTDOWN_WAIT_KEY = "dubbo.service.shutdown.wait"; + + public static final String IS_SERVER_KEY = "isserver"; + + public static final int DEFAULT_SERVER_SHUTDOWN_TIMEOUT = 10000; + + public static final String ON_CONNECT_KEY = "onconnect"; + + public static final String ON_DISCONNECT_KEY = "ondisconnect"; + + public static final String ON_INVOKE_METHOD_KEY = "oninvoke.method"; + + public static final String ON_RETURN_METHOD_KEY = "onreturn.method"; + + public static final String ON_THROW_METHOD_KEY = "onthrow.method"; + + public static final String ON_INVOKE_INSTANCE_KEY = "oninvoke.instance"; + + public static final String ON_RETURN_INSTANCE_KEY = "onreturn.instance"; + + public static final String ON_THROW_INSTANCE_KEY = "onthrow.instance"; + + public static final String OVERRIDE_PROTOCOL = "override"; + + public static final String PRIORITY_KEY = "priority"; + + public static final String RULE_KEY = "rule"; + + public static final String TYPE_KEY = "type"; + + public static final String RUNTIME_KEY = "runtime"; + + public static final String ROUTER_TYPE_CLEAR = "clean"; + + public static final String DEFAULT_SCRIPT_TYPE_KEY = "javascript"; + + public static final String STUB_EVENT_KEY = "dubbo.stub.event"; + + public static final boolean DEFAULT_STUB_EVENT = false; + + public static final String STUB_EVENT_METHODS_KEY = "dubbo.stub.event.methods"; + + public static final String INVOCATION_NEED_MOCK = "invocation.need.mock"; + + public static final String LOCAL_PROTOCOL = "injvm"; + + public static final String AUTO_ATTACH_INVOCATIONID_KEY = "invocationid.autoattach"; + + public static final String SCOPE_KEY = "scope"; + + public static final String SCOPE_LOCAL = "local"; + + public static final String SCOPE_REMOTE = "remote"; + + public static final String SCOPE_NONE = "none"; + + public static final String RELIABLE_PROTOCOL = "napoli"; + + public static final String TPS_LIMIT_RATE_KEY = "tps"; + + public static final String TPS_LIMIT_INTERVAL_KEY = "tps.interval"; + + public static final long DEFAULT_TPS_LIMIT_INTERVAL = 60 * 1000; + + public static final String DECODE_IN_IO_THREAD_KEY = "decode.in.io"; + + public static final boolean DEFAULT_DECODE_IN_IO_THREAD = true; + + public static final String INPUT_KEY = "input"; + + public static final String OUTPUT_KEY = "output"; + + public static final String EXECUTOR_SERVICE_COMPONENT_KEY = ExecutorService.class.getName(); + + public static final String GENERIC_SERIALIZATION_NATIVE_JAVA = "nativejava"; + + public static final String GENERIC_SERIALIZATION_DEFAULT = "true"; + + public static final String INVOKER_CONNECTED_KEY = "connected"; + + public static final String INVOKER_INSIDE_INVOKERS_KEY = "inside.invokers"; + + public static final String INVOKER_INSIDE_INVOKER_COUNT_KEY = "inside.invoker.count"; + + public static final String CLUSTER_SWITCH_FACTOR = "cluster.switch.factor"; + + public static final String CLUSTER_SWITCH_LOG_ERROR = "cluster.switch.log.error"; + + public static final double DEFAULT_CLUSTER_SWITCH_FACTOR = 2; + + public static final String DISPATHER_KEY = "dispather"; } diff --git a/dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/RpcContext.java b/dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/RpcContext.java index 4c49bc1793..cfc5fb4b8b 100644 --- a/dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/RpcContext.java +++ b/dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/RpcContext.java @@ -37,6 +37,7 @@ import java.util.concurrent.Future; import java.util.concurrent.FutureTask; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; +import java.util.stream.Collectors; @Deprecated public class RpcContext { @@ -320,6 +321,25 @@ public class RpcContext { return isConsumerSide(); } + @Deprecated + public Invoker getInvoker() { + org.apache.dubbo.rpc.Invoker invoker = newRpcContext.getInvoker(); + if (invoker == null) { + return null; + } + return new Invoker.CompatibleInvoker<>(invoker); + } + + @Deprecated + public List> getInvokers() { + List> invokers = newRpcContext.getInvokers(); + if (CollectionUtils.isEmpty(invokers)) { + return Collections.emptyList(); + } + return invokers.stream() + .map(Invoker.CompatibleInvoker::new) + .collect(Collectors.toList()); + } /** * Async invocation. Timeout will be handled even if Future.get() is not called. * diff --git a/dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/RpcException.java b/dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/RpcException.java index 07923c6ee5..1e994019ac 100644 --- a/dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/RpcException.java +++ b/dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/RpcException.java @@ -19,7 +19,7 @@ package com.alibaba.dubbo.rpc; @Deprecated public class RpcException extends org.apache.dubbo.rpc.RpcException { - + public RpcException() { super(); } @@ -51,4 +51,8 @@ public class RpcException extends org.apache.dubbo.rpc.RpcException { public RpcException(int code, Throwable cause) { super(code, cause); } + + public boolean isForbidded() { + return isForbidden(); + } }