Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Endpoint State metrics Cleanup #2138

Merged
merged 1 commit into from
May 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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