Commit b42bc5a0 authored by vrg0's avatar vrg0

调整Client IP匹配策略

parent 3a0e8d74
...@@ -11,6 +11,7 @@ type PathNode struct { ...@@ -11,6 +11,7 @@ type PathNode struct {
ServiceName string ServiceName string
Path string Path string
RemoteServiceMap map[string]struct{} RemoteServiceMap map[string]struct{}
RemoteIpMap map[string]struct{}
} }
func NewPathNode(path string, serviceName string) PathNode { func NewPathNode(path string, serviceName string) PathNode {
...@@ -18,6 +19,7 @@ func NewPathNode(path string, serviceName string) PathNode { ...@@ -18,6 +19,7 @@ func NewPathNode(path string, serviceName string) PathNode {
Path: path, Path: path,
ServiceName: serviceName, ServiceName: serviceName,
RemoteServiceMap: make(map[string]struct{}), RemoteServiceMap: make(map[string]struct{}),
RemoteIpMap: make(map[string]struct{}),
} }
} }
...@@ -75,7 +77,7 @@ func NewStatistics() *Statistics { ...@@ -75,7 +77,7 @@ func NewStatistics() *Statistics {
func (s *Statistics) addServer(point TraceMsg) { func (s *Statistics) addServer(point TraceMsg) {
local := point.LocalEndpoint local := point.LocalEndpoint
//remote := point.RemoteEndpoint remote := point.RemoteEndpoint
tag := point.Tags tag := point.Tags
if _, ok := s.ServiceMap[local.ServiceName]; !ok { if _, ok := s.ServiceMap[local.ServiceName]; !ok {
...@@ -88,30 +90,27 @@ func (s *Statistics) addServer(point TraceMsg) { ...@@ -88,30 +90,27 @@ func (s *Statistics) addServer(point TraceMsg) {
path := strings.ToLower(point.Name) path := strings.ToLower(point.Name)
if _, ok := methodMap[strings.ToLower(point.Name)]; ok { if _, ok := methodMap[strings.ToLower(point.Name)]; ok {
path = strings.ToLower(tag.HttpMethod + "-" + tag.HttpPath) path = strings.ToLower(tag.HttpMethod + " " + tag.HttpPath)
} }
_, ok := s.ServiceMap[local.ServiceName].PathMap[path] _, ok := s.ServiceMap[local.ServiceName].PathMap[path]
if !ok { if !ok {
s.ServiceMap[local.ServiceName].PathMap[path] = NewPathNode(path, local.ServiceName) s.ServiceMap[local.ServiceName].PathMap[path] = NewPathNode(path, local.ServiceName)
} }
s.ServiceMap[local.ServiceName].PathMap[path].RemoteIpMap[remote.Ipv4] = struct{}{}
} }
func (s *Statistics) addClient(point TraceMsg) { func (s *Statistics) addClient(point TraceMsg) {
local := point.LocalEndpoint local := point.LocalEndpoint
remote := point.RemoteEndpoint
tag := point.Tags tag := point.Tags
for sName := range s.ServiceMap {
for ip := range s.ServiceMap[sName].IpMap {
if ip == remote.Ipv4 {
//添加服务
path := strings.ToLower(point.Name) path := strings.ToLower(point.Name)
if _, ok := methodMap[strings.ToLower(point.Name)]; ok { if _, ok := methodMap[strings.ToLower(point.Name)]; ok {
path = strings.ToLower(tag.HttpMethod + "-" + tag.HttpPath) path = strings.ToLower(tag.HttpMethod + " " + tag.HttpPath)
}
if _, ok := s.ServiceMap[sName].PathMap[path]; !ok {
s.ServiceMap[sName].PathMap[path] = NewPathNode(path, s.ServiceMap[sName].ServiceName)
} }
for sName := range s.ServiceMap {
if _, ok := s.ServiceMap[sName].PathMap[path]; ok {
if _, ok := s.ServiceMap[sName].PathMap[path].RemoteIpMap[local.Ipv4]; ok {
s.ServiceMap[sName].PathMap[path].RemoteServiceMap[local.ServiceName] = struct{}{} s.ServiceMap[sName].PathMap[path].RemoteServiceMap[local.ServiceName] = struct{}{}
} }
} }
...@@ -131,25 +130,3 @@ func (s *Statistics) AddNode(point TraceMsg) { ...@@ -131,25 +130,3 @@ func (s *Statistics) AddNode(point TraceMsg) {
//位置类型,不处理 //位置类型,不处理
} }
} }
/*
type PathNode struct {
ServiceName string
Path string
SrcServiceList map[string]struct{}
SrcNodeIp map[string]struct{}
}
type Statistics struct {
PathMap map[string]PathNode
lock *sync.Mutex
}
func NewStatistics() *Statistics {
return &Statistics{
PathMap: make(map[string]PathNode),
lock: new(sync.Mutex),
}
}
*/
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment