You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by al...@apache.org on 2022/01/05 09:46:11 UTC

[dubbo] branch 3.0 updated: [3.0] Add Router Snapshot Print Support (#9517)

This is an automated email from the ASF dual-hosted git repository.

albumenj pushed a commit to branch 3.0
in repository https://gitbox.apache.org/repos/asf/dubbo.git


The following commit(s) were added to refs/heads/3.0 by this push:
     new 4cc3b28  [3.0] Add Router Snapshot Print Support (#9517)
4cc3b28 is described below

commit 4cc3b28a3e7e76ce18bb0a6d0fd288ab07dae99a
Author: Albumen Kevin <jh...@gmail.com>
AuthorDate: Wed Jan 5 17:45:31 2022 +0800

    [3.0] Add Router Snapshot Print Support (#9517)
    
    * [3.0] Add Router Snapshot
    
    * [3.0] Add ut
    
    * [3.0] Add RouterSnapshotFilter
    
    * [3.0] Add recent log
    
    * opt
---
 .../rpc/cluster/ClusterScopeModelInitializer.java  |  4 +-
 .../org/apache/dubbo/rpc/cluster/RouterChain.java  | 27 ++++++--
 .../rpc/cluster/router/RouterSnapshotFilter.java   | 70 ++++++++++++++++++++
 .../rpc/cluster/router/RouterSnapshotSwitcher.java | 72 ++++++++++++++++++++
 .../cluster/router/mock/MockInvokersSelector.java  | 11 ++++
 .../cluster/router/state/AbstractStateRouter.java  | 11 ++++
 .../dubbo/rpc/cluster/router/state/BitList.java    | 54 +++++++++++----
 .../cluster/router/state/RouterGroupingState.java  | 77 ++++++++++++++++++++++
 .../rpc/cluster/router/state/StateRouter.java      |  7 ++
 .../rpc/cluster/router/state/TailStateRouter.java  |  5 ++
 ...g.apache.dubbo.rpc.cluster.filter.ClusterFilter |  3 +-
 .../cluster/router/RouterSnapshotFilterTest.java   | 73 ++++++++++++++++++++
 .../dubbo/common/constants/CommonConstants.java    |  3 +
 .../qos/command/impl/DisableRouterSnapshot.java    | 59 +++++++++++++++++
 .../qos/command/impl/EnableDetailProfiler.java     |  2 +-
 .../qos/command/impl/EnableRouterSnapshot.java     | 59 +++++++++++++++++
 ...Profiler.java => GetEnabledRouterSnapshot.java} | 20 +++---
 ...lProfiler.java => GetRecentRouterSnapshot.java} | 25 ++++---
 .../dubbo/qos/command/impl/GetRouterSnapshot.java  | 76 +++++++++++++++++++++
 .../org.apache.dubbo.qos.command.BaseCommand       |  5 ++
 .../dubbo/qos/command/util/CommandHelperTest.java  | 10 +++
 .../client/migration/MigrationInvoker.java         |  9 +--
 22 files changed, 637 insertions(+), 45 deletions(-)

diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/ClusterScopeModelInitializer.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/ClusterScopeModelInitializer.java
index 1bc6e92..4b2e01b 100644
--- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/ClusterScopeModelInitializer.java
+++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/ClusterScopeModelInitializer.java
@@ -18,6 +18,7 @@ package org.apache.dubbo.rpc.cluster;
 
 import org.apache.dubbo.common.beans.factory.ScopeBeanFactory;
 import org.apache.dubbo.rpc.cluster.merger.MergerFactory;
+import org.apache.dubbo.rpc.cluster.router.RouterSnapshotSwitcher;
 import org.apache.dubbo.rpc.cluster.router.mesh.route.MeshRuleManager;
 import org.apache.dubbo.rpc.cluster.support.ClusterUtils;
 import org.apache.dubbo.rpc.model.ApplicationModel;
@@ -28,7 +29,8 @@ import org.apache.dubbo.rpc.model.ScopeModelInitializer;
 public class ClusterScopeModelInitializer implements ScopeModelInitializer {
     @Override
     public void initializeFrameworkModel(FrameworkModel frameworkModel) {
-
+        ScopeBeanFactory beanFactory = frameworkModel.getBeanFactory();
+        beanFactory.registerBean(RouterSnapshotSwitcher.class);
     }
 
     @Override
diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/RouterChain.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/RouterChain.java
index ace0765..f3b4f5d 100644
--- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/RouterChain.java
+++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/RouterChain.java
@@ -29,11 +29,13 @@ import org.apache.dubbo.rpc.Invoker;
 import org.apache.dubbo.rpc.RpcContext;
 import org.apache.dubbo.rpc.cluster.router.RouterResult;
 import org.apache.dubbo.rpc.cluster.router.RouterSnapshotNode;
+import org.apache.dubbo.rpc.cluster.router.RouterSnapshotSwitcher;
 import org.apache.dubbo.rpc.cluster.router.state.BitList;
 import org.apache.dubbo.rpc.cluster.router.state.StateRouter;
 import org.apache.dubbo.rpc.cluster.router.state.StateRouterFactory;
 import org.apache.dubbo.rpc.cluster.router.state.TailStateRouter;
 import org.apache.dubbo.rpc.model.ModuleModel;
+import org.apache.dubbo.rpc.model.ScopeModelUtil;
 
 import java.util.ArrayList;
 import java.util.Collections;
@@ -74,6 +76,8 @@ public class RouterChain<T> {
      */
     private final boolean shouldFailFast;
 
+    private final RouterSnapshotSwitcher routerSnapshotSwitcher;
+
     public static <T> RouterChain<T> buildChain(Class<T> interfaceClass, URL url) {
         ModuleModel moduleModel = url.getOrDefaultModuleModel();
 
@@ -95,15 +99,18 @@ public class RouterChain<T> {
 
         boolean shouldFailFast = Boolean.parseBoolean(ConfigurationUtils.getProperty(moduleModel, Constants.SHOULD_FAIL_FAST_KEY, "true"));
 
-        return new RouterChain<>(routers, stateRouters, shouldFailFast);
+        RouterSnapshotSwitcher routerSnapshotSwitcher = ScopeModelUtil.getFrameworkModel(moduleModel).getBeanFactory().getBean(RouterSnapshotSwitcher.class);
+
+        return new RouterChain<>(routers, stateRouters, shouldFailFast, routerSnapshotSwitcher);
     }
 
-    public RouterChain(List<Router> routers, List<StateRouter<T>> stateRouters, boolean shouldFailFast) {
+    public RouterChain(List<Router> routers, List<StateRouter<T>> stateRouters, boolean shouldFailFast, RouterSnapshotSwitcher routerSnapshotSwitcher) {
         initWithRouters(routers);
 
         initWithStateRouters(stateRouters);
 
         this.shouldFailFast = shouldFailFast;
+        this.routerSnapshotSwitcher = routerSnapshotSwitcher;
     }
 
     private void initWithStateRouters(List<StateRouter<T>> stateRouters) {
@@ -282,17 +289,25 @@ public class RouterChain<T> {
         if (snapshotNode.getChainOutputInvokers() == null ||
             snapshotNode.getChainOutputInvokers().isEmpty()) {
             if (logger.isWarnEnabled()) {
-                logger.warn("No provider available after route for the service " + url.getServiceKey()
+                String message = "No provider available after route for the service " + url.getServiceKey()
                     + " from registry " + url.getAddress()
                     + " on the consumer " + NetUtils.getLocalHost()
-                    + " using the dubbo version " + Version.getVersion() + ". Router snapshot is below: \n" + snapshotNode.toString());
+                    + " using the dubbo version " + Version.getVersion() + ". Router snapshot is below: \n" + snapshotNode.toString();
+                if (routerSnapshotSwitcher.isEnable()) {
+                    routerSnapshotSwitcher.setSnapshot(message);
+                }
+                logger.warn(message);
             }
         } else {
             if (logger.isInfoEnabled()) {
-                logger.info("Router snapshot service " + url.getServiceKey()
+                String message = "Router snapshot service " + url.getServiceKey()
                     + " from registry " + url.getAddress()
                     + " on the consumer " + NetUtils.getLocalHost()
-                    + " using the dubbo version " + Version.getVersion() + " is below: \n" + snapshotNode.toString());
+                    + " using the dubbo version " + Version.getVersion() + " is below: \n" + snapshotNode.toString();
+                if (routerSnapshotSwitcher.isEnable()) {
+                    routerSnapshotSwitcher.setSnapshot(message);
+                }
+                logger.info(message);
             }
         }
     }
diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/RouterSnapshotFilter.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/RouterSnapshotFilter.java
new file mode 100644
index 0000000..93f47f8
--- /dev/null
+++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/RouterSnapshotFilter.java
@@ -0,0 +1,70 @@
+/*
+ * 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.router;
+
+import org.apache.dubbo.common.extension.Activate;
+import org.apache.dubbo.common.logger.Logger;
+import org.apache.dubbo.common.logger.LoggerFactory;
+import org.apache.dubbo.rpc.BaseFilter;
+import org.apache.dubbo.rpc.Invocation;
+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.cluster.filter.ClusterFilter;
+import org.apache.dubbo.rpc.model.FrameworkModel;
+
+import static org.apache.dubbo.common.constants.CommonConstants.CONSUMER;
+
+@Activate(group = {CONSUMER})
+public class RouterSnapshotFilter implements ClusterFilter, BaseFilter.Listener {
+
+    private final RouterSnapshotSwitcher switcher;
+    private final static Logger logger = LoggerFactory.getLogger(RouterSnapshotFilter.class);
+
+    public RouterSnapshotFilter(FrameworkModel frameworkModel) {
+        this.switcher = frameworkModel.getBeanFactory().getBean(RouterSnapshotSwitcher.class);
+    }
+
+    @Override
+    public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
+        if (!switcher.isEnable()) {
+            return invoker.invoke(invocation);
+        }
+
+        if (!logger.isInfoEnabled()) {
+            return invoker.invoke(invocation);
+        }
+
+        if (!switcher.isEnable(invocation.getServiceModel().getServiceKey())) {
+            return invoker.invoke(invocation);
+        }
+
+        RpcContext.getServiceContext().setNeedPrintRouterSnapshot(true);
+        return invoker.invoke(invocation);
+    }
+
+    @Override
+    public void onResponse(Result appResponse, Invoker<?> invoker, Invocation invocation) {
+        RpcContext.getServiceContext().setNeedPrintRouterSnapshot(false);
+    }
+
+    @Override
+    public void onError(Throwable t, Invoker<?> invoker, Invocation invocation) {
+        RpcContext.getServiceContext().setNeedPrintRouterSnapshot(false);
+    }
+}
diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/RouterSnapshotSwitcher.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/RouterSnapshotSwitcher.java
new file mode 100644
index 0000000..9ed5416
--- /dev/null
+++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/RouterSnapshotSwitcher.java
@@ -0,0 +1,72 @@
+/*
+ * 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.router;
+
+import org.apache.dubbo.common.utils.ConcurrentHashSet;
+
+import java.util.Collections;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicInteger;
+
+public class RouterSnapshotSwitcher {
+    private volatile boolean enable;
+    private final Set<String> enabledService = new ConcurrentHashSet<>();
+
+    private final static int MAX_LENGTH = 1 << 5; // 2 ^ 5 = 31
+
+    private final AtomicInteger offset = new AtomicInteger(0);
+    private volatile String[] recentSnapshot = new String[MAX_LENGTH];
+
+    public boolean isEnable() {
+        return enable;
+    }
+
+    public synchronized void addEnabledService(String service) {
+        enabledService.add(service);
+        enable = true;
+        recentSnapshot = new String[MAX_LENGTH];
+    }
+
+    public boolean isEnable(String service) {
+        return enabledService.contains(service);
+    }
+
+    public synchronized void removeEnabledService(String service) {
+        enabledService.remove(service);
+        enable = enabledService.size() > 0;
+        recentSnapshot = new String[MAX_LENGTH];
+    }
+
+    public synchronized Set<String> getEnabledService() {
+        return Collections.unmodifiableSet(enabledService);
+    }
+
+    public void setSnapshot(String snapshot) {
+        if (enable) {
+            // lock free
+            recentSnapshot[offset.incrementAndGet() % MAX_LENGTH] = System.currentTimeMillis() + " - " + snapshot;
+        }
+    }
+
+    public String[] cloneSnapshot() {
+        String[] clonedSnapshot = new String[MAX_LENGTH];
+        for (int i = 0; i < MAX_LENGTH; i++) {
+            clonedSnapshot[i] = recentSnapshot[i];
+        }
+        return clonedSnapshot;
+    }
+}
diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/mock/MockInvokersSelector.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/mock/MockInvokersSelector.java
index 4654fd3..b031c00 100644
--- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/mock/MockInvokersSelector.java
+++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/mock/MockInvokersSelector.java
@@ -25,6 +25,10 @@ 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.cluster.router.state.RouterGroupingState;
+
+import java.util.HashMap;
+import java.util.Map;
 
 import static org.apache.dubbo.rpc.cluster.Constants.INVOCATION_NEED_MOCK;
 import static org.apache.dubbo.rpc.cluster.Constants.MOCK_PROTOCOL;
@@ -99,4 +103,11 @@ public class MockInvokersSelector<T> extends AbstractStateRouter<T> {
         normalInvokers = clonedInvokers;
     }
 
+    @Override
+    protected String doBuildSnapshot() {
+        Map<String, BitList<Invoker<T>>> grouping = new HashMap<>();
+        grouping.put("Mocked", mockedInvokers);
+        grouping.put("Normal", normalInvokers);
+        return new RouterGroupingState<>(this.getClass().getSimpleName(), mockedInvokers.size() + normalInvokers.size(), grouping).toString();
+    }
 }
diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/state/AbstractStateRouter.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/state/AbstractStateRouter.java
index 0c10d7a..a81a1ea 100644
--- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/state/AbstractStateRouter.java
+++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/state/AbstractStateRouter.java
@@ -186,4 +186,15 @@ public abstract class AbstractStateRouter<T> implements StateRouter<T> {
     public final void setNextRouter(StateRouter<T> nextRouter) {
         this.nextRouter = nextRouter;
     }
+
+    @Override
+    public final String buildSnapshot() {
+        return doBuildSnapshot() +
+            "            ↓ \n" +
+            nextRouter.buildSnapshot();
+    }
+
+    protected String doBuildSnapshot() {
+        return this.getClass().getSimpleName() + " not support\n";
+    }
 }
diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/state/BitList.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/state/BitList.java
index bb4dd23..055fd4c 100644
--- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/state/BitList.java
+++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/state/BitList.java
@@ -28,25 +28,26 @@ import java.util.LinkedList;
 import java.util.List;
 import java.util.ListIterator;
 import java.util.NoSuchElementException;
+import java.util.concurrent.ThreadLocalRandom;
 
 /**
  * BitList based on BitMap implementation.
  * BitList is consists of `originList`, `rootSet` and `tailList`.
- *
+ * <p>
  * originList: Initial elements of the list. This list will not be changed
- *             in modification actions (expect clear all).
+ * in modification actions (expect clear all).
  * rootSet: A bitMap to store the indexes of originList are still exist.
- *          Most of the modification actions are operated on this bitMap.
+ * Most of the modification actions are operated on this bitMap.
  * tailList: An additional list for BitList. Worked when adding totally new
- *           elements to list. These elements will be appended to the last
- *           of the BitList.
- *
+ * elements to list. These elements will be appended to the last
+ * of the BitList.
+ * <p>
  * An example of BitList:
- *   originList:  A  B  C  D  E             (5 elements)
- *   rootSet:     x  v  x  v  v
- *                0  1  0  1  1             (5 elements)
- *   tailList:                   F  G  H    (3 elements)
- *   resultList:     B     D  E  F  G  H    (6 elements)
+ * originList:  A  B  C  D  E             (5 elements)
+ * rootSet:     x  v  x  v  v
+ * 0  1  0  1  1             (5 elements)
+ * tailList:                   F  G  H    (3 elements)
+ * resultList:     B     D  E  F  G  H    (6 elements)
  *
  * @param <E>
  * @since 3.0
@@ -145,6 +146,31 @@ public class BitList<E> extends AbstractList<E> {
         tailList.add(e);
     }
 
+    public E randomSelectOne() {
+        int originSize = originList.size();
+        int tailSize = tailList != null ? tailList.size() : 0;
+        int totalSize = originSize + tailSize;
+        int cardinality = rootSet.cardinality();
+
+        // example 1 : origin size is 1000, cardinality is 50, rate is 1/20. 20 * 2 = 40 < 50, try random select
+        // example 2 : origin size is 1000, cardinality is 25, rate is 1/40. 40 * 2 = 80 > 50, directly use iterator
+        int rate = originSize / cardinality;
+        if (rate <= cardinality * 2) {
+            int count = rate * 5;
+            for (int i = 0; i < count; i++) {
+                int random = ThreadLocalRandom.current().nextInt(totalSize);
+                if (random < originSize) {
+                    if (rootSet.get(random)) {
+                        return originList.get(random);
+                    }
+                } else {
+                    return tailList.get(random - originSize);
+                }
+            }
+        }
+        return get(ThreadLocalRandom.current().nextInt(cardinality + tailSize));
+    }
+
     @SuppressWarnings("unchecked")
     public static <T> BitList<T> emptyList() {
         return emptyList;
@@ -170,9 +196,9 @@ public class BitList<E> extends AbstractList<E> {
     /**
      * If the element to added is appeared in originList even if it is not in rootSet,
      * directly set its index in rootSet to true. (This may change the order of elements.)
-     *
+     * <p>
      * If the element is not contained in originList, allocate tailList and add to tailList.
-     *
+     * <p>
      * Notice: It is not recommended adding duplicated element.
      */
     @Override
@@ -192,7 +218,7 @@ public class BitList<E> extends AbstractList<E> {
     /**
      * If the element to added is appeared in originList,
      * directly set its index in rootSet to false. (This may change the order of elements.)
-     *
+     * <p>
      * If the element is not contained in originList, try to remove from tailList.
      */
     @Override
diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/state/RouterGroupingState.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/state/RouterGroupingState.java
new file mode 100644
index 0000000..396efa1
--- /dev/null
+++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/state/RouterGroupingState.java
@@ -0,0 +1,77 @@
+/*
+ * 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.router.state;
+
+import org.apache.dubbo.common.URL;
+import org.apache.dubbo.rpc.Invoker;
+
+import java.util.Map;
+import java.util.stream.Collectors;
+
+public class RouterGroupingState<T> {
+    private final String routerName;
+    private final int total;
+    private final Map<String, BitList<Invoker<T>>> grouping;
+
+    public RouterGroupingState(String routerName, int total, Map<String, BitList<Invoker<T>>> grouping) {
+        this.routerName = routerName;
+        this.total = total;
+        this.grouping = grouping;
+    }
+
+    public String getRouterName() {
+        return routerName;
+    }
+
+    public int getTotal() {
+        return total;
+    }
+
+    public Map<String, BitList<Invoker<T>>> getGrouping() {
+        return grouping;
+    }
+
+    @Override
+    public String toString() {
+        StringBuilder stringBuilder = new StringBuilder();
+        stringBuilder.append(routerName)
+            .append(" ")
+            .append(" Total: ")
+            .append(total)
+            .append("\n");
+
+        for (Map.Entry<String, BitList<Invoker<T>>> entry : grouping.entrySet()) {
+            BitList<Invoker<T>> invokers = entry.getValue();
+            stringBuilder.append("[ ")
+                .append(entry.getKey())
+                .append(" -> ")
+                .append(invokers.isEmpty() ?
+                    "Empty" :
+                    invokers.stream()
+                        .limit(5)
+                        .map(Invoker::getUrl)
+                        .map(URL::getAddress)
+                        .collect(Collectors.joining(",")))
+                .append(invokers.size() > 5 ? "..." : "")
+                .append(" (Total: ")
+                .append(invokers.size())
+                .append(") ]")
+                .append("\n");
+        }
+        return stringBuilder.toString();
+    }
+}
diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/state/StateRouter.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/state/StateRouter.java
index 4d7820c..94d82fd 100644
--- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/state/StateRouter.java
+++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/state/StateRouter.java
@@ -84,6 +84,13 @@ public interface StateRouter<T> {
      */
     void notify(BitList<Invoker<T>> invokers);
 
+    /**
+     * Build Router's Current State Snapshot for QoS
+     *
+     * @return Current State
+     */
+    String buildSnapshot();
+
     default void stop() {
         //do nothing by default
     }
diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/state/TailStateRouter.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/state/TailStateRouter.java
index d1cead7..8a0780c 100644
--- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/state/TailStateRouter.java
+++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/state/TailStateRouter.java
@@ -64,4 +64,9 @@ public class TailStateRouter<T> implements StateRouter<T> {
     public void notify(BitList<Invoker<T>> invokers) {
 
     }
+
+    @Override
+    public String buildSnapshot() {
+        return "TailStateRouter End";
+    }
 }
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 8f70d31..bd85b15 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,2 +1,3 @@
 zone-aware=org.apache.dubbo.rpc.cluster.filter.support.ZoneAwareFilter
-consumercontext=org.apache.dubbo.rpc.cluster.filter.support.ConsumerContextFilter
\ No newline at end of file
+consumercontext=org.apache.dubbo.rpc.cluster.filter.support.ConsumerContextFilter
+router-snapshot=org.apache.dubbo.rpc.cluster.router.RouterSnapshotFilter
diff --git a/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/router/RouterSnapshotFilterTest.java b/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/router/RouterSnapshotFilterTest.java
new file mode 100644
index 0000000..1c67051
--- /dev/null
+++ b/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/router/RouterSnapshotFilterTest.java
@@ -0,0 +1,73 @@
+/*
+ * 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.router;
+
+import org.apache.dubbo.rpc.Invocation;
+import org.apache.dubbo.rpc.Invoker;
+import org.apache.dubbo.rpc.RpcContext;
+import org.apache.dubbo.rpc.model.FrameworkModel;
+import org.apache.dubbo.rpc.model.ServiceModel;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.mockito.Mockito;
+
+public class RouterSnapshotFilterTest {
+
+    @Test
+    public void test() {
+        FrameworkModel frameworkModel = new FrameworkModel();
+        RouterSnapshotSwitcher routerSnapshotSwitcher = frameworkModel.getBeanFactory().getBean(RouterSnapshotSwitcher.class);
+        RouterSnapshotFilter routerSnapshotFilter = new RouterSnapshotFilter(frameworkModel);
+
+        Invoker invoker = Mockito.mock(Invoker.class);
+        Invocation invocation = Mockito.mock(Invocation.class);
+        ServiceModel serviceModel = Mockito.mock(ServiceModel.class);
+        Mockito.when(serviceModel.getServiceKey()).thenReturn("TestKey");
+        Mockito.when(invocation.getServiceModel()).thenReturn(serviceModel);
+
+        routerSnapshotFilter.invoke(invoker, invocation);
+        Mockito.verify(invoker, Mockito.times(1)).invoke(invocation);
+        Assertions.assertFalse(RpcContext.getServiceContext().isNeedPrintRouterSnapshot());
+
+        routerSnapshotSwitcher.addEnabledService("Test");
+        routerSnapshotFilter.invoke(invoker, invocation);
+        Assertions.assertFalse(RpcContext.getServiceContext().isNeedPrintRouterSnapshot());
+
+        routerSnapshotSwitcher.removeEnabledService("Test");
+        routerSnapshotFilter.invoke(invoker, invocation);
+        Assertions.assertFalse(RpcContext.getServiceContext().isNeedPrintRouterSnapshot());
+
+        routerSnapshotSwitcher.addEnabledService("TestKey");
+        routerSnapshotFilter.invoke(invoker, invocation);
+        Assertions.assertTrue(RpcContext.getServiceContext().isNeedPrintRouterSnapshot());
+        routerSnapshotFilter.onResponse(null, null, null);
+        Assertions.assertFalse(RpcContext.getServiceContext().isNeedPrintRouterSnapshot());
+
+        routerSnapshotSwitcher.addEnabledService("TestKey");
+        routerSnapshotFilter.invoke(invoker, invocation);
+        Assertions.assertTrue(RpcContext.getServiceContext().isNeedPrintRouterSnapshot());
+        routerSnapshotFilter.onError(null, null, null);
+        Assertions.assertFalse(RpcContext.getServiceContext().isNeedPrintRouterSnapshot());
+
+        routerSnapshotSwitcher.removeEnabledService("TestKey");
+        routerSnapshotFilter.invoke(invoker, invocation);
+        Assertions.assertFalse(RpcContext.getServiceContext().isNeedPrintRouterSnapshot());
+        routerSnapshotFilter.onError(null, null, null);
+        Assertions.assertFalse(RpcContext.getServiceContext().isNeedPrintRouterSnapshot());
+    }
+}
diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/constants/CommonConstants.java b/dubbo-common/src/main/java/org/apache/dubbo/common/constants/CommonConstants.java
index 661a9aa..89504d7 100644
--- a/dubbo-common/src/main/java/org/apache/dubbo/common/constants/CommonConstants.java
+++ b/dubbo-common/src/main/java/org/apache/dubbo/common/constants/CommonConstants.java
@@ -516,4 +516,7 @@ public interface CommonConstants {
 
     String PROVIDER_ASYNC_KEY = "PROVIDER_ASYNC";
 
+    String CURRENT_CLUSTER_INVOKER_KEY = "currentClusterInvoker";
+
+    String ENABLE_ROUTER_SNAPSHOT_PRINT_KEY = "ENABLE_ROUTER_SNAPSHOT_PRINT";
 }
diff --git a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/DisableRouterSnapshot.java b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/DisableRouterSnapshot.java
new file mode 100644
index 0000000..a2f9f2e
--- /dev/null
+++ b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/DisableRouterSnapshot.java
@@ -0,0 +1,59 @@
+/*
+ * 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.qos.command.impl;
+
+import org.apache.dubbo.qos.command.BaseCommand;
+import org.apache.dubbo.qos.command.CommandContext;
+import org.apache.dubbo.qos.command.annotation.Cmd;
+import org.apache.dubbo.rpc.cluster.router.RouterSnapshotSwitcher;
+import org.apache.dubbo.rpc.model.ConsumerModel;
+import org.apache.dubbo.rpc.model.FrameworkModel;
+import org.apache.dubbo.rpc.model.ServiceMetadata;
+
+@Cmd(name = "disableRouterSnapshot",
+    summary = "Disable Dubbo Invocation Level Router Snapshot Print",
+    example = "disableRouterSnapshot xx.xx.xxx.service")
+public class DisableRouterSnapshot implements BaseCommand {
+    private final RouterSnapshotSwitcher routerSnapshotSwitcher;
+    private final FrameworkModel frameworkModel;
+
+    public DisableRouterSnapshot(FrameworkModel frameworkModel) {
+        this.frameworkModel = frameworkModel;
+        this.routerSnapshotSwitcher = frameworkModel.getBeanFactory().getBean(RouterSnapshotSwitcher.class);
+    }
+
+    @Override
+    public String execute(CommandContext commandContext, String[] args) {
+        if (args.length != 1) {
+            return "args count should be 1. example disableRouterSnapshot xx.xx.xxx.service";
+        }
+        String servicePattern = args[0];
+        int count = 0;
+        for (ConsumerModel consumerModel : frameworkModel.getServiceRepository().allConsumerModels()) {
+            try {
+                ServiceMetadata metadata = consumerModel.getServiceMetadata();
+                if (metadata.getServiceKey().matches(servicePattern) || metadata.getDisplayServiceKey().matches(servicePattern)) {
+                    routerSnapshotSwitcher.removeEnabledService(metadata.getServiceKey());
+                    count += 1;
+                }
+            } catch (Throwable ignore) {
+
+            }
+        }
+        return "OK. Found service count: " + count;
+    }
+}
diff --git a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/EnableDetailProfiler.java b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/EnableDetailProfiler.java
index bc1a136..0800163 100644
--- a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/EnableDetailProfiler.java
+++ b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/EnableDetailProfiler.java
@@ -31,6 +31,6 @@ public class EnableDetailProfiler implements BaseCommand {
     public String execute(CommandContext commandContext, String[] args) {
         ProfilerSwitch.enableDetailProfiler();
         logger.warn("Dubbo Invocation Profiler has been enabled.");
-        return "OK";
+        return "OK. This will cause performance degradation, please be careful!";
     }
 }
diff --git a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/EnableRouterSnapshot.java b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/EnableRouterSnapshot.java
new file mode 100644
index 0000000..ef18cd7
--- /dev/null
+++ b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/EnableRouterSnapshot.java
@@ -0,0 +1,59 @@
+/*
+ * 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.qos.command.impl;
+
+import org.apache.dubbo.qos.command.BaseCommand;
+import org.apache.dubbo.qos.command.CommandContext;
+import org.apache.dubbo.qos.command.annotation.Cmd;
+import org.apache.dubbo.rpc.cluster.router.RouterSnapshotSwitcher;
+import org.apache.dubbo.rpc.model.ConsumerModel;
+import org.apache.dubbo.rpc.model.FrameworkModel;
+import org.apache.dubbo.rpc.model.ServiceMetadata;
+
+@Cmd(name = "enableRouterSnapshot",
+    summary = "Enable Dubbo Invocation Level Router Snapshot Print",
+    example = "enableRouterSnapshot xx.xx.xxx.service")
+public class EnableRouterSnapshot implements BaseCommand {
+    private final RouterSnapshotSwitcher routerSnapshotSwitcher;
+    private final FrameworkModel frameworkModel;
+
+    public EnableRouterSnapshot(FrameworkModel frameworkModel) {
+        this.frameworkModel = frameworkModel;
+        this.routerSnapshotSwitcher = frameworkModel.getBeanFactory().getBean(RouterSnapshotSwitcher.class);
+    }
+
+    @Override
+    public String execute(CommandContext commandContext, String[] args) {
+        if (args.length != 1) {
+            return "args count should be 1. example enableRouterSnapshot xx.xx.xxx.service";
+        }
+        String servicePattern = args[0];
+        int count = 0;
+        for (ConsumerModel consumerModel : frameworkModel.getServiceRepository().allConsumerModels()) {
+            try {
+                ServiceMetadata metadata = consumerModel.getServiceMetadata();
+                if (metadata.getServiceKey().matches(servicePattern) || metadata.getDisplayServiceKey().matches(servicePattern)) {
+                    routerSnapshotSwitcher.addEnabledService(metadata.getServiceKey());
+                    count += 1;
+                }
+            } catch (Throwable ignore) {
+
+            }
+        }
+        return "OK. Found service count: " + count + ". This will cause performance degradation, please be careful!";
+    }
+}
diff --git a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/EnableDetailProfiler.java b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/GetEnabledRouterSnapshot.java
similarity index 63%
copy from dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/EnableDetailProfiler.java
copy to dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/GetEnabledRouterSnapshot.java
index bc1a136..3f705ba 100644
--- a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/EnableDetailProfiler.java
+++ b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/GetEnabledRouterSnapshot.java
@@ -16,21 +16,23 @@
  */
 package org.apache.dubbo.qos.command.impl;
 
-import org.apache.dubbo.common.logger.Logger;
-import org.apache.dubbo.common.logger.LoggerFactory;
-import org.apache.dubbo.common.profiler.ProfilerSwitch;
 import org.apache.dubbo.qos.command.BaseCommand;
 import org.apache.dubbo.qos.command.CommandContext;
 import org.apache.dubbo.qos.command.annotation.Cmd;
+import org.apache.dubbo.rpc.cluster.router.RouterSnapshotSwitcher;
+import org.apache.dubbo.rpc.model.FrameworkModel;
 
-@Cmd(name = "enableDetailProfiler", summary = "Enable Dubbo Invocation Profiler.")
-public class EnableDetailProfiler implements BaseCommand {
-    private final static Logger logger = LoggerFactory.getLogger(EnableDetailProfiler.class);
+@Cmd(name = "getEnabledRouterSnapshot",
+    summary = "Get enabled Dubbo invocation level router snapshot print service list")
+public class GetEnabledRouterSnapshot implements BaseCommand {
+    private final RouterSnapshotSwitcher routerSnapshotSwitcher;
+
+    public GetEnabledRouterSnapshot(FrameworkModel frameworkModel) {
+        this.routerSnapshotSwitcher = frameworkModel.getBeanFactory().getBean(RouterSnapshotSwitcher.class);
+    }
 
     @Override
     public String execute(CommandContext commandContext, String[] args) {
-        ProfilerSwitch.enableDetailProfiler();
-        logger.warn("Dubbo Invocation Profiler has been enabled.");
-        return "OK";
+        return String.join("\n", routerSnapshotSwitcher.getEnabledService());
     }
 }
diff --git a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/EnableDetailProfiler.java b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/GetRecentRouterSnapshot.java
similarity index 59%
copy from dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/EnableDetailProfiler.java
copy to dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/GetRecentRouterSnapshot.java
index bc1a136..5d14a1c 100644
--- a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/EnableDetailProfiler.java
+++ b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/GetRecentRouterSnapshot.java
@@ -16,21 +16,28 @@
  */
 package org.apache.dubbo.qos.command.impl;
 
-import org.apache.dubbo.common.logger.Logger;
-import org.apache.dubbo.common.logger.LoggerFactory;
-import org.apache.dubbo.common.profiler.ProfilerSwitch;
 import org.apache.dubbo.qos.command.BaseCommand;
 import org.apache.dubbo.qos.command.CommandContext;
 import org.apache.dubbo.qos.command.annotation.Cmd;
+import org.apache.dubbo.rpc.cluster.router.RouterSnapshotSwitcher;
+import org.apache.dubbo.rpc.model.FrameworkModel;
 
-@Cmd(name = "enableDetailProfiler", summary = "Enable Dubbo Invocation Profiler.")
-public class EnableDetailProfiler implements BaseCommand {
-    private final static Logger logger = LoggerFactory.getLogger(EnableDetailProfiler.class);
+import java.util.Arrays;
+import java.util.Objects;
+import java.util.stream.Collectors;
+
+@Cmd(name = "getRecentRouterSnapshot",
+    summary = "Get recent (32) router snapshot message")
+public class GetRecentRouterSnapshot implements BaseCommand {
+
+    private final RouterSnapshotSwitcher routerSnapshotSwitcher;
+
+    public GetRecentRouterSnapshot(FrameworkModel frameworkModel) {
+        this.routerSnapshotSwitcher = frameworkModel.getBeanFactory().getBean(RouterSnapshotSwitcher.class);
+    }
 
     @Override
     public String execute(CommandContext commandContext, String[] args) {
-        ProfilerSwitch.enableDetailProfiler();
-        logger.warn("Dubbo Invocation Profiler has been enabled.");
-        return "OK";
+        return Arrays.stream(routerSnapshotSwitcher.cloneSnapshot()).filter(Objects::nonNull).sorted().collect(Collectors.joining("\n\n"));
     }
 }
diff --git a/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/GetRouterSnapshot.java b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/GetRouterSnapshot.java
new file mode 100644
index 0000000..b827da6
--- /dev/null
+++ b/dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/GetRouterSnapshot.java
@@ -0,0 +1,76 @@
+/*
+ * 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.qos.command.impl;
+
+import org.apache.dubbo.common.constants.CommonConstants;
+import org.apache.dubbo.qos.command.BaseCommand;
+import org.apache.dubbo.qos.command.CommandContext;
+import org.apache.dubbo.qos.command.annotation.Cmd;
+import org.apache.dubbo.registry.Registry;
+import org.apache.dubbo.registry.client.migration.MigrationInvoker;
+import org.apache.dubbo.rpc.cluster.Directory;
+import org.apache.dubbo.rpc.cluster.directory.AbstractDirectory;
+import org.apache.dubbo.rpc.cluster.router.state.StateRouter;
+import org.apache.dubbo.rpc.model.ConsumerModel;
+import org.apache.dubbo.rpc.model.FrameworkModel;
+import org.apache.dubbo.rpc.model.ServiceMetadata;
+
+import java.util.Map;
+
+@Cmd(name = "getRouterSnapshot", summary = "Get State Router Snapshot.", example = "getRouterSnapshot xx.xx.xxx.service")
+public class GetRouterSnapshot implements BaseCommand {
+    private FrameworkModel frameworkModel;
+
+    public GetRouterSnapshot(FrameworkModel frameworkModel) {
+        this.frameworkModel = frameworkModel;
+    }
+
+    @Override
+    public String execute(CommandContext commandContext, String[] args) {
+        if (args.length != 1) {
+            return "args count should be 1. example getRouterSnapshot xx.xx.xxx.service";
+        }
+        String servicePattern = args[0];
+        StringBuilder stringBuilder = new StringBuilder();
+        for (ConsumerModel consumerModel : frameworkModel.getServiceRepository().allConsumerModels()) {
+            try {
+                ServiceMetadata metadata = consumerModel.getServiceMetadata();
+                if (metadata.getServiceKey().matches(servicePattern) || metadata.getDisplayServiceKey().matches(servicePattern)) {
+                    Object object = metadata.getAttribute(CommonConstants.CURRENT_CLUSTER_INVOKER_KEY);
+                    Map<Registry, MigrationInvoker<?>> invokerMap;
+                    if (object instanceof Map) {
+                        invokerMap = (Map<Registry, MigrationInvoker<?>>) object;
+                        for (Map.Entry<Registry, MigrationInvoker<?>> invokerEntry : invokerMap.entrySet()) {
+                            Directory<?> directory = invokerEntry.getValue().getDirectory();
+                            StateRouter<?> headStateRouter = directory.getRouterChain().getHeadStateRouter();
+                            stringBuilder.append(metadata.getServiceKey()).append("@").append(Integer.toHexString(System.identityHashCode(metadata)))
+                                .append("\n")
+                                .append("[ All Invokers:").append(directory.getAllInvokers().size()).append(" ] ")
+                                .append("[ Valid Invokers: ").append(((AbstractDirectory<?>)directory).getValidInvokers().size()).append(" ]\n")
+                                .append("\n")
+                                .append(headStateRouter.buildSnapshot())
+                                .append("\n\n");
+                        }
+                    }
+                }
+            } catch (Throwable ignore) {
+
+            }
+        }
+        return stringBuilder.toString();
+    }
+}
diff --git a/dubbo-plugin/dubbo-qos/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.qos.command.BaseCommand b/dubbo-plugin/dubbo-qos/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.qos.command.BaseCommand
index d00c59c..2e68fed 100644
--- a/dubbo-plugin/dubbo-qos/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.qos.command.BaseCommand
+++ b/dubbo-plugin/dubbo-qos/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.qos.command.BaseCommand
@@ -24,3 +24,8 @@ disableDetailProfiler=org.apache.dubbo.qos.command.impl.DisableDetailProfiler
 enableSimpleProfiler=org.apache.dubbo.qos.command.impl.EnableSimpleProfiler
 disableSimpleProfiler=org.apache.dubbo.qos.command.impl.DisableSimpleProfiler
 setProfilerWarnPercent=org.apache.dubbo.qos.command.impl.SetProfilerWarnPercent
+getRouterSnapshot=org.apache.dubbo.qos.command.impl.GetRouterSnapshot
+getEnabledRouterSnapshot=org.apache.dubbo.qos.command.impl.GetEnabledRouterSnapshot
+enableRouterSnapshot=org.apache.dubbo.qos.command.impl.EnableRouterSnapshot
+disableRouterSnapshot=org.apache.dubbo.qos.command.impl.DisableRouterSnapshot
+getRecentRouterSnapshot=org.apache.dubbo.qos.command.impl.GetRecentRouterSnapshot
diff --git a/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/command/util/CommandHelperTest.java b/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/command/util/CommandHelperTest.java
index e765213..ad95a74 100644
--- a/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/command/util/CommandHelperTest.java
+++ b/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/command/util/CommandHelperTest.java
@@ -20,9 +20,14 @@ import org.apache.dubbo.qos.command.GreetingCommand;
 import org.apache.dubbo.qos.command.impl.ChangeTelnet;
 import org.apache.dubbo.qos.command.impl.CountTelnet;
 import org.apache.dubbo.qos.command.impl.DisableDetailProfiler;
+import org.apache.dubbo.qos.command.impl.DisableRouterSnapshot;
 import org.apache.dubbo.qos.command.impl.DisableSimpleProfiler;
 import org.apache.dubbo.qos.command.impl.EnableDetailProfiler;
+import org.apache.dubbo.qos.command.impl.EnableRouterSnapshot;
 import org.apache.dubbo.qos.command.impl.EnableSimpleProfiler;
+import org.apache.dubbo.qos.command.impl.GetEnabledRouterSnapshot;
+import org.apache.dubbo.qos.command.impl.GetRecentRouterSnapshot;
+import org.apache.dubbo.qos.command.impl.GetRouterSnapshot;
 import org.apache.dubbo.qos.command.impl.Help;
 import org.apache.dubbo.qos.command.impl.InvokeTelnet;
 import org.apache.dubbo.qos.command.impl.Live;
@@ -99,6 +104,11 @@ public class CommandHelperTest {
         expectedClasses.add(EnableSimpleProfiler.class);
         expectedClasses.add(DisableSimpleProfiler.class);
         expectedClasses.add(SetProfilerWarnPercent.class);
+        expectedClasses.add(GetRouterSnapshot.class);
+        expectedClasses.add(GetEnabledRouterSnapshot.class);
+        expectedClasses.add(EnableRouterSnapshot.class);
+        expectedClasses.add(DisableRouterSnapshot.class);
+        expectedClasses.add(GetRecentRouterSnapshot.class);
         assertThat(classes, containsInAnyOrder(expectedClasses.toArray(new Class<?>[0])));
     }
 
diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/migration/MigrationInvoker.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/migration/MigrationInvoker.java
index 0bb2286..2c48684 100644
--- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/migration/MigrationInvoker.java
+++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/migration/MigrationInvoker.java
@@ -17,6 +17,7 @@
 package org.apache.dubbo.registry.client.migration;
 
 import org.apache.dubbo.common.URL;
+import org.apache.dubbo.common.constants.CommonConstants;
 import org.apache.dubbo.common.logger.Logger;
 import org.apache.dubbo.common.logger.LoggerFactory;
 import org.apache.dubbo.common.status.reporter.FrameworkStatusReportService;
@@ -95,7 +96,7 @@ public class MigrationInvoker<T> implements MigrationClusterInvoker<T> {
         this.reportService = consumerUrl.getOrDefaultApplicationModel().getBeanFactory().getBean(FrameworkStatusReportService.class);
 
         if (consumerModel != null) {
-            Object object = consumerModel.getServiceMetadata().getAttribute("currentClusterInvoker");
+            Object object = consumerModel.getServiceMetadata().getAttribute(CommonConstants.CURRENT_CLUSTER_INVOKER_KEY);
             Map<Registry, MigrationInvoker<?>> invokerMap;
             if (object instanceof Map) {
                 invokerMap = (Map<Registry, MigrationInvoker<?>>) object;
@@ -103,7 +104,7 @@ public class MigrationInvoker<T> implements MigrationClusterInvoker<T> {
                 invokerMap = new ConcurrentHashMap<>();
             }
             invokerMap.put(registry, this);
-            consumerModel.getServiceMetadata().addAttribute("currentClusterInvoker", invokerMap);
+            consumerModel.getServiceMetadata().addAttribute(CommonConstants.CURRENT_CLUSTER_INVOKER_KEY, invokerMap);
         }
     }
 
@@ -319,13 +320,13 @@ public class MigrationInvoker<T> implements MigrationClusterInvoker<T> {
             serviceDiscoveryInvoker.destroy();
         }
         if (consumerModel != null) {
-            Object object = consumerModel.getServiceMetadata().getAttribute("currentClusterInvoker");
+            Object object = consumerModel.getServiceMetadata().getAttribute(CommonConstants.CURRENT_CLUSTER_INVOKER_KEY);
             Map<Registry, MigrationInvoker<?>> invokerMap;
             if (object instanceof Map) {
                 invokerMap = (Map<Registry, MigrationInvoker<?>>) object;
                 invokerMap.remove(registry);
                 if (invokerMap.isEmpty()) {
-                    consumerModel.getServiceMetadata().getAttributeMap().remove("currentClusterInvoker");
+                    consumerModel.getServiceMetadata().getAttributeMap().remove(CommonConstants.CURRENT_CLUSTER_INVOKER_KEY);
                 }
             }
         }