From 8c4286bdd33dcca35bac800aa60d5a86224fff05 Mon Sep 17 00:00:00 2001 From: lukasmetzner Date: Mon, 26 Jan 2026 14:56:19 +0100 Subject: [PATCH 1/4] 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. --- .../controllers/route/metrics.go | 30 +++++++++++++++++++ .../controllers/route/route_controller.go | 4 +++ 2 files changed, 34 insertions(+) create mode 100644 staging/src/k8s.io/cloud-provider/controllers/route/metrics.go diff --git a/staging/src/k8s.io/cloud-provider/controllers/route/metrics.go b/staging/src/k8s.io/cloud-provider/controllers/route/metrics.go new file mode 100644 index 00000000000..6f2e55e9fb3 --- /dev/null +++ b/staging/src/k8s.io/cloud-provider/controllers/route/metrics.go @@ -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) + }) +} diff --git a/staging/src/k8s.io/cloud-provider/controllers/route/route_controller.go b/staging/src/k8s.io/cloud-provider/controllers/route/route_controller.go index c7e6c57e7da..ad897ac85b0 100644 --- a/staging/src/k8s.io/cloud-provider/controllers/route/route_controller.go +++ b/staging/src/k8s.io/cloud-provider/controllers/route/route_controller.go @@ -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) From 61cfa3fd14670de900813ecebb57ce106d0ea389 Mon Sep 17 00:00:00 2001 From: lukasmetzner Date: Tue, 27 Jan 2026 09:05:59 +0100 Subject: [PATCH 2/4] feat: add boilerplate header --- .../cloud-provider/controllers/route/metrics.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/staging/src/k8s.io/cloud-provider/controllers/route/metrics.go b/staging/src/k8s.io/cloud-provider/controllers/route/metrics.go index 6f2e55e9fb3..b6ef3994a57 100644 --- a/staging/src/k8s.io/cloud-provider/controllers/route/metrics.go +++ b/staging/src/k8s.io/cloud-provider/controllers/route/metrics.go @@ -1,3 +1,19 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + package route import ( From a53840212694c71f2f37e7fa3fadf6603940a658 Mon Sep 17 00:00:00 2001 From: lukasmetzner Date: Tue, 27 Jan 2026 09:36:55 +0100 Subject: [PATCH 3/4] fix: update golden list of metrics --- test/instrumentation/testdata/stable-metrics-list.yaml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/instrumentation/testdata/stable-metrics-list.yaml b/test/instrumentation/testdata/stable-metrics-list.yaml index 01f05bbfbd9..9a6146203e3 100644 --- a/test/instrumentation/testdata/stable-metrics-list.yaml +++ b/test/instrumentation/testdata/stable-metrics-list.yaml @@ -256,6 +256,12 @@ labels: - deprecated_version - stability_level +- name: route_sync_total + subsystem: route_controller + help: A metric counting the amount of times routes have been synced with the cloud + provider. + type: Counter + stabilityLevel: BETA - name: pod_scheduling_sli_duration_seconds subsystem: scheduler help: E2e latency for a pod being scheduled, from the time the pod enters the scheduling From f3de090c6061991aaa63a2b08c3e14ce0ecc7402 Mon Sep 17 00:00:00 2001 From: lukasmetzner Date: Tue, 27 Jan 2026 10:56:01 +0100 Subject: [PATCH 4/4] fix: introduce metric as stage alpha --- .../src/k8s.io/cloud-provider/controllers/route/metrics.go | 2 +- test/instrumentation/testdata/stable-metrics-list.yaml | 6 ------ 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/staging/src/k8s.io/cloud-provider/controllers/route/metrics.go b/staging/src/k8s.io/cloud-provider/controllers/route/metrics.go index b6ef3994a57..27a375e087c 100644 --- a/staging/src/k8s.io/cloud-provider/controllers/route/metrics.go +++ b/staging/src/k8s.io/cloud-provider/controllers/route/metrics.go @@ -35,7 +35,7 @@ var ( 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, + StabilityLevel: metrics.ALPHA, }) ) diff --git a/test/instrumentation/testdata/stable-metrics-list.yaml b/test/instrumentation/testdata/stable-metrics-list.yaml index 9a6146203e3..01f05bbfbd9 100644 --- a/test/instrumentation/testdata/stable-metrics-list.yaml +++ b/test/instrumentation/testdata/stable-metrics-list.yaml @@ -256,12 +256,6 @@ labels: - deprecated_version - stability_level -- name: route_sync_total - subsystem: route_controller - help: A metric counting the amount of times routes have been synced with the cloud - provider. - type: Counter - stabilityLevel: BETA - name: pod_scheduling_sli_duration_seconds subsystem: scheduler help: E2e latency for a pod being scheduled, from the time the pod enters the scheduling