apache / dubbo

The java implementation of Apache Dubbo. An RPC and microservice framework.
https://dubbo.apache.org/
Apache License 2.0
40.51k stars 26.43k forks source link

Make it easily to figure out why no provider available #9826

Open AlbumenJ opened 2 years ago

AlbumenJ commented 2 years ago

When Dubbo process the request, Dubbo need to find out some providers to invoke. However, for various reasons (null addresses, routers...) exceptions that no provider is available always occur.

Is there anything we can do to make it easier for developers to figure out why it happened?

AlbumenJ commented 2 years ago

In Dubbo 3.0.6, there is a log when empty provider happend.

org.apache.dubbo.rpc.cluster.directory.AbstractDirectory#list
            logger.warn("No provider available after connectivity filter for the service " + getConsumerUrl().getServiceKey()
                + " All validInvokers' size: " + validInvokers.size()
                + " All routed invokers' size: " + routedResult.size()
                + " All invokers' size: " + invokers.size()
                + " from registry " + getUrl().getAddress()
                + " on the consumer " + NetUtils.getLocalHost()
                + " using the dubbo version " + Version.getVersion() + ".");

All validInvokers means all of the invokers from registry except those unconnectable invokers. All routed invokers means all of the invokers being selected in routers. All invokers means all of the invokers from registry.

AlbumenJ commented 2 years ago

RouterSnapshot in org.apache.dubbo.rpc.cluster.RouterChain#logRouterSnapshot can print router status if router's result is empty.

It would be like

[ Parent (Input: 2) (Current Node Output: 2) (Chain Node Output: 0) ] Input: 192.168.31.105:20880,192.168.31.105:20881 -> Chain Node Output: Empty
  [ MockInvokersSelector (Input: 2) (Current Node Output: 2) (Chain Node Output: 0) Router message: invocation.need.mock not set. Return normal Invokers. ] Current Node Output: 192.168.31.105:20880,192.168.31.105:20881
    [ StandardMeshRuleRouter (Input: 2) (Current Node Output: 2) (Chain Node Output: 0) Router message: MeshRuleCache has not been built. Skip route. ] Current Node Output: 192.168.31.105:20880,192.168.31.105:20881
      [ TagStateRouter (Input: 2) (Current Node Output: 0) (Chain Node Output: 0) Router message: FAILOVER: return all Providers without any tags ] Current Node Output: Empty
        [ ServiceRouter (Input: 0) (Current Node Output: 0) (Chain Node Output: 0) Router message: Directly return. Reason: Invokers from previous router is empty or conditionRouters is empty. ] Current Node Output: Empty
          [ AppStateRouter (Input: 0) (Current Node Output: 0) (Chain Node Output: 0) Router message: Directly return. Reason: Invokers from previous router is empty or conditionRouters is empty. ] Current Node Output: Empty, dubbo version: 3.0.6-SNAPSHOT, current host: 192.168.31.105

Also, RpcContext.getServiceContext().setNeedPrintRouterSnapshot(true);(or with telnet command) can enable router snapshot print switch for once.

[ Parent (Input: 2) (Current Node Output: 2) (Chain Node Output: 1) ] Input: 192.168.31.105:20880,192.168.31.105:20881 -> Chain Node Output: 192.168.31.105:20881
  [ MockInvokersSelector (Input: 2) (Current Node Output: 2) (Chain Node Output: 1) Router message: invocation.need.mock not set. Return normal Invokers. ] Current Node Output: 192.168.31.105:20880,192.168.31.105:20881
    [ StandardMeshRuleRouter (Input: 2) (Current Node Output: 2) (Chain Node Output: 1) Router message: MeshRuleCache has not been built. Skip route. ] Current Node Output: 192.168.31.105:20880,192.168.31.105:20881
      [ TagStateRouter (Input: 2) (Current Node Output: 1) (Chain Node Output: 1) Router message: Use tag tag1 to route. Reason: result is not null OR it's null but force=true ] Current Node Output: 192.168.31.105:20881
        [ ServiceRouter (Input: 1) (Current Node Output: 1) (Chain Node Output: 1) Router message: Directly return. Reason: Invokers from previous router is empty or conditionRouters is empty. ] Current Node Output: 192.168.31.105:20881
          [ AppStateRouter (Input: 1) (Current Node Output: 1) (Chain Node Output: 1) Router message: Directly return. Reason: Invokers from previous router is empty or conditionRouters is empty. ] Current Node Output: 192.168.31.105:20881, dubbo version: 3.0.6-SNAPSHOT, current host: 192.168.31.105
24kpure commented 2 years ago

It's very useful. I spent a lot of time in finguring out these problems some days ago,for my dubbo version is 2.7.x.

guohao commented 2 years ago

Great feature!