feat(ccm): introduce metric route_controller_route_sync_total

This metric tracks the amount of times routes are synced with the
cloud provider. This metric is mainly used for A/B tests on the
feature gate `CloudControllerManagerWatchBasedRoutesReconciliation`
introduced in Kubernetes v1.35.
This commit is contained in:
lukasmetzner
2026-01-26 14:56:19 +01:00
parent 437184c055
commit 8c4286bdd3
2 changed files with 34 additions and 0 deletions

View File

@@ -0,0 +1,30 @@
package route
import (
"sync"
"k8s.io/component-base/metrics"
"k8s.io/component-base/metrics/legacyregistry"
)
const (
// subsystem is the name of this subsystem used for prometheus metrics.
subsystem = "route_controller"
)
var registration sync.Once
var (
routeSyncCount = metrics.NewCounter(&metrics.CounterOpts{
Name: "route_sync_total",
Subsystem: subsystem,
Help: "A metric counting the amount of times routes have been synced with the cloud provider.",
StabilityLevel: metrics.BETA,
})
)
func registerMetrics() {
registration.Do(func() {
legacyregistry.MustRegister(routeSyncCount)
})
}

View File

@@ -87,6 +87,8 @@ func New(
clusterName string,
clusterCIDRs []*net.IPNet,
) (*RouteController, error) {
registerMetrics()
if len(clusterCIDRs) == 0 {
klog.Fatal("RouteController: Must specify clusterCIDR.")
}
@@ -247,6 +249,8 @@ func (rc *RouteController) processNextWorkItem(ctx context.Context) bool {
}
func (rc *RouteController) reconcileNodeRoutes(ctx context.Context) error {
routeSyncCount.Inc()
routeList, err := rc.routes.ListRoutes(ctx, rc.clusterName)
if err != nil {
return fmt.Errorf("error listing routes: %v", err)