Skip to content

Commit

Permalink
Rename syncer and endpoint metrics to match Monarch
Browse files Browse the repository at this point in the history
Rename metrics name and key to match monarch definition.
  • Loading branch information
sawsa307 committed May 9, 2023
1 parent b0a43b7 commit 517b0c5
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 46 deletions.
16 changes: 4 additions & 12 deletions pkg/neg/metrics/endpoint_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,32 +20,24 @@ import (
"github.com/prometheus/client_golang/prometheus"
)

const (
endpointState = "endpoint_state"
endpointSliceState = "endpoint_slice_state"

endpointStateKey = "neg_sync_endpoint_state"
endpointSliceStateKey = "neg_sync_endpoint_slice_state"
)

var (
// syncerEndpointState tracks the count of endpoints in different states
syncerEndpointState = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Subsystem: negControllerSubsystem,
Name: endpointStateKey,
Name: "syncer_endpoint_state",
Help: "Current count of endpoints in each state",
},
[]string{endpointState},
[]string{"state"},
)

// syncerEndpointSliceState tracks the count of endpoint slices in different states
syncerEndpointSliceState = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Subsystem: negControllerSubsystem,
Name: endpointSliceStateKey,
Name: "syncer_endpoint_slice_state",
Help: "Current count of endpoint slices in each state",
},
[]string{endpointSliceState},
[]string{"state"},
)
)
20 changes: 10 additions & 10 deletions pkg/neg/metrics/neg_metrics_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ type SyncerMetricsCollector interface {
}

type SyncerMetrics struct {
// syncerStatusMap tracks the status of each syncer
syncerStatusMap map[negtypes.NegSyncerKey]negtypes.Reason
// syncerStateMap tracks the status of each syncer
syncerStateMap map[negtypes.NegSyncerKey]negtypes.Reason
// syncerEndpointStateMap is a map between syncer and endpoint state counts.
syncerEndpointStateMap map[negtypes.NegSyncerKey]negtypes.StateCountMap
// syncerEndpointSliceStateMap is a map between syncer and endpoint slice state counts.
Expand All @@ -54,7 +54,7 @@ type SyncerMetrics struct {
// NewNEGMetricsCollector initializes SyncerMetrics and starts a go routine to compute and export metrics periodically.
func NewNegMetricsCollector(exportInterval time.Duration, logger klog.Logger) *SyncerMetrics {
return &SyncerMetrics{
syncerStatusMap: make(map[negtypes.NegSyncerKey]negtypes.Reason),
syncerStateMap: make(map[negtypes.NegSyncerKey]negtypes.Reason),
syncerEndpointStateMap: make(map[negtypes.NegSyncerKey]negtypes.StateCountMap),
syncerEndpointSliceStateMap: make(map[negtypes.NegSyncerKey]negtypes.StateCountMap),
syncerLabelProagationStats: make(map[negtypes.NegSyncerKey]LabelPropagationStats),
Expand All @@ -71,7 +71,7 @@ func FakeSyncerMetrics() *SyncerMetrics {
// RegisterSyncerMetrics registers syncer related metrics
func RegisterSyncerMetrics() {
prometheus.MustRegister(syncerSyncResult)
prometheus.MustRegister(syncerSyncerState)
prometheus.MustRegister(syncerState)
prometheus.MustRegister(syncerEndpointState)
prometheus.MustRegister(syncerEndpointSliceState)
}
Expand Down Expand Up @@ -116,11 +116,11 @@ func (sm *SyncerMetrics) UpdateSyncerStatusInMetrics(key negtypes.NegSyncerKey,
syncerSyncResult.WithLabelValues(string(reason)).Inc()
sm.mu.Lock()
defer sm.mu.Unlock()
if sm.syncerStatusMap == nil {
sm.syncerStatusMap = make(map[negtypes.NegSyncerKey]negtypes.Reason)
sm.logger.V(3).Info("Syncer Metrics failed to initialize correctly, reinitializing syncerStatusMap: %v", sm.syncerStatusMap)
if sm.syncerStateMap == nil {
sm.syncerStateMap = make(map[negtypes.NegSyncerKey]negtypes.Reason)
sm.logger.V(3).Info("Syncer Metrics failed to initialize correctly, reinitializing syncerStatusMap: %v", sm.syncerStateMap)
}
sm.syncerStatusMap[key] = reason
sm.syncerStateMap[key] = reason
}

func (sm *SyncerMetrics) UpdateSyncerEPMetrics(key negtypes.NegSyncerKey, endpointCount, endpointSliceCount negtypes.StateCountMap) {
Expand Down Expand Up @@ -153,7 +153,7 @@ func (sm *SyncerMetrics) SetLabelPropagationStats(key negtypes.NegSyncerKey, lab
func (sm *SyncerMetrics) DeleteSyncer(key negtypes.NegSyncerKey) {
sm.mu.Lock()
defer sm.mu.Unlock()
delete(sm.syncerStatusMap, key)
delete(sm.syncerStateMap, key)
delete(sm.syncerEndpointStateMap, key)
delete(sm.syncerEndpointSliceStateMap, key)
delete(sm.syncerLabelProagationStats, key)
Expand All @@ -178,7 +178,7 @@ func (sm *SyncerMetrics) computeSyncerStateMetrics() (*syncerStateCount, int) {

stateCount := &syncerStateCount{}
syncerCount := 0
for _, syncerState := range sm.syncerStatusMap {
for _, syncerState := range sm.syncerStateMap {
stateCount.inc(syncerState)
syncerCount++
}
Expand Down
45 changes: 21 additions & 24 deletions pkg/neg/metrics/syncer_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ const (
syncResultLabel = "result"
syncResultKey = "sync_result"

syncerStateLabel = "state"
syncerStateKey = "syncer_state"

EPCountsDiffer = "EndpointCountsDiffer"
EPNodeMissing = "EndpointNodeMissing"
EPNodeNotFound = "EndpointNodeNotFound"
Expand Down Expand Up @@ -58,14 +55,14 @@ var (
[]string{syncResultLabel},
)

// syncerSyncerState tracks the count of syncer in different states
syncerSyncerState = prometheus.NewGaugeVec(
// syncerState tracks the count of syncer in different states
syncerState = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Subsystem: negControllerSubsystem,
Name: syncerStateKey,
Name: "syncer_state",
Help: "Current count of syncers in each state",
},
[]string{syncerStateLabel},
[]string{"state"},
)
)

Expand Down Expand Up @@ -127,21 +124,21 @@ func (sc *syncerStateCount) inc(reason negtypes.Reason) {
}

func PublishSyncerStateMetrics(stateCount *syncerStateCount) {
syncerSyncerState.WithLabelValues(EPCountsDiffer).Set(float64(stateCount.epCountsDiffer))
syncerSyncerState.WithLabelValues(EPNodeMissing).Set(float64(stateCount.epNodeMissing))
syncerSyncerState.WithLabelValues(EPNodeNotFound).Set(float64(stateCount.epNodeNotFound))
syncerSyncerState.WithLabelValues(EPPodMissing).Set(float64(stateCount.epPodMissing))
syncerSyncerState.WithLabelValues(EPPodNotFound).Set(float64(stateCount.epPodNotFound))
syncerSyncerState.WithLabelValues(EPPodTypeAssertionFailed).Set(float64(stateCount.epPodTypeAssertionFailed))
syncerSyncerState.WithLabelValues(EPZoneMissing).Set(float64(stateCount.epZoneMissing))
syncerSyncerState.WithLabelValues(EPSEndpointCountZero).Set(float64(stateCount.epsEndpointCountZero))
syncerSyncerState.WithLabelValues(EPCalculationCountZero).Set(float64(stateCount.epCalculationCountZero))
syncerSyncerState.WithLabelValues(InvalidAPIResponse).Set(float64(stateCount.invalidAPIResponse))
syncerSyncerState.WithLabelValues(InvalidEPAttach).Set(float64(stateCount.invalidEPAttach))
syncerSyncerState.WithLabelValues(InvalidEPDetach).Set(float64(stateCount.invalidEPDetach))
syncerSyncerState.WithLabelValues(NegNotFound).Set(float64(stateCount.negNotFound))
syncerSyncerState.WithLabelValues(CurrentNegEPNotFound).Set(float64(stateCount.currentNegEPNotFound))
syncerSyncerState.WithLabelValues(EPSNotFound).Set(float64(stateCount.epsNotFound))
syncerSyncerState.WithLabelValues(OtherError).Set(float64(stateCount.otherError))
syncerSyncerState.WithLabelValues(Success).Set(float64(stateCount.success))
syncerState.WithLabelValues(EPCountsDiffer).Set(float64(stateCount.epCountsDiffer))
syncerState.WithLabelValues(EPNodeMissing).Set(float64(stateCount.epNodeMissing))
syncerState.WithLabelValues(EPNodeNotFound).Set(float64(stateCount.epNodeNotFound))
syncerState.WithLabelValues(EPPodMissing).Set(float64(stateCount.epPodMissing))
syncerState.WithLabelValues(EPPodNotFound).Set(float64(stateCount.epPodNotFound))
syncerState.WithLabelValues(EPPodTypeAssertionFailed).Set(float64(stateCount.epPodTypeAssertionFailed))
syncerState.WithLabelValues(EPZoneMissing).Set(float64(stateCount.epZoneMissing))
syncerState.WithLabelValues(EPSEndpointCountZero).Set(float64(stateCount.epsEndpointCountZero))
syncerState.WithLabelValues(EPCalculationCountZero).Set(float64(stateCount.epCalculationCountZero))
syncerState.WithLabelValues(InvalidAPIResponse).Set(float64(stateCount.invalidAPIResponse))
syncerState.WithLabelValues(InvalidEPAttach).Set(float64(stateCount.invalidEPAttach))
syncerState.WithLabelValues(InvalidEPDetach).Set(float64(stateCount.invalidEPDetach))
syncerState.WithLabelValues(NegNotFound).Set(float64(stateCount.negNotFound))
syncerState.WithLabelValues(CurrentNegEPNotFound).Set(float64(stateCount.currentNegEPNotFound))
syncerState.WithLabelValues(EPSNotFound).Set(float64(stateCount.epsNotFound))
syncerState.WithLabelValues(OtherError).Set(float64(stateCount.otherError))
syncerState.WithLabelValues(Success).Set(float64(stateCount.success))
}

0 comments on commit 517b0c5

Please sign in to comment.