You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by GitBox <gi...@apache.org> on 2020/08/13 19:46:51 UTC

[GitHub] [dubbo-go] AlexStocks commented on a change in pull request #703: Ftr: add dynamic tag router

AlexStocks commented on a change in pull request #703:
URL: https://github.com/apache/dubbo-go/pull/703#discussion_r470206063



##########
File path: cluster/router/tag/tag_router.go
##########
@@ -93,10 +204,81 @@ func filterUsingStaticTag(invokers []protocol.Invoker, url *common.URL, invocati
 	return invokers
 }
 
+// filterInvokersWithTag gets a list of invoker using dynamic route with tag
+func filterInvokersWithTag(invokers []protocol.Invoker, url *common.URL, invocation protocol.Invocation, tagRouterRule RouterRule, tag string) []protocol.Invoker {
+	var (
+		result    []protocol.Invoker
+		addresses []string
+	)
+	addresses, _ = tagRouterRule.getTagNameToAddresses()[tag]
+	// filter by dynamic tag group first
+	if len(addresses) > 0 {
+		filterAddressMatches := func(invoker protocol.Invoker) bool {
+			url := invoker.GetUrl()
+			return len(addresses) > 0 && checkAddressMatch(addresses, url.Ip, url.Port)
+		}
+		result = filterInvoker(invokers, filterAddressMatches)
+		if len(result) > 0 || tagRouterRule.Force {
+			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
+		filter := func(invoker protocol.Invoker) bool {
+			return invoker.GetUrl().GetParam(constant.Tagkey, "") == tag
+		}
+		result = filterInvoker(invokers, filter)
+	}
+	// 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 len(result) > 0 || isForceUseTag(url, invocation) {
+		return result
+	} else {

Review comment:
       pls delete the else.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org