Skip to content

Commit

Permalink
add logging in NEG syncer
Browse files Browse the repository at this point in the history
  • Loading branch information
freehan committed Jun 12, 2020
1 parent 7846b52 commit 82d3ae5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
25 changes: 24 additions & 1 deletion pkg/neg/syncers/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,15 @@ func (s *transactionSyncer) syncInternal() error {
if err != nil {
return err
}
s.logStats(currentMap, "current NEG endpoints")

// Merge the current state from cloud with the transaction table together
// The combined state represents the eventual result when all transactions completed
mergeTransactionIntoZoneEndpointMap(currentMap, s.transactions)
s.logStats(currentMap, "after in-progress operations have completed, NEG endpoints")

targetMap, endpointPodMap, err := s.endpointsCalculator.CalculateEndpoints(ep.(*apiv1.Endpoints), currentMap)
s.logStats(currentMap, "desired NEG endpoints")

// Calculate the endpoints to add and delete to transform the current state to desire state
addEndpoints, removeEndpoints := calculateNetworkEndpointDifference(targetMap, currentMap)
Expand All @@ -185,7 +189,8 @@ func (s *transactionSyncer) syncInternal() error {
klog.V(4).Infof("No endpoint change for %s/%s, skip syncing NEG. ", s.Namespace, s.Name)
return nil
}

s.logEndpoints(addEndpoints, "adding endpoint")
s.logEndpoints(removeEndpoints, "removing endpoint")
return s.syncNetworkEndpoints(addEndpoints, removeEndpoints)
}

Expand Down Expand Up @@ -391,3 +396,21 @@ func mergeTransactionIntoZoneEndpointMap(endpointMap map[string]negtypes.Network
}
return
}

// logStats logs aggregated stats of the input endpointMap
func (s *transactionSyncer) logStats(endpointMap map[string]negtypes.NetworkEndpointSet, desc string) {
stats := []string{}
for zone, endpointSet := range endpointMap {
stats = append(stats, fmt.Sprintf("%d endpoints in zone %q", endpointSet.Len(), zone))
}
klog.V(3).Infof("For NEG %q, %s: %s.", s.negName, desc, strings.Join(stats, ","))
}

// logEndpoints logs individual endpoint in the input endpointMap
func (s *transactionSyncer) logEndpoints(endpointMap map[string]negtypes.NetworkEndpointSet, desc string) {
for zone, endpointSet := range endpointMap {
for _, endpoint := range endpointSet.List() {
klog.V(3).Infof("For NEG %q, %s: %+v to zone %q", s.negName, desc, endpoint, zone)
}
}
}
6 changes: 5 additions & 1 deletion pkg/neg/syncers/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func toZoneNetworkEndpointMap(endpoints *apiv1.Endpoints, zoneGetter negtypes.Zo
klog.Errorf("Endpoint object is nil")
return zoneNetworkEndpointMap, networkEndpointPodMap, nil
}

var foundMatchingPort bool
for _, subset := range endpoints.Subsets {
matchPort := ""
// service spec allows target Port to be a named Port.
Expand All @@ -193,6 +193,7 @@ func toZoneNetworkEndpointMap(endpoints *apiv1.Endpoints, zoneGetter negtypes.Zo
if len(matchPort) == 0 {
continue
}
foundMatchingPort = true

// processAddressFunc adds the qualified endpoints from the input list into the endpointSet group by zone
processAddressFunc := func(addresses []v1.EndpointAddress, includeAllEndpoints bool) error {
Expand Down Expand Up @@ -244,6 +245,9 @@ func toZoneNetworkEndpointMap(endpoints *apiv1.Endpoints, zoneGetter negtypes.Zo
return nil, nil, err
}
}
if !foundMatchingPort {
klog.Errorf("Service port name %q was not found in the endpoints object %+v", servicePortName, endpoints)
}
return zoneNetworkEndpointMap, networkEndpointPodMap, nil
}

Expand Down

0 comments on commit 82d3ae5

Please sign in to comment.