Skip to content

Commit

Permalink
Add metrics for sync result
Browse files Browse the repository at this point in the history
Created sync metrics collector to collect sync related metrics. Added
metrics to collect the cumulative count of sync results. Specified
metrics emit interval in flags.
  • Loading branch information
sawsa307 committed Jan 26, 2023
1 parent 5bcc3b0 commit 16db295
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
19 changes: 16 additions & 3 deletions pkg/neg/metrics/neg_metrics_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,22 @@ func init() {
// NewNEGMetricsCollector initializes SyncerMetrics and starts a go routine to compute and export metrics periodically.
func NewNegMetricsCollector(exportInterval time.Duration) *SyncerMetrics {
return &SyncerMetrics{
countSinceLastExport: make(map[syncError]int),
metricsInterval: exportInterval,
countSinceLastExport: map[syncError]int{
ErrEPCountsDiffer: 0,
ErrEPMissingNodeName: 0,
ErrEPMissingZone: 0,
ErrInvalidEPAttach: 0,
ErrInvalidEPDetach: 0,
ErrEPSEndpointCountZero: 0,
ErrEPCalculationCountZero: 0,
ErrNegNotFound: 0,
ErrCurrentEPNotFound: 0,
ErrEPSNotFound: 0,
ErrNodeNotFound: 0,
ErrOtherError: 0,
Success: 0,
},
metricsInterval: exportInterval,
}
}

Expand Down Expand Up @@ -98,7 +112,6 @@ func (im *SyncerMetrics) Run(stopCh <-chan struct{}) {
klog.V(3).Infof("Syncer Metrics initialized. Metrics will be exported at an interval of %v", im.metricsInterval)
// Compute and export metrics periodically.
go func() {
// Wait for ingress states to be populated in the cache before computing metrics.
time.Sleep(im.metricsInterval)
wait.Until(im.export, im.metricsInterval, stopCh)
}()
Expand Down
9 changes: 9 additions & 0 deletions pkg/neg/syncers/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ type transactionSyncer struct {
// 4. Endpoint count from EPS or calculated endpoint list is 0
// Need to grab syncLock first for any reads or writes based on this value
inError bool

// syncCollector collect sync related metrics
syncCollector metrics.SyncerMetricsCollector
}

func NewTransactionSyncer(
Expand All @@ -121,6 +124,7 @@ func NewTransactionSyncer(
epc negtypes.NetworkEndpointsCalculator,
kubeSystemUID string,
svcNegClient svcnegclient.Interface,
syncerMetrics *metrics.SyncerMetrics,
customName bool,
enableEndpointSlices bool,
log klog.Logger) negtypes.NegSyncer {
Expand All @@ -145,6 +149,7 @@ func NewTransactionSyncer(
reflector: reflector,
kubeSystemUID: kubeSystemUID,
svcNegClient: svcNegClient,
syncCollector: syncerMetrics,
customName: customName,
enableEndpointSlices: enableEndpointSlices,
inError: false,
Expand Down Expand Up @@ -192,6 +197,9 @@ func (s *transactionSyncer) syncInternal() error {

s.updateStatus(err)
metrics.PublishNegSyncMetrics(string(s.NegSyncerKey.NegType), string(s.endpointsCalculator.Mode()), err, start)
if s.enableEndpointSlices {
s.syncCollector.UpdateSyncer(s.NegSyncerKey, err)
}
return err
}

Expand Down Expand Up @@ -510,6 +518,7 @@ func (s *transactionSyncer) operationInternal(operation transactionOp, zone stri
if operation == detachOp {
err = fmt.Errorf("%w, reason: %v", metrics.ErrInvalidEPDetach, err)
}
s.syncCollector.UpdateSyncer(s.NegSyncerKey, err)
}
}

Expand Down

0 comments on commit 16db295

Please sign in to comment.