You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by "thinkerFenglm (GitHub)" <gi...@apache.org> on 2019/01/23 09:35:03 UTC

[GitHub] [incubator-dubbo] thinkerFenglm opened issue #3319: Tag 路由本地yml配置不生效,需要写到 config-center 才生效。

- [ ] I have searched the [issues](https://github.com/apache/incubator-dubbo/issues) of this repository and believe that this is not a duplicate.
- [ ] I have checked the [FAQ](https://github.com/apache/incubator-dubbo/blob/master/FAQ.md) of this repository and believe that this is not a duplicate.

### Environment

* Dubbo version: 2.7.0-SNAPSHOT
* Operating System version: xxx
* Java version: 1.8

### Steps to reproduce this issue

1. 使用的是社区sample,需要手动把tag路由规则写到 /dubbo/config/governance-appoverride-provider/configurators 或者需要在Dubbo OPS 里写入规则,否则由于初始化的 tagRouterRule 为null 即使通过dubbo.service.tag 属性写入 tag 仍不生效。
2. 需要本地配置的dubbo-routers-condition.yml怎么才可以生效?
3. https://github.com/apache/incubator-dubbo-samples/tree/samples-for-2.7.0-SNAPSHOT/dubbo-samples-governance/dubbo-samples-tagrouter

Pls. provide [GitHub address] to reproduce this issue.

### Expected Result

What do you expected from the above steps?

### Actual Result

What actually happens?

If there is an exception, please attach the exception trace:

```
Just put your stack trace here!
```


[ Full content available at: https://github.com/apache/incubator-dubbo/issues/3319 ]
This message was relayed via gitbox.apache.org for notifications@dubbo.apache.org

[GitHub] [incubator-dubbo] thinkerFenglm commented on issue #3319: Tag 路由本地yml配置不生效,需要写到 config-center 才生效。

Posted by "thinkerFenglm (GitHub)" <gi...@apache.org>.
<dubbo:service tag="{the-tag-you-want}"/>
这种方式由于 org.apache.dubbo.rpc.cluster.router.tag.TagRouter#route这个方法里对 tagRouterRule 做了判断,导致 tag 失效
`if (tagRouterRule == null || !tagRouterRule.isValid() || !tagRouterRule.isEnabled()) {
            return filterUsingStaticTag(invokers, url, invocation);
  }`


[ Full content available at: https://github.com/apache/incubator-dubbo/issues/3319 ]
This message was relayed via gitbox.apache.org for notifications@dubbo.apache.org

[GitHub] [incubator-dubbo] thinkerFenglm commented on issue #3319: Tag 路由本地yml配置不生效,需要写到 config-center 才生效。

Posted by "thinkerFenglm (GitHub)" <gi...@apache.org>.
最新代码已经fix

[ Full content available at: https://github.com/apache/incubator-dubbo/issues/3319 ]
This message was relayed via gitbox.apache.org for notifications@dubbo.apache.org

[GitHub] [incubator-dubbo] thinkerFenglm closed issue #3319: Tag 路由本地yml配置不生效,需要写到 config-center 才生效。

Posted by "thinkerFenglm (GitHub)" <gi...@apache.org>.
[ issue closed by thinkerFenglm ]

[ Full content available at: https://github.com/apache/incubator-dubbo/issues/3319 ]
This message was relayed via gitbox.apache.org for notifications@dubbo.apache.org


[GitHub] [incubator-dubbo] thinkerFenglm commented on issue #3319: Tag 路由本地yml配置不生效,需要写到 config-center 才生效。

Posted by "thinkerFenglm (GitHub)" <gi...@apache.org>.
做如下更改就可以支持
`@Override
    public <T> List<Invoker<T>> route(List<Invoker<T>> invokers, URL url, Invocation invocation) throws RpcException {
        if (CollectionUtils.isEmpty(invokers)) {
            return invokers;
        }
        String tag = StringUtils.isEmpty(invocation.getAttachment(TAG_KEY)) ? url.getParameter(TAG_KEY) :
                invocation.getAttachment(TAG_KEY);
        List<Invoker<T>> result = invokers;

        // if we are requesting for a Provider with a specific tag
        if (StringUtils.isNotEmpty(tag)) {
            if(tagRouterRule == null || !tagRouterRule.isValid() || !tagRouterRule.isEnabled()){
                result = filterInvoker(invokers, invoker -> tag.equals(invoker.getUrl().getParameter(TAG_KEY)));
                if (CollectionUtils.isEmpty(result)){
                    result = filterInvoker(result, invoker -> {
                        String localTag = invoker.getUrl().getParameter(TAG_KEY);
                        return StringUtils.isEmpty(localTag);
                    });
                }
                return result;
            }
            List<String> addresses = tagRouterRule.getTagnameToAddresses().get(tag);
            // filter by dynamic tag group first
            if (CollectionUtils.isNotEmpty(addresses)) {
                result = filterInvoker(invokers, invoker -> addressMatches(invoker.getUrl(), addresses));
                // if result is not null OR it's null but force=true, return result directly
                if (CollectionUtils.isNotEmpty(result) || tagRouterRule.isForce()) {
                    return result;
                }
            } else {
                // dynamic tag group doesn't have any item about the requested app OR it's null after filtered by
                // dynamic tag group but force=false. check static tag
                result = filterInvoker(invokers, invoker -> tag.equals(invoker.getUrl().getParameter(TAG_KEY)));
            }
            // If there's no tagged providers that can match the current tagged request. force.tag is set by default
            // to false, which means it will invoke any providers without a tag unless it's explicitly disallowed.
            if (CollectionUtils.isNotEmpty(result) || isForceUse(invocation)) {
                return result;
            }
            // FAILOVER: return all Providers without any tags.
            else {
                List<Invoker<T>> tmp = filterInvoker(invokers, invoker -> addressNotMatches(invoker.getUrl(),
                        tagRouterRule.getAddresses()));
                return filterInvoker(tmp, invoker -> StringUtils.isEmpty(invoker.getUrl().getParameter(TAG_KEY)));
            }
        } else {
            // List<String> addresses = tagRouterRule.filter(providerApp);
            // return all addresses in dynamic tag group.
            if(tagRouterRule != null && tagRouterRule.isValid() && tagRouterRule.isEnabled()){
                List<String> addresses = tagRouterRule.getAddresses();
                if (CollectionUtils.isNotEmpty(addresses)) {
                    result = filterInvoker(invokers, invoker -> addressNotMatches(invoker.getUrl(), addresses));
                    // 1. all addresses are in dynamic tag group, return empty list.
                    if (CollectionUtils.isEmpty(result)) {
                        return result;
                    }
                    // 2. if there are some addresses that are not in any dynamic tag group, continue to filter using the
                    // static tag group.
                }
            }

            return filterInvoker(result, invoker -> {
                String localTag = invoker.getUrl().getParameter(TAG_KEY);
                return StringUtils.isEmpty(localTag) || (tagRouterRule != null && !tagRouterRule.getTagNames().contains(localTag));
            });
        }
    }`

[ Full content available at: https://github.com/apache/incubator-dubbo/issues/3319 ]
This message was relayed via gitbox.apache.org for notifications@dubbo.apache.org

[GitHub] [incubator-dubbo] chickenlj commented on issue #3319: Tag 路由本地yml配置不生效,需要写到 config-center 才生效。

Posted by "chickenlj (GitHub)" <gi...@apache.org>.
目前本地无法配置dubbo-routers-condition.yml,所有配置规则我们对接的是配置中心,目前支持两种实现:
* Zookeeper
* Apollo
两种均可以通过OPS完成写入。

或许如果未来要支持本地配置的话,那将会是一种 File 类型的配置中心扩展。

[ Full content available at: https://github.com/apache/incubator-dubbo/issues/3319 ]
This message was relayed via gitbox.apache.org for notifications@dubbo.apache.org

[GitHub] [incubator-dubbo] thinkerFenglm commented on issue #3319: Tag 路由本地yml配置不生效,需要写到 config-center 才生效。

Posted by "thinkerFenglm (GitHub)" <gi...@apache.org>.
<dubbo:service tag="{the-tag-you-want}"/>
这种方式由于
org.apache.dubbo.rpc.cluster.router.tag.TagRouter#route
这个方法里对 tagRouterRule 做了判断,导致 tag 失效
`if (tagRouterRule == null || !tagRouterRule.isValid() || !tagRouterRule.isEnabled()) {
            return filterUsingStaticTag(invokers, url, invocation);
        }`


[ Full content available at: https://github.com/apache/incubator-dubbo/issues/3319 ]
This message was relayed via gitbox.apache.org for notifications@dubbo.apache.org

[GitHub] [incubator-dubbo] thinkerFenglm commented on issue #3319: Tag 路由本地yml配置不生效,需要写到 config-center 才生效。

Posted by "thinkerFenglm (GitHub)" <gi...@apache.org>.
最新代码已经fixed

[ Full content available at: https://github.com/apache/incubator-dubbo/issues/3319 ]
This message was relayed via gitbox.apache.org for notifications@dubbo.apache.org

[GitHub] [incubator-dubbo] chickenlj commented on issue #3319: Tag 路由本地yml配置不生效,需要写到 config-center 才生效。

Posted by "chickenlj (GitHub)" <gi...@apache.org>.
在本地,你可以在配置阶段通过XML或者API方式来指定某个服务的tag
```xml
<dubbo:service tag="{the-tag-you-want}"/>
```

```java
ServiceConfig serviceconfig = new ServiceConfig();
serviceConfig.setTag("tag1");
serviceConfig.export();
```

[ Full content available at: https://github.com/apache/incubator-dubbo/issues/3319 ]
This message was relayed via gitbox.apache.org for notifications@dubbo.apache.org

[GitHub] [incubator-dubbo] thinkerFenglm commented on issue #3319: Tag 路由本地yml配置不生效,需要写到 config-center 才生效。

Posted by "thinkerFenglm (GitHub)" <gi...@apache.org>.
<dubbo:service tag="{the-tag-you-want}"/>
这种方式

[ Full content available at: https://github.com/apache/incubator-dubbo/issues/3319 ]
This message was relayed via gitbox.apache.org for notifications@dubbo.apache.org