Skip to content

Commit

Permalink
Rename NEG metrics collector
Browse files Browse the repository at this point in the history
* Rename NEG metrics collector because it collects more than syncer
  metrics now.
* FakeNEGControllerMetrics should be used for testing.
  • Loading branch information
sawsa307 committed Jan 26, 2024
1 parent 8a5a2a3 commit cfe77a6
Show file tree
Hide file tree
Showing 11 changed files with 190 additions and 191 deletions.
21 changes: 10 additions & 11 deletions pkg/neg/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ import (
"k8s.io/ingress-gce/pkg/flags"
"k8s.io/ingress-gce/pkg/neg/metrics"
"k8s.io/ingress-gce/pkg/neg/metrics/metricscollector"
syncMetrics "k8s.io/ingress-gce/pkg/neg/metrics/metricscollector"
"k8s.io/ingress-gce/pkg/neg/readiness"
"k8s.io/ingress-gce/pkg/neg/syncers/labels"
negtypes "k8s.io/ingress-gce/pkg/neg/types"
Expand All @@ -57,7 +56,7 @@ import (
func init() {
// register prometheus metrics
metrics.RegisterMetrics()
syncMetrics.RegisterMetrics()
metricscollector.RegisterMetrics()
}

// Controller is network endpoint group controller.
Expand Down Expand Up @@ -96,8 +95,8 @@ type Controller struct {
// reflector handles NEG readiness gate and conditions for pods in NEG.
reflector readiness.Reflector

// syncerMetrics collects NEG controller metrics
syncerMetrics *syncMetrics.SyncerMetrics
// metricsCollector collects NEG controller metrics
metricsCollector *metricscollector.NEGControllerMetrics

// runL4 indicates whether to run NEG controller that processes L4 services
runL4 bool
Expand Down Expand Up @@ -166,7 +165,7 @@ func NewController(
recorder := eventBroadcaster.NewRecorder(negScheme,
apiv1.EventSource{Component: "neg-controller"})

syncerMetrics := syncMetrics.NewNegMetricsCollector(flags.F.NegMetricsExportInterval, logger)
metricsCollector := metricscollector.NewNegControllerMetrics(flags.F.NegMetricsExportInterval, logger)
manager := newSyncerManager(
namer,
recorder,
Expand All @@ -179,7 +178,7 @@ func NewController(
endpointSliceInformer.GetIndexer(),
nodeInformer.GetIndexer(),
svcNegInformer.GetIndexer(),
syncerMetrics,
metricsCollector,
enableNonGcpMode,
enableDualStackNEG,
numGCWorkers,
Expand Down Expand Up @@ -229,7 +228,7 @@ func NewController(
nodeQueue: workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), "neg_node_queue"),
syncTracker: utils.NewTimeTracker(),
reflector: reflector,
syncerMetrics: syncerMetrics,
metricsCollector: metricsCollector,
runL4: runL4Controller,
enableIngressRegionalExternal: enableIngressRegionalExternal,
logger: logger,
Expand Down Expand Up @@ -352,7 +351,7 @@ func (c *Controller) Run(stopCh <-chan struct{}) {
wait.Until(c.gc, c.gcPeriod, stopCh)
}()
go c.reflector.Run(stopCh)
go c.syncerMetrics.Run(stopCh)
go c.metricsCollector.Run(stopCh)
<-stopCh
}

Expand Down Expand Up @@ -463,7 +462,7 @@ func (c *Controller) processService(key string) error {
return err
}
if !exists {
c.syncerMetrics.DeleteNegService(key)
c.metricsCollector.DeleteNegService(key)
c.manager.StopSyncer(namespace, name)
return nil
}
Expand Down Expand Up @@ -518,12 +517,12 @@ func (c *Controller) processService(key string) error {
return err
}
negUsage.SuccessfulNeg, negUsage.ErrorNeg, err = c.manager.EnsureSyncers(namespace, name, svcPortInfoMap)
c.syncerMetrics.SetNegService(key, negUsage)
c.metricsCollector.SetNegService(key, negUsage)
return err
}
// do not need Neg
c.logger.V(3).Info("Service does not need any NEG. Skipping", "service", key)
c.syncerMetrics.DeleteNegService(key)
c.metricsCollector.DeleteNegService(key)
// neg annotation is not found or NEG is not enabled
c.manager.StopSyncer(namespace, name)

Expand Down
14 changes: 7 additions & 7 deletions pkg/neg/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ type syncerManager struct {
// syncerMap stores the NEG syncer
// key consists of service namespace, name and targetPort. Value is the corresponding syncer.
syncerMap map[negtypes.NegSyncerKey]negtypes.NegSyncer
// syncCollector collect sync related metrics
syncerMetrics *metricscollector.SyncerMetrics
// metricsCollector collects NEG controller metrics
metricsCollector *metricscollector.NEGControllerMetrics

// reflector handles NEG readiness gate and conditions for pods in NEG.
reflector readiness.Reflector
Expand Down Expand Up @@ -128,7 +128,7 @@ func newSyncerManager(namer negtypes.NetworkEndpointGroupNamer,
endpointSliceLister cache.Indexer,
nodeLister cache.Indexer,
svcNegLister cache.Indexer,
syncerMetrics *metricscollector.SyncerMetrics,
metricsCollector *metricscollector.NEGControllerMetrics,
enableNonGcpMode bool,
enableDualStackNEG bool,
numGCWorkers int,
Expand All @@ -151,7 +151,7 @@ func newSyncerManager(namer negtypes.NetworkEndpointGroupNamer,
svcNegLister: svcNegLister,
svcPortMap: make(map[serviceKey]negtypes.PortInfoMap),
syncerMap: make(map[negtypes.NegSyncerKey]negtypes.NegSyncer),
syncerMetrics: syncerMetrics,
metricsCollector: metricsCollector,
svcNegClient: svcNegClient,
kubeSystemUID: kubeSystemUID,
enableNonGcpMode: enableNonGcpMode,
Expand Down Expand Up @@ -238,7 +238,7 @@ func (manager *syncerManager) EnsureSyncers(namespace, name string, newPorts neg
portInfo.EpCalculatorMode,
manager.logger.WithValues("service", klog.KRef(syncerKey.Namespace, syncerKey.Name), "negName", syncerKey.NegName),
manager.enableDualStackNEG,
manager.syncerMetrics,
manager.metricsCollector,
&portInfo.NetworkInfo,
)
syncer = negsyncer.NewTransactionSyncer(
Expand All @@ -255,7 +255,7 @@ func (manager *syncerManager) EnsureSyncers(namespace, name string, newPorts neg
epc,
string(manager.kubeSystemUID),
manager.svcNegClient,
manager.syncerMetrics,
manager.metricsCollector,
!manager.namer.IsNEG(portInfo.NegName),
manager.logger,
manager.lpConfig,
Expand Down Expand Up @@ -481,7 +481,7 @@ func (manager *syncerManager) garbageCollectSyncer() {
for key, syncer := range manager.syncerMap {
if syncer.IsStopped() && !syncer.IsShuttingDown() {
delete(manager.syncerMap, key)
manager.syncerMetrics.DeleteSyncer(key)
manager.metricsCollector.DeleteSyncer(key)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/neg/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func NewTestSyncerManager(kubeClient kubernetes.Interface) (*syncerManager, *gce
testContext.EndpointSliceInformer.GetIndexer(),
testContext.NodeInformer.GetIndexer(),
testContext.SvcNegInformer.GetIndexer(),
metricscollector.FakeSyncerMetrics(),
metricscollector.FakeNEGControllerMetrics(),
false, //enableNonGcpMode
testContext.EnableDualStackNEG,
testContext.NumGCWorkers,
Expand Down
Loading

0 comments on commit cfe77a6

Please sign in to comment.