feat: add cdn addresses log (#1091)
Signed-off-by: Gaius <gaius.qi@gmail.com>
This commit is contained in:
parent
e6e9d2102a
commit
8bdfeab60b
|
|
@ -213,9 +213,13 @@ func newCDNClient(dynconfig config.DynconfigInterface, hostManager HostManager,
|
||||||
|
|
||||||
// Dynamic config notify function
|
// Dynamic config notify function
|
||||||
func (c *cdnClient) OnNotify(data *config.DynconfigData) {
|
func (c *cdnClient) OnNotify(data *config.DynconfigData) {
|
||||||
ips := getCDNIPs(data.CDNs)
|
var cdns []config.CDN
|
||||||
|
for _, cdn := range data.CDNs {
|
||||||
|
cdns = append(cdns, *cdn)
|
||||||
|
}
|
||||||
|
|
||||||
if reflect.DeepEqual(c.data, data) {
|
if reflect.DeepEqual(c.data, data) {
|
||||||
logger.Infof("cdn addresses deep equal: %v", ips)
|
logger.Infof("cdn addresses deep equal: %#v", cdns)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -239,7 +243,7 @@ func (c *cdnClient) OnNotify(data *config.DynconfigData) {
|
||||||
|
|
||||||
// Update grpc cdn addresses
|
// Update grpc cdn addresses
|
||||||
c.UpdateState(cdnsToNetAddrs(data.CDNs))
|
c.UpdateState(cdnsToNetAddrs(data.CDNs))
|
||||||
logger.Infof("cdn addresses have been updated: %v", ips)
|
logger.Infof("cdn addresses have been updated: %#v", cdns)
|
||||||
}
|
}
|
||||||
|
|
||||||
// cdnsToHosts coverts []*config.CDN to map[string]*Host.
|
// cdnsToHosts coverts []*config.CDN to map[string]*Host.
|
||||||
|
|
@ -318,13 +322,3 @@ func diffCDNs(cx []*config.CDN, cy []*config.CDN) []*config.CDN {
|
||||||
|
|
||||||
return diff
|
return diff
|
||||||
}
|
}
|
||||||
|
|
||||||
// getCDNIPs get ips by []*config.CDN.
|
|
||||||
func getCDNIPs(cdns []*config.CDN) []string {
|
|
||||||
ips := []string{}
|
|
||||||
for _, cdn := range cdns {
|
|
||||||
ips = append(ips, cdn.IP)
|
|
||||||
}
|
|
||||||
|
|
||||||
return ips
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -618,44 +618,3 @@ func TestCDNClient_diffCDNs(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCDNClient_getCDNIPs(t *testing.T) {
|
|
||||||
tests := []struct {
|
|
||||||
name string
|
|
||||||
cdns []*config.CDN
|
|
||||||
expect func(t *testing.T, ips []string)
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
name: "cdns covert to hosts",
|
|
||||||
cdns: []*config.CDN{
|
|
||||||
{
|
|
||||||
ID: 1,
|
|
||||||
Hostname: mockRawCDNHost.HostName,
|
|
||||||
IP: mockRawCDNHost.Ip,
|
|
||||||
Port: mockRawCDNHost.RpcPort,
|
|
||||||
DownloadPort: mockRawCDNHost.DownPort,
|
|
||||||
Location: mockRawCDNHost.Location,
|
|
||||||
IDC: mockRawCDNHost.Idc,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
expect: func(t *testing.T, ips []string) {
|
|
||||||
assert := assert.New(t)
|
|
||||||
assert.Equal(ips[0], mockRawCDNHost.Ip)
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "cdns is empty",
|
|
||||||
cdns: []*config.CDN{},
|
|
||||||
expect: func(t *testing.T, ips []string) {
|
|
||||||
assert := assert.New(t)
|
|
||||||
assert.Equal(len(ips), 0)
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, tc := range tests {
|
|
||||||
t.Run(tc.name, func(t *testing.T) {
|
|
||||||
tc.expect(t, getCDNIPs(tc.cdns))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue