Skip to content

Commit 733d1c1

Browse files
Improve logging messages with more descriptive context across network and CNS components
Co-authored-by: prmathur-microsoft <[email protected]>
1 parent a3d5aee commit 733d1c1

File tree

4 files changed

+55
-55
lines changed

4 files changed

+55
-55
lines changed

cns/restserver/internalapi.go

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ func (service *HTTPRestService) SyncNodeStatus(dncEP, infraVnet, nodeID string,
108108
ncVersionListResp, err := service.nma.GetNCVersionList(ctx)
109109
if err != nil {
110110
skipNCVersionCheck = true
111-
logger.Errorf("failed to get nc version list from nmagent")
111+
logger.Errorf("Failed to retrieve network container version list from NMAgent, skipping version validation: %v", err)
112112
}
113113

114114
if !skipNCVersionCheck {
@@ -123,11 +123,11 @@ func (service *HTTPRestService) SyncNodeStatus(dncEP, infraVnet, nodeID string,
123123

124124
body, err = json.Marshal(ncsToBeAdded[ncid])
125125
if err != nil {
126-
logger.Errorf("[Azure-CNS] Failed to marshal nc with nc id %s and content %v", ncid, ncsToBeAdded[ncid])
126+
logger.Errorf("[Azure-CNS] Failed to marshal network container request for NC ID %s during sync: %v", ncid, err)
127127
}
128128
req, err = http.NewRequestWithContext(ctx, http.MethodPost, "", bytes.NewBuffer(body))
129129
if err != nil {
130-
logger.Errorf("[Azure CNS] Error received while creating http POST request for nc %v", ncsToBeAdded[ncid])
130+
logger.Errorf("[Azure CNS] Failed to create HTTP POST request for network container %s during sync: %v", ncid, err)
131131
}
132132
req.Header.Set(common.ContentType, common.JsonContent)
133133

@@ -162,7 +162,7 @@ func (service *HTTPRestService) SyncNodeStatus(dncEP, infraVnet, nodeID string,
162162
req.Header.Set(common.JsonContent, common.JsonContent)
163163
service.deleteNetworkContainer(httptest.NewRecorder(), req)
164164
} else {
165-
logger.Errorf("[Azure-CNS] Failed to delete NC request to sync state: %s", err.Error())
165+
logger.Errorf("[Azure-CNS] Failed to marshal delete NC request body during state sync for NC ID %s: %s", ncID, err.Error())
166166
}
167167
}
168168
return
@@ -182,7 +182,7 @@ func (service *HTTPRestService) SyncHostNCVersion(ctx context.Context, channelMo
182182
go service.MustGenerateCNIConflistOnce()
183183
}
184184
if err != nil {
185-
logger.Errorf("sync host error %v", err)
185+
logger.Errorf("Failed to synchronize host network container versions with NMAgent: %v", err)
186186
}
187187
syncHostNCVersionCount.WithLabelValues(strconv.FormatBool(err == nil)).Inc()
188188
syncHostNCVersionLatency.WithLabelValues(strconv.FormatBool(err == nil)).Observe(time.Since(start).Seconds())
@@ -201,19 +201,19 @@ func (service *HTTPRestService) syncHostNCVersion(ctx context.Context, channelMo
201201
// Will open a separate PR to convert all the NC version related variable to int. Change from string to int is a pain.
202202
localNCVersion, err := strconv.Atoi(service.state.ContainerStatus[idx].HostVersion)
203203
if err != nil {
204-
logger.Errorf("Received err when change containerstatus.HostVersion %s to int, err msg %v", service.state.ContainerStatus[idx].HostVersion, err)
204+
logger.Errorf("Failed to parse NC host version string '%s' to integer for container %s: %v", service.state.ContainerStatus[idx].HostVersion, service.state.ContainerStatus[idx].ID, err)
205205
continue
206206
}
207207
dncNCVersion, err := strconv.Atoi(service.state.ContainerStatus[idx].CreateNetworkContainerRequest.Version)
208208
if err != nil {
209-
logger.Errorf("Received err when change nc version %s in containerstatus to int, err msg %v", service.state.ContainerStatus[idx].CreateNetworkContainerRequest.Version, err)
209+
logger.Errorf("Failed to parse NC version string '%s' to integer from DNC for container %s: %v", service.state.ContainerStatus[idx].CreateNetworkContainerRequest.Version, service.state.ContainerStatus[idx].ID, err)
210210
continue
211211
}
212212
// host NC version is the NC version from NMAgent, if it's smaller than NC version from DNC, then append it to indicate it needs update.
213213
if localNCVersion < dncNCVersion {
214214
outdatedNCs[service.state.ContainerStatus[idx].ID] = struct{}{}
215215
} else if localNCVersion > dncNCVersion {
216-
logger.Errorf("NC version from NMAgent is larger than DNC, NC version from NMAgent is %d, NC version from DNC is %d", localNCVersion, dncNCVersion)
216+
logger.Errorf("Network container version inconsistency detected: NMAgent version (%d) is greater than DNC version (%d) for NC %s", localNCVersion, dncNCVersion, service.state.ContainerStatus[idx].ID)
217217
}
218218

219219
if localNCVersion > -1 {
@@ -263,7 +263,7 @@ func (service *HTTPRestService) syncHostNCVersion(ctx context.Context, channelMo
263263
}
264264
nmaProgrammedNCVersion, err := strconv.Atoi(nmaProgrammedNCVersionStr)
265265
if err != nil {
266-
logger.Errorf("failed to parse container version of %s: %s", ncID, err)
266+
logger.Errorf("Failed to parse NC version string '%s' from NMAgent for container %s: %s", nmaProgrammedNCVersionStr, ncID, err)
267267
continue
268268
}
269269
// Check whether it exist in service state and get the related nc info
@@ -280,12 +280,12 @@ func (service *HTTPRestService) syncHostNCVersion(ctx context.Context, channelMo
280280

281281
localNCVersion, err := strconv.Atoi(ncInfo.HostVersion)
282282
if err != nil {
283-
logger.Errorf("failed to parse host nc version string %s: %s", ncInfo.HostVersion, err)
283+
logger.Errorf("Failed to parse host NC version string '%s' to integer for container %s: %s", ncInfo.HostVersion, ncID, err)
284284
continue
285285
}
286286
if localNCVersion > nmaProgrammedNCVersion {
287287
//nolint:staticcheck // SA1019: suppress deprecated logger.Printf usage. Todo: legacy logger usage is consistent in cns repo. Migrates when all logger usage is migrated
288-
logger.Errorf("NC version from consolidated sources is decreasing: have %d, got %d", localNCVersion, nmaProgrammedNCVersion)
288+
logger.Errorf("Network container version regression detected for NC %s: local version %d is greater than NMAgent programmed version %d", ncID, localNCVersion, nmaProgrammedNCVersion)
289289
continue
290290
}
291291
if channelMode == cns.CRD {
@@ -342,7 +342,7 @@ func (service *HTTPRestService) ReconcileIPAssignment(podInfoByIP map[string]cns
342342

343343
podKeyToPodIPs, err := newPodKeyToPodIPsMap(podInfoByIP)
344344
if err != nil {
345-
logger.Errorf("could not transform pods indexed by IP address to pod IPs indexed by interface: %v", err)
345+
logger.Errorf("Failed to transform pod IP address map to interface-indexed pod IP map during reconciliation: %v", err)
346346
return types.UnexpectedError
347347
}
348348

@@ -368,7 +368,7 @@ func (service *HTTPRestService) ReconcileIPAssignment(podInfoByIP map[string]cns
368368
} else {
369369
// it might still be possible to see host networking pods here (where ips are not from ncs) if we are restoring using the kube podinfo provider
370370
// todo: once kube podinfo provider reconcile flow is removed, this line will not be necessary/should be removed.
371-
logger.Errorf("ip %s assigned to pod %+v but not found in any nc", ip, podIPs)
371+
logger.Errorf("IP address %s is assigned to pod %+v but was not found in any network container", ip, podIPs)
372372
}
373373
}
374374

@@ -379,7 +379,7 @@ func (service *HTTPRestService) ReconcileIPAssignment(podInfoByIP map[string]cns
379379

380380
jsonContext, err := podIPs.OrchestratorContext()
381381
if err != nil {
382-
logger.Errorf("Failed to marshal KubernetesPodInfo, error: %v", err)
382+
logger.Errorf("Failed to marshal KubernetesPodInfo to JSON for pod %s: %v", podKey, err)
383383
return types.UnexpectedError
384384
}
385385

@@ -431,7 +431,7 @@ func (service *HTTPRestService) ReconcileIPAMStateForSwift(ncReqs []*cns.CreateN
431431
}
432432

433433
if err := service.MarkExistingIPsAsPendingRelease(nnc.Spec.IPsNotInUse); err != nil {
434-
logger.Errorf("[Azure CNS] Error. Failed to mark IPs as pending %v", nnc.Spec.IPsNotInUse)
434+
logger.Errorf("[Azure CNS] Failed to mark unused IPs as pending release from NodeNetworkConfig: %v", err)
435435
return types.UnexpectedError
436436
}
437437

@@ -444,7 +444,7 @@ func (service *HTTPRestService) ReconcileIPAMStateForNodeSubnet(ncReqs []*cns.Cr
444444
logger.Printf("Reconciling CNS IPAM state with nc requests: [%+v], PodInfo [%+v]", ncReqs, podInfoByIP)
445445

446446
if len(ncReqs) != 1 {
447-
logger.Errorf("Nodesubnet should always have 1 NC to hold secondary IPs")
447+
logger.Errorf("Node subnet mode requires exactly 1 network container for secondary IPs, but found %d", len(ncReqs))
448448
return types.NetworkContainerNotSpecified
449449
}
450450

@@ -577,7 +577,7 @@ func (service *HTTPRestService) MustEnsureNoStaleNCs(validNCIDs []string) {
577577
panic(msg)
578578
}
579579

580-
logger.Errorf("[Azure CNS] Found stale NC ID %s in CNS state. Removing...", ncID)
580+
logger.Errorf("[Azure CNS] Found stale network container ID %s in CNS state with no assigned IPs. Removing from state...", ncID)
581581
delete(service.state.ContainerStatus, ncID)
582582
mutated = true
583583
}
@@ -591,14 +591,14 @@ func (service *HTTPRestService) MustEnsureNoStaleNCs(validNCIDs []string) {
591591
// This API will be called by CNS RequestController on CRD update.
592592
func (service *HTTPRestService) CreateOrUpdateNetworkContainerInternal(req *cns.CreateNetworkContainerRequest) types.ResponseCode {
593593
if req.NetworkContainerid == "" {
594-
logger.Errorf("[Azure CNS] Error. NetworkContainerid is empty")
594+
logger.Errorf("[Azure CNS] Network container ID is empty in CreateOrUpdateNetworkContainer request")
595595
return types.NetworkContainerNotSpecified
596596
}
597597

598598
// For now only RequestController uses this API which will be initialized only for AKS scenario.
599599
// Validate ContainerType is set as Docker
600600
if service.state.OrchestratorType != cns.KubernetesCRD && service.state.OrchestratorType != cns.Kubernetes {
601-
logger.Errorf("[Azure CNS] Error. Unsupported OrchestratorType: %s", service.state.OrchestratorType)
601+
logger.Errorf("[Azure CNS] Unsupported orchestrator type %s for CreateOrUpdateNetworkContainer operation", service.state.OrchestratorType)
602602
return types.UnsupportedOrchestratorType
603603
}
604604

network/endpoint_linux.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func (nw *network) newEndpointImpl(
7070
)
7171

7272
if nw.Endpoints[epInfo.EndpointID] != nil {
73-
logger.Info("[net] Endpoint already exists.")
73+
logger.Info("Endpoint already exists in network, skipping creation", zap.String("endpointID", epInfo.EndpointID), zap.String("networkID", nw.Id))
7474
err = errEndpointExists
7575
return nil, err
7676
}
@@ -95,7 +95,7 @@ func (nw *network) newEndpointImpl(
9595
contIfName = fmt.Sprintf("%s%s2", hostVEthInterfacePrefix, vethname)
9696
} else {
9797
// Create a veth pair.
98-
logger.Info("Generate veth name based on endpoint id")
98+
logger.Info("Generating veth pair names based on endpoint ID", zap.String("endpointID", epInfo.EndpointID[:7]))
9999
hostIfName = fmt.Sprintf("%s%s", hostVEthInterfacePrefix, epInfo.EndpointID[:7])
100100
contIfName = fmt.Sprintf("%s%s-2", hostVEthInterfacePrefix, epInfo.EndpointID[:7])
101101
}
@@ -140,13 +140,13 @@ func (nw *network) newEndpointImpl(
140140
//nolint:gocritic
141141
if vlanid != 0 {
142142
if nw.Mode == opModeTransparentVlan {
143-
logger.Info("Transparent vlan client")
143+
logger.Info("Initializing transparent VLAN endpoint client", zap.String("endpointID", epInfo.EndpointID), zap.Int("vlanID", vlanid))
144144
if _, ok := epInfo.Data[SnatBridgeIPKey]; ok {
145145
nw.SnatBridgeIP = epInfo.Data[SnatBridgeIPKey].(string)
146146
}
147147
epClient = NewTransparentVlanEndpointClient(nw, epInfo, hostIfName, contIfName, vlanid, localIP, nl, plc, nsc, iptc)
148148
} else {
149-
logger.Info("OVS client")
149+
logger.Info("Initializing OVS endpoint client", zap.String("endpointID", epInfo.EndpointID), zap.Int("vlanID", vlanid))
150150
if _, ok := epInfo.Data[SnatBridgeIPKey]; ok {
151151
nw.SnatBridgeIP = epInfo.Data[SnatBridgeIPKey].(string)
152152
}
@@ -164,13 +164,13 @@ func (nw *network) newEndpointImpl(
164164
iptc)
165165
}
166166
} else if nw.Mode != opModeTransparent {
167-
logger.Info("Bridge client")
167+
logger.Info("Initializing Linux bridge endpoint client", zap.String("endpointID", epInfo.EndpointID))
168168
epClient = NewLinuxBridgeEndpointClient(nw.extIf, hostIfName, contIfName, nw.Mode, nl, plc)
169169
} else if epInfo.NICType == cns.NodeNetworkInterfaceFrontendNIC {
170-
logger.Info("Secondary client")
170+
logger.Info("Initializing secondary endpoint client", zap.String("endpointID", epInfo.EndpointID))
171171
epClient = NewSecondaryEndpointClient(nl, netioCli, plc, nsc, dhcpclient, ep)
172172
} else {
173-
logger.Info("Transparent client")
173+
logger.Info("Initializing transparent endpoint client", zap.String("endpointID", epInfo.EndpointID))
174174
epClient = NewTransparentEndpointClient(nw.extIf, hostIfName, contIfName, nw.Mode, nl, netioCli, plc)
175175
}
176176
}
@@ -241,7 +241,7 @@ func (nw *network) newEndpointImpl(
241241

242242
if epInfo.IPV6Mode != "" {
243243
// Enable ipv6 setting in container
244-
logger.Info("Enable ipv6 setting in container.")
244+
logger.Info("Enabling IPv6 settings in container namespace", zap.String("endpointID", epInfo.EndpointID), zap.String("ipv6Mode", epInfo.IPV6Mode))
245245
nuc := networkutils.NewNetworkUtils(nl, plc)
246246
if epErr := nuc.UpdateIPV6Setting(0); epErr != nil {
247247
return fmt.Errorf("enable ipv6 in container failed:%w", epErr)
@@ -351,7 +351,7 @@ func addRoutes(nl netlink.NetlinkInterface, netioshim netio.NetIOInterface, inte
351351
if !strings.Contains(strings.ToLower(err.Error()), "file exists") {
352352
return err
353353
} else {
354-
logger.Info("route already exists")
354+
logger.Info("Skipping route addition: route already exists in routing table", zap.String("destination", route.Dst.String()))
355355
}
356356
}
357357
}
@@ -408,9 +408,9 @@ func (nm *networkManager) updateEndpointImpl(nw *network, existingEpInfo *Endpoi
408408
var ep *endpoint
409409

410410
existingEpFromRepository := nw.Endpoints[existingEpInfo.EndpointID]
411-
logger.Info("[updateEndpointImpl] Going to retrieve endpoint with Id to update", zap.String("id", existingEpInfo.EndpointID))
411+
logger.Info("Attempting to update endpoint", zap.String("endpointID", existingEpInfo.EndpointID), zap.String("networkID", nw.Id))
412412
if existingEpFromRepository == nil {
413-
logger.Info("[updateEndpointImpl] Endpoint cannot be updated as it does not exist")
413+
logger.Info("Cannot update endpoint: endpoint does not exist in network", zap.String("endpointID", existingEpInfo.EndpointID))
414414
return nil, errEndpointNotFound
415415
}
416416

0 commit comments

Comments
 (0)