Skip to content

Commit

Permalink
Merge pull request #2138 from sawsa307/fix-endpoint-metrics
Browse files Browse the repository at this point in the history
Endpoint State metrics Cleanup
  • Loading branch information
k8s-ci-robot authored May 23, 2023
2 parents 02cd7a6 + fb83fb0 commit a5542be
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
27 changes: 17 additions & 10 deletions pkg/neg/metrics/neg_metrics_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,19 @@ func (sm *SyncerMetrics) export() {
stateCount, syncerCount := sm.computeSyncerStateMetrics()
PublishSyncerStateMetrics(stateCount)

epStateCount, epsStateCount := sm.computeEndpointStateMetrics(false)
epStateCount, epsStateCount, epCount, epsCount := sm.computeEndpointStateMetrics()
for state, count := range epStateCount {
syncerEndpointState.WithLabelValues(string(state)).Set(float64(count))
}
for state, count := range epsStateCount {
syncerEndpointSliceState.WithLabelValues(string(state)).Set(float64(count))
}

sm.logger.V(3).Info("Exporting syncer related metrics", "Syncer count", syncerCount, "Number of Endpoints", lpMetrics.NumberOfEndpoints)
sm.logger.V(3).Info("Exporting syncer related metrics", "Syncer count", syncerCount,
"Network Endpoint Count", lpMetrics.NumberOfEndpoints,
"Endpoint Count From EPS", epCount,
"Endpoint Slice Count", epsCount,
)

finishedDurations, longestUnfinishedDurations := sm.computeDualStackMigrationDurations()
for _, duration := range finishedDurations {
Expand Down Expand Up @@ -222,24 +226,27 @@ func (sm *SyncerMetrics) computeSyncerStateMetrics() (*syncerStateCount, int) {
}

// computeSyncerEndpointStateMetrics aggregates endpoint and endpoint slice counts from all syncers
func (sm *SyncerMetrics) computeEndpointStateMetrics(forDegradedMode bool) (negtypes.StateCountMap, negtypes.StateCountMap) {
func (sm *SyncerMetrics) computeEndpointStateMetrics() (negtypes.StateCountMap, negtypes.StateCountMap, int, int) {
sm.mu.Lock()
defer sm.mu.Unlock()

epCounts := negtypes.StateCountMap{}
epsCounts := negtypes.StateCountMap{}
var epCount, epsCount int
epStateCount := negtypes.StateCountMap{}
epsStateCount := negtypes.StateCountMap{}
// collect count from each syncer
for _, epCount := range sm.syncerEndpointStateMap {
for _, epState := range sm.syncerEndpointStateMap {
for _, state := range negtypes.StatesForEndpointMetrics() {
epCounts[state] += epCount[state]
epStateCount[state] += epState[state]
epCount += epState[state]
}
}
for _, epsCount := range sm.syncerEndpointSliceStateMap {
for _, epsState := range sm.syncerEndpointSliceStateMap {
for _, state := range negtypes.StatesForEndpointMetrics() {
epsCounts[state] += epsCount[state]
epsStateCount[state] += epsState[state]
epsCount += epsState[state]
}
}
return epCounts, epsCounts
return epStateCount, epsStateCount, epCount, epsCount
}

// CollectDualStackMigrationMetrics will be used by dualstack.Migrator to export
Expand Down
2 changes: 1 addition & 1 deletion pkg/neg/syncers/endpoints_calculator.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ func (l *L7EndpointsCalculator) Mode() types.EndpointsCalculatorMode {
// CalculateEndpoints determines the endpoints in the NEGs based on the current service endpoints and the current NEGs.
func (l *L7EndpointsCalculator) CalculateEndpoints(eds []types.EndpointsData, _ map[string]types.NetworkEndpointSet) (map[string]types.NetworkEndpointSet, types.EndpointPodMap, int, error) {
result, err := toZoneNetworkEndpointMap(eds, l.zoneGetter, l.podLister, l.servicePortName, l.networkEndpointType, l.enableDualStackNEG)
if err != nil { // If current calculation ends up in error, we trigger and emit metrics in degraded mode.
if err == nil { // If current calculation ends up in error, we trigger and emit metrics in degraded mode.
l.syncMetricsCollector.UpdateSyncerEPMetrics(l.syncerKey, result.EPCount, result.EPSCount)
}
return result.NetworkEndpointSet, result.EndpointPodMap, result.EPCount[negtypes.Duplicate], err
Expand Down

0 comments on commit a5542be

Please sign in to comment.