feat: add cdn addresses log (#1091)

Signed-off-by: Gaius <gaius.qi@gmail.com>
This commit is contained in:
Gaius 2022-02-24 16:44:21 +08:00
parent e6e9d2102a
commit 8bdfeab60b
No known key found for this signature in database
GPG Key ID: 8B4E5D1290FA2FFB
2 changed files with 7 additions and 54 deletions

View File

@ -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
}

View File

@ -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))
})
}
}