Skip to content

Commit

Permalink
Configure DualStack Migrator to export metrics to collector
Browse files Browse the repository at this point in the history
  • Loading branch information
gauravkghildiyal committed May 3, 2023
1 parent 7124413 commit 858afb1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
16 changes: 14 additions & 2 deletions pkg/neg/syncers/dualstack/migrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ type Migrator struct {
enableDualStack bool
// The NEG syncer which will be synced when Continue gets called.
syncer syncable
// The unique identifier of the syncer which is using this Migrator.
syncerKey types.NegSyncerKey
// metricsCollector is used for exporting metrics.
metricsCollector MetricsCollector

// mu protects paused, continueInProgress and previousDetach.
mu sync.Mutex
Expand Down Expand Up @@ -90,10 +94,16 @@ type syncable interface {
Sync() bool
}

func NewMigrator(enableDualStackNEG bool, syncer syncable, logger klog.Logger) *Migrator {
type MetricsCollector interface {
CollectDualStackMigrationMetrics(key types.NegSyncerKey, committedEndpoints map[string]types.NetworkEndpointSet, migrationCount int)
}

func NewMigrator(enableDualStackNEG bool, syncer syncable, syncerKey types.NegSyncerKey, metricsCollector MetricsCollector, logger klog.Logger) *Migrator {
return &Migrator{
enableDualStack: enableDualStackNEG,
syncer: syncer,
syncerKey: syncerKey,
metricsCollector: metricsCollector,
migrationWaitDuration: defaultMigrationWaitDuration,
previousDetachThreshold: defaultPreviousDetachThreshold,
fractionOfMigratingEndpoints: defaultFractionOfMigratingEndpoints,
Expand All @@ -119,8 +129,10 @@ func (d *Migrator) Filter(addEndpoints, removeEndpoints, committedEndpoints map[
}

_, migrationEndpointsInRemoveSet := findAndFilterMigrationEndpoints(addEndpoints, removeEndpoints)

migrationCount := endpointsCount(migrationEndpointsInRemoveSet)

d.metricsCollector.CollectDualStackMigrationMetrics(d.syncerKey, committedEndpoints, migrationCount)

paused := d.isPaused()
if migrationCount == 0 || paused {
d.logger.V(2).Info("Not starting migration detachments", "migrationCount", migrationCount, "paused", paused)
Expand Down
3 changes: 2 additions & 1 deletion pkg/neg/syncers/dualstack/migrator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/google/go-cmp/cmp"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/ingress-gce/pkg/neg/metrics"
"k8s.io/ingress-gce/pkg/neg/types"
"k8s.io/klog/v2"
)
Expand Down Expand Up @@ -773,5 +774,5 @@ func cloneZoneNetworkEndpointsMap(m map[string]types.NetworkEndpointSet) map[str
}

func newMigratorForTest(enableDualStackNEG bool) *Migrator {
return NewMigrator(enableDualStackNEG, &fakeSyncable{}, klog.Background())
return NewMigrator(enableDualStackNEG, &fakeSyncable{}, types.NegSyncerKey{}, metrics.FakeSyncerMetrics(), klog.Background())
}
2 changes: 1 addition & 1 deletion pkg/neg/syncers/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ func NewTransactionSyncer(
// transactionSyncer needs syncer interface for internals
ts.syncer = syncer
ts.retry = NewDelayRetryHandler(func() { syncer.Sync() }, NewExponentialBackendOffHandler(maxRetries, minRetryDelay, maxRetryDelay))
ts.dsMigrator = dualstack.NewMigrator(enableDualStackNEG, syncer, logger)
ts.dsMigrator = dualstack.NewMigrator(enableDualStackNEG, syncer, negSyncerKey, syncerMetrics, logger)
return syncer
}

Expand Down

0 comments on commit 858afb1

Please sign in to comment.