Skip to content

Commit 77de27f

Browse files
committed
add new telemetry logs for debugging
1 parent 0451318 commit 77de27f

File tree

8 files changed

+23
-17
lines changed

8 files changed

+23
-17
lines changed

cni/network/invoker_cns.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ func (invoker *CNSIPAMInvoker) Add(addConfig IPAMAddConfig) (IPAMAddResult, erro
142142
}
143143
}
144144

145+
telemetry.SendEvent(fmt.Sprintf("Received from cns: %+v", response.PodIPInfo))
146+
145147
addResult := IPAMAddResult{interfaceInfo: make(map[string]network.InterfaceInfo)}
146148
numInterfacesWithDefaultRoutes := 0
147149

cni/network/multitenancy.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ func (m *Multitenancy) getNetworkContainersInternal(
267267
}
268268

269269
logger.Info("Network config received from cns", zap.Any("nconfig", ncConfigs))
270+
telemetry.SendEvent(fmt.Sprintf("Network config received from cns: %+v", ncConfigs))
270271

271272
subnetPrefixes := []net.IPNet{}
272273
for i := 0; i < len(ncConfigs); i++ {

cni/network/network.go

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,6 @@ func (plugin *NetPlugin) addIpamInvoker(ipamAddConfig IPAMAddConfig) (IPAMAddRes
326326
if err != nil {
327327
return IPAMAddResult{}, errors.Wrap(err, "failed to add ipam invoker")
328328
}
329-
telemetry.SendEvent(fmt.Sprintf("Allocated IPAddress from ipam interface: %+v", ipamAddResult.PrettyString()))
330329
return ipamAddResult, nil
331330
}
332331

@@ -432,7 +431,7 @@ func (plugin *NetPlugin) Add(args *cniSkel.CmdArgs) error {
432431
zap.Any("IPs", cniResult.IPs),
433432
zap.Error(log.NewErrorWithoutStackTrace(err)))
434433

435-
telemetry.SendEvent(fmt.Sprintf("ADD command completed for ipamAddResult verbose: %s epInfos: %s error: %v ", ipamAddResult.PrettyString(), network.FormatStructPointers(epInfos), err))
434+
telemetry.SendEvent(fmt.Sprintf("ADD command completed with [ipamAddResult]: %s [epInfos]: %s [error]: %v ", ipamAddResult.PrettyString(), network.FormatStructPointers(epInfos), err))
436435
}()
437436

438437
ipamAddResult = IPAMAddResult{interfaceInfo: make(map[string]network.InterfaceInfo)}
@@ -538,15 +537,9 @@ func (plugin *NetPlugin) Add(args *cniSkel.CmdArgs) error {
538537
if err != nil {
539538
return fmt.Errorf("IPAM Invoker Add failed with error: %w", err)
540539
}
541-
542-
// TODO: This proably needs to be changed as we return all interfaces...
543-
// sendEvent(plugin, fmt.Sprintf("Allocated IPAddress from ipam DefaultInterface: %+v, SecondaryInterfaces: %+v", ipamAddResult.interfaceInfo[ifIndex], ipamAddResult.interfaceInfo))
544540
}
545541

546542
policies := cni.GetPoliciesFromNwCfg(nwCfg.AdditionalArgs)
547-
// moved to addIpamInvoker
548-
// sendEvent(plugin, fmt.Sprintf("Allocated IPAddress from ipam interface: %+v", ipamAddResult.PrettyString()))
549-
550543
defer func() { //nolint:gocritic
551544
if err != nil {
552545
// for swift v1 multi-tenancies scenario, CNI is not supposed to invoke CNS for cleaning Ips
@@ -980,6 +973,7 @@ func (plugin *NetPlugin) Delete(args *cniSkel.CmdArgs) error {
980973
logger.Info("DEL command completed",
981974
zap.String("pod", k8sPodName),
982975
zap.Error(log.NewErrorWithoutStackTrace(err)))
976+
telemetry.SendEvent(fmt.Sprintf("DEL command completed: [released ip]: %+v [podname]: %s [namespace]: %s [error]: %v", nwCfg.IPAM.Address, k8sPodName, k8sNamespace, err))
983977
}()
984978

985979
// Parse network configuration from stdin.
@@ -1096,13 +1090,13 @@ func (plugin *NetPlugin) Delete(args *cniSkel.CmdArgs) error {
10961090
if len(epInfos) == 0 {
10971091
endpointID := plugin.nm.GetEndpointID(args.ContainerID, args.IfName)
10981092
if !nwCfg.MultiTenancy {
1099-
logger.Error("Failed to query endpoint",
1093+
logger.Warn("Could not query endpoint",
11001094
zap.String("endpoint", endpointID),
11011095
zap.Error(err))
11021096

1103-
logger.Error("Release ip by ContainerID (endpoint not found)",
1097+
logger.Warn("Release ip by ContainerID (endpoint not found)",
11041098
zap.String("containerID", args.ContainerID))
1105-
telemetry.SendEvent(fmt.Sprintf("Release ip by ContainerID (endpoint not found):%v", args.ContainerID))
1099+
telemetry.SendEvent(fmt.Sprintf("Release ip by ContainerID (endpoint not found): %s", args.ContainerID))
11061100
if err = plugin.ipamInvoker.Delete(nil, nwCfg, args, nwInfo.Options); err != nil {
11071101
return plugin.RetriableError(fmt.Errorf("failed to release address(no endpoint): %w", err))
11081102
}
@@ -1129,14 +1123,13 @@ func (plugin *NetPlugin) Delete(args *cniSkel.CmdArgs) error {
11291123
for _, epInfo := range epInfos {
11301124
logger.Info("Deleting endpoint",
11311125
zap.String("endpointID", epInfo.EndpointID))
1132-
telemetry.SendEvent(fmt.Sprintf("Deleting endpoint:%v", epInfo.EndpointID))
11331126

11341127
if !nwCfg.MultiTenancy && (epInfo.NICType == cns.InfraNIC || epInfo.NICType == "") {
11351128
// Delegated/secondary nic ips are statically allocated so we don't need to release
11361129
// Call into IPAM plugin to release the endpoint's addresses.
11371130
for i := range epInfo.IPAddresses {
11381131
logger.Info("Release ip", zap.String("ip", epInfo.IPAddresses[i].IP.String()))
1139-
telemetry.SendEvent(fmt.Sprintf("Release ip:%s", epInfo.IPAddresses[i].IP.String()))
1132+
telemetry.SendEvent(fmt.Sprintf("Release ip: %s container id: %s endpoint id: %s", epInfo.IPAddresses[i].IP.String(), args.ContainerID, epInfo.EndpointID))
11401133
err = plugin.ipamInvoker.Delete(&epInfo.IPAddresses[i], nwCfg, args, nwInfo.Options)
11411134
if err != nil {
11421135
return plugin.RetriableError(fmt.Errorf("failed to release address: %w", err))
@@ -1145,6 +1138,7 @@ func (plugin *NetPlugin) Delete(args *cniSkel.CmdArgs) error {
11451138
} else if epInfo.EnableInfraVnet { // remove in future PR
11461139
nwCfg.IPAM.Subnet = nwInfo.Subnets[0].Prefix.String()
11471140
nwCfg.IPAM.Address = epInfo.InfraVnetIP.IP.String()
1141+
telemetry.SendEvent(fmt.Sprintf("Deleting infra vnet endpoint: container id: %s endpoint id: %s subnet: %s address: %s", args.ContainerID, epInfo.EndpointID, nwCfg.IPAM.Subnet, nwCfg.IPAM.Address))
11481142
err = plugin.ipamInvoker.Delete(nil, nwCfg, args, nwInfo.Options)
11491143
if err != nil {
11501144
return plugin.RetriableError(fmt.Errorf("failed to release address: %w", err))
@@ -1156,7 +1150,6 @@ func (plugin *NetPlugin) Delete(args *cniSkel.CmdArgs) error {
11561150
if err != nil {
11571151
return plugin.RetriableError(fmt.Errorf("failed to save state: %w", err))
11581152
}
1159-
telemetry.SendEvent(fmt.Sprintf("CNI DEL succeeded : Released ip %+v podname %v namespace %v", nwCfg.IPAM.Address, k8sPodName, k8sNamespace))
11601153

11611154
return err
11621155
}

network/endpoint_windows.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,7 @@ func (nw *network) deleteEndpointImplHnsV2(ep *endpoint) error {
580580
}
581581

582582
logger.Info("Deleting hcn endpoint with id", zap.String("HnsId", ep.HnsId))
583+
telemetry.SendEvent(fmt.Sprintf("Deleting HCN endpoint: %s", ep.HnsId))
583584

584585
hcnEndpoint, err = Hnsv2.GetEndpointByID(ep.HnsId)
585586
if err != nil {

network/manager.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package network
55

66
import (
77
"context"
8+
"fmt"
89
"net"
910
"sync"
1011
"time"
@@ -422,10 +423,13 @@ func (nm *networkManager) UpdateEndpointState(eps []*endpoint) error {
422423
}
423424

424425
ifnameToIPInfoMap := generateCNSIPInfoMap(eps) // key : interface name, value : IPInfo
425-
for _, ipinfo := range ifnameToIPInfoMap {
426-
logger.Info("Update endpoint state", zap.String("hnsEndpointID", ipinfo.HnsEndpointID), zap.String("hnsNetworkID", ipinfo.HnsNetworkID),
426+
ifNameToIPInfoCopy := map[string]restserver.IPInfo{}
427+
for key, ipinfo := range ifnameToIPInfoMap {
428+
logger.Info("Update endpoint state", zap.String("key", key), zap.String("hnsEndpointID", ipinfo.HnsEndpointID), zap.String("hnsNetworkID", ipinfo.HnsNetworkID),
427429
zap.String("hostVethName", ipinfo.HostVethName), zap.String("macAddress", ipinfo.MacAddress), zap.String("nicType", string(ipinfo.NICType)))
430+
ifNameToIPInfoCopy[key] = *ipinfo
428431
}
432+
telemetry.SendEvent(fmt.Sprintf("Stateless CNI update endpoint state with: %+v", ifNameToIPInfoCopy))
429433

430434
// we assume all endpoints have the same container id
431435
cnsEndpointID := eps[0].ContainerID

network/network_windows.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,7 @@ func (nm *networkManager) newNetworkImplHnsV2(nwInfo *EndpointInfo, extIf *exter
378378
// if network not found, create the HNS network.
379379
if errors.As(err, &hcn.NetworkNotFoundError{}) {
380380
logger.Info("Creating hcn network", zap.Any("hcnNetwork", hcnNetwork))
381+
telemetry.SendEvent(fmt.Sprintf("Creating HCN network: %+v", hcnNetwork))
381382
hnsResponse, err = Hnsv2.CreateNetwork(hcnNetwork)
382383
if err != nil {
383384
return nil, fmt.Errorf("Failed to create hcn network: %s due to error: %v", hcnNetwork.Name, err)
@@ -475,6 +476,7 @@ func (nm *networkManager) deleteNetworkImplHnsV2(nw *network) error {
475476
var hcnNetwork *hcn.HostComputeNetwork
476477
var err error
477478
logger.Info("Deleting hcn network with id", zap.String("id", nw.HnsId))
479+
telemetry.SendEvent(fmt.Sprintf("Deleting HCN network: %s", nw.HnsId))
478480

479481
if hcnNetwork, err = Hnsv2.GetNetworkByID(nw.HnsId); err != nil {
480482
return fmt.Errorf("Failed to get hcn network with id: %s due to err: %v", nw.HnsId, err)

network/transparent_vlan_endpointclient_linux.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ func (client *TransparentVlanEndpointClient) ensureCleanPopulateVM() error {
144144
if vlanIfErr != nil {
145145
// Assume any error is the vlan interface not found
146146
logger.Info("vlan interface doesn't exist even though network namespace exists, deleting network namespace...", zap.String("message", vlanIfErr.Error()))
147+
telemetry.SendEvent(fmt.Sprintf("vlan interface %s doesn't exist even though network namespace exists, deleting", client.vlanIfName))
147148
delErr := client.netnsClient.DeleteNamed(client.vnetNSName)
148149
if delErr != nil {
149150
return errors.Wrap(delErr, "failed to cleanup/delete ns after noticing vlan veth does not exist")
@@ -155,6 +156,7 @@ func (client *TransparentVlanEndpointClient) ensureCleanPopulateVM() error {
155156
if vlanIfInVMErr == nil {
156157
// The vlan interface exists in the VM ns because it failed to move into the network ns previously and needs to be cleaned up
157158
logger.Info("vlan interface exists on the VM namespace, deleting", zap.String("vlanIfName", client.vlanIfName))
159+
telemetry.SendEvent(fmt.Sprintf("vlan interface %s exists on the VM namespace, deleting", client.vlanIfName))
158160
if delErr := client.netlink.DeleteLink(client.vlanIfName); delErr != nil {
159161
return errors.Wrap(delErr, "failed to clean up vlan interface")
160162
}
@@ -300,6 +302,7 @@ func (client *TransparentVlanEndpointClient) PopulateVM(epInfo *EndpointInfo) er
300302
return errors.Wrap(deleteNSIfNotNilErr, "failed to move or detect vlan veth inside vnet namespace")
301303
}
302304
logger.Info("Moving vlan veth into namespace confirmed")
305+
telemetry.SendEvent(fmt.Sprintf("Moving vlan veth %s into namespace %s (id: %d) confirmed", client.vlanIfName, client.vnetNSName, client.vnetNSFileDescriptor))
303306
} else {
304307
logger.Info("Existing NS detected. vlan interface should exist or namespace would've been deleted.", zap.String("vnetNSName", client.vnetNSName), zap.String("vlanIfName", client.vlanIfName))
305308
}

telemetry/telemetrybuffer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ func (tb *TelemetryBuffer) StartTelemetryService(path string, args []string) err
308308
err := tb.plc.KillProcessByName(TelemetryServiceProcessName)
309309
if err != nil {
310310
if tb.logger != nil {
311-
tb.logger.Error("Failed to kill process by", zap.String("TelemetryServiceProcessName", TelemetryServiceProcessName), zap.Error(err))
311+
tb.logger.Warn("Failed to kill process by", zap.String("TelemetryServiceProcessName", TelemetryServiceProcessName), zap.Error(err))
312312
} else {
313313
log.Logf("[Telemetry] Failed to kill process by telemetryServiceProcessName %s due to %v", TelemetryServiceProcessName, err)
314314
}

0 commit comments

Comments
 (0)