Skip to content

Commit

Permalink
Add metrics for syncer status
Browse files Browse the repository at this point in the history
Added metrics to collect the current count of syncers in each status.
  • Loading branch information
sawsa307 committed Feb 15, 2023
1 parent b14be83 commit b0b0442
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions pkg/neg/metrics/neg_metrics_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ var (
syncResultLabel = "result"
syncResultKey = "sync_result"

syncerStatusLabel = "status"
syncerStatusKey = "syncer_status"

// syncerSyncResult tracks the count for each sync result
syncerSyncResult = prometheus.NewCounterVec(
prometheus.CounterOpts{
Expand All @@ -39,6 +42,16 @@ var (
},
[]string{syncResultLabel},
)

// syncerSyncerStatus tracks the count of syncer in different statuses
syncerSyncerStatus = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Subsystem: negControllerSubsystem,
Name: syncerStatusKey,
Help: "Current count of syncers in each status",
},
[]string{syncerStatusLabel},
)
)

type SyncerMetricsCollector interface {
Expand Down Expand Up @@ -73,6 +86,7 @@ func FakeSyncerMetrics() *SyncerMetrics {
// RegisterSyncerMetrics registers syncer related metrics
func RegisterSyncerMetrics() {
prometheus.MustRegister(syncerSyncResult)
prometheus.MustRegister(syncerSyncerStatus)
}

func (sm *SyncerMetrics) Run(stopCh <-chan struct{}) {
Expand All @@ -87,6 +101,11 @@ func (sm *SyncerMetrics) Run(stopCh <-chan struct{}) {

// export exports syncer metrics.
func (sm *SyncerMetrics) export() {
statusCount, syncerCount := sm.computeSyncerStatusMetrics()
sm.logger.V(3).Info("Exporting syncer status metrics.", "Syncer count", syncerCount)
for syncerStatus, count := range statusCount {
syncerSyncerStatus.WithLabelValues(syncerStatus).Set(float64(count))
}
}

// UpdateSyncer update the status of corresponding syncer based on the syncResult.
Expand All @@ -101,3 +120,31 @@ func (sm *SyncerMetrics) UpdateSyncer(key negtypes.NegSyncerKey, syncResult *neg
}
sm.syncerStatusMap[key] = syncResult.Result
}

func (sm *SyncerMetrics) computeSyncerStatusMetrics() (map[string]int, int) {
sm.mu.Lock()
defer sm.mu.Unlock()
sm.logger.V(3).Info("computing syncer status metrics")

statusCount := map[string]int{
negtypes.ResultEPCountsDiffer: 0,
negtypes.ResultEPMissingNodeName: 0,
negtypes.ResultNodeNotFound: 0,
negtypes.ResultEPMissingZone: 0,
negtypes.ResultEPSEndpointCountZero: 0,
negtypes.ResultEPCalculationCountZero: 0,
negtypes.ResultInvalidEPAttach: 0,
negtypes.ResultInvalidEPDetach: 0,
negtypes.ResultNegNotFound: 0,
negtypes.ResultCurrentEPNotFound: 0,
negtypes.ResultEPSNotFound: 0,
negtypes.ResultOtherError: 0,
negtypes.ResultSuccess: 0,
}
syncerCount := 0
for _, syncerStatus := range sm.syncerStatusMap {
statusCount[syncerStatus] += 1
syncerCount += 1
}
return statusCount, syncerCount
}

0 comments on commit b0b0442

Please sign in to comment.