-
Notifications
You must be signed in to change notification settings - Fork 929
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ftr: dynamic tag router #665
Conversation
cluster/router/tag/router_rule.go
Outdated
return r, nil | ||
} | ||
|
||
func (t *RouterRule) init() { | ||
t.addressToTagNames = make(map[string][]string) | ||
t.tagNameToAddresses = make(map[string][]string) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
t.addressToTagNames = make(map[string][]string, 8)
t.tagNameToAddresses = make(map[string][]string, 8)
cluster/router/tag/router_rule.go
Outdated
func (t *RouterRule) getAddresses() []string { | ||
// TODO get all tag addresses | ||
return nil | ||
var result []string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
var result = make([]string, 0, 8 * len(t.Tags))
cluster/router/tag/router_rule.go
Outdated
} | ||
|
||
func (t *RouterRule) getTagNames() []string { | ||
// TODO get all tag names | ||
return nil | ||
var result []string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
var result = make([]string, 0, len(t.Tags))
cluster/router/tag/tag_router.go
Outdated
// TODO address parse | ||
if address == (host + port) { | ||
// TODO ip match | ||
if address == host+":"+port { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
delete "host+":"+port", using net.JoinHostPort(host, port) instead.
logger.Errorf("Get rule fail, config rule{%s}, error{%v}", rule, err) | ||
return | ||
} | ||
if rule != "" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
len>0
Codecov Report
@@ Coverage Diff @@
## develop #665 +/- ##
===========================================
- Coverage 63.72% 63.37% -0.35%
===========================================
Files 237 239 +2
Lines 12295 12598 +303
===========================================
+ Hits 7835 7984 +149
- Misses 3706 3829 +123
- Partials 754 785 +31
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if the comment has resolved you can click resolved
button in the comment.
var ( | ||
result []protocol.Invoker | ||
addresses []string | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The definition can be moved to the top.
And can you break this pile of code into several parts,it is hard for me 😂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agree
} | ||
|
||
pattern = hostAndPort[0] | ||
// TODO 常量化 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
has some easy todo
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should not use Chinese comment in our codes.
@@ -19,32 +19,59 @@ package tag | |||
|
|||
import ( | |||
"context" | |||
"fmt" | |||
"github.com/stretchr/testify/suite" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pkg import problem
@@ -19,32 +19,59 @@ package tag | |||
|
|||
import ( | |||
"context" | |||
"fmt" | |||
"github.com/stretchr/testify/suite" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pkg import problem
var ( | ||
result []protocol.Invoker | ||
addresses []string | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agree
for _, invoker := range invokers { | ||
for _, filter := range filters { | ||
if !filter(invoker) { | ||
continue OUTER |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
break OUTER?
} | ||
|
||
pattern = hostAndPort[0] | ||
// TODO 常量化 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should not use Chinese comment in our codes.
|
||
ipAddress := strings.Split(host, splitCharacter) | ||
for i := 0; i < len(mask); i++ { | ||
if "*" == mask[i] || mask[i] == ipAddress[i] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
u should add comment for every if/else branch to make it easy to understand.
|
||
func getPatternHostAndPort(pattern string, isIpv4 bool) []string { | ||
result := make([]string, 2) | ||
if strings.HasPrefix(pattern, "[") && strings.Contains(pattern, "]:") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add some comments for every if/else branch, pls.
return r, nil | ||
} | ||
|
||
func (t *RouterRule) init() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why create a new func named init? If you create the func ,pls add the comment for it.
} | ||
|
||
func (t *RouterRule) getAddresses() []string { | ||
var result = make([]string, 0, 8*len(t.Tags)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pls add func comment for RouterRule
t.addressToTagNames = make(map[string][]string, 8) | ||
t.tagNameToAddresses = make(map[string][]string, 8) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
t.addressToTagNames = make(map[string][]string, 8) | |
t.tagNameToAddresses = make(map[string][]string, 8) | |
l:=len(t.Tags) | |
t.addressToTagNames = make(map[string][]string, l*2) | |
t.tagNameToAddresses = make(map[string][]string, l) |
} | ||
|
||
func (t *RouterRule) getAddresses() []string { | ||
var result = make([]string, 0, 8*len(t.Tags)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
var result = make([]string, 0, 8*len(t.Tags)) | |
var result = make([]string, 0, 2*len(t.Tags)) |
i think * 2 enough
for _, t := range t.Tags { | ||
if tag == t.Name { | ||
return true | ||
} | ||
} | ||
return false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for _, t := range t.Tags { | |
if tag == t.Name { | |
return true | |
} | |
} | |
return false | |
return len(tagNameToAddresses[tag])>0 |
Why dont you use tagNameToAddresses map[string][]string
?
routerRule := *c.tagRouterRule | ||
return routerRule |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
routerRule := *c.tagRouterRule | |
return routerRule | |
return *c.tagRouterRule |
enough? and i think no need to extract a new function for single scene
if invoker.GetUrl().GetParam(constant.Tagkey, "") == "" { | ||
return true | ||
} | ||
return false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if invoker.GetUrl().GetParam(constant.Tagkey, "") == "" { | |
return true | |
} | |
return false | |
return invoker.GetUrl().GetParam(constant.Tagkey, "") == "" |
if invoker.GetUrl().GetParam(constant.Tagkey, "") == tag { | ||
return true | ||
} | ||
return false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if invoker.GetUrl().GetParam(constant.Tagkey, "") == tag { | |
return true | |
} | |
return false | |
return invoker.GetUrl().GetParam(constant.Tagkey, "") == tag |
if len(addresses) == 0 || !checkAddressMatch(tagRouterRuleCopy.getAddresses(), url.Ip, url.Port) { | ||
return true | ||
} | ||
return false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if len(addresses) == 0 || !checkAddressMatch(tagRouterRuleCopy.getAddresses(), url.Ip, url.Port) { | |
return true | |
} | |
return false | |
return len(addresses) == 0 || !checkAddressMatch(tagRouterRuleCopy.getAddresses(), url.Ip, url.Port) |
if remoting.EventTypeDel == event.ConfigType { | ||
c.tagRouterRule = nil | ||
return | ||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
delete else
if subnet != nil && subnet.Contains(net.ParseIP(host)) { | ||
return true | ||
} | ||
return false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if subnet != nil && subnet.Contains(net.ParseIP(host)) { | |
return true | |
} | |
return false | |
return subnet != nil && subnet.Contains(net.ParseIP(host)) |
) | ||
|
||
import ( | ||
"github.com/dubbogo/go-zookeeper/zk" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
split package
What this PR does:
#593
Which issue(s) this PR fixes:
Fixes #
Special notes for your reviewer:
Does this PR introduce a user-facing change?: