Skip to content

Commit 2096276

Browse files
authored
🌱 Add SSA cache metrics (#11635)
* 🌱 Add ssh cache metrics * rm unused field * update per comments * rm unused var * address comments * rm comments
1 parent 2d86cc0 commit 2096276

File tree

19 files changed

+120
-70
lines changed

19 files changed

+120
-70
lines changed

controlplane/kubeadm/internal/controllers/controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ func (r *KubeadmControlPlaneReconciler) SetupWithManager(ctx context.Context, mg
138138

139139
r.controller = c
140140
r.recorder = mgr.GetEventRecorderFor("kubeadmcontrolplane-controller")
141-
r.ssaCache = ssa.NewCache()
141+
r.ssaCache = ssa.NewCache("kubeadmcontrolplane")
142142

143143
if r.managementCluster == nil {
144144
r.managementCluster = &internal.Management{

controlplane/kubeadm/internal/controllers/controller_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1351,7 +1351,7 @@ kubernetesVersion: metav1.16.1
13511351
Status: internal.ClusterStatus{},
13521352
},
13531353
},
1354-
ssaCache: ssa.NewCache(),
1354+
ssaCache: ssa.NewCache("test-controller"),
13551355
}
13561356

13571357
result, err := r.Reconcile(ctx, ctrl.Request{NamespacedName: util.ObjectKey(kcp)})
@@ -1678,7 +1678,7 @@ func TestKubeadmControlPlaneReconciler_syncMachines(t *testing.T) {
16781678
reconciler := &KubeadmControlPlaneReconciler{
16791679
Client: env,
16801680
SecretCachingClient: secretCachingClient,
1681-
ssaCache: ssa.NewCache(),
1681+
ssaCache: ssa.NewCache("test-controller"),
16821682
}
16831683
g.Expect(reconciler.syncMachines(ctx, controlPlane)).To(Succeed())
16841684

controlplane/kubeadm/internal/controllers/upgrade_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ func TestKubeadmControlPlaneReconciler_RolloutStrategy_ScaleUp(t *testing.T) {
9696
Status: internal.ClusterStatus{Nodes: 1},
9797
},
9898
},
99-
ssaCache: ssa.NewCache(),
99+
ssaCache: ssa.NewCache("test-controller"),
100100
}
101101
controlPlane := &internal.ControlPlane{
102102
KCP: kcp,

exp/internal/controllers/machinepool_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ func (r *MachinePoolReconciler) SetupWithManager(ctx context.Context, mgr ctrl.M
145145
Scheme: mgr.GetScheme(),
146146
PredicateLogger: r.predicateLog,
147147
}
148-
r.ssaCache = ssa.NewCache()
148+
r.ssaCache = ssa.NewCache("machinepool")
149149

150150
return nil
151151
}

exp/internal/controllers/machinepool_controller_phases_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ import (
5050
const (
5151
clusterName = "test-cluster"
5252
wrongNamespace = "wrong-namespace"
53+
testController = "test-controller"
5354
)
5455

5556
func TestReconcileMachinePoolPhases(t *testing.T) {
@@ -1424,7 +1425,7 @@ func TestReconcileMachinePoolMachines(t *testing.T) {
14241425

14251426
r := &MachinePoolReconciler{
14261427
Client: env,
1427-
ssaCache: ssa.NewCache(),
1428+
ssaCache: ssa.NewCache(testController),
14281429
externalTracker: external.ObjectTracker{
14291430
Controller: externalfake.Controller{},
14301431
Cache: &informertest.FakeInformers{},
@@ -1493,7 +1494,7 @@ func TestReconcileMachinePoolMachines(t *testing.T) {
14931494

14941495
r := &MachinePoolReconciler{
14951496
Client: env,
1496-
ssaCache: ssa.NewCache(),
1497+
ssaCache: ssa.NewCache(testController),
14971498
externalTracker: external.ObjectTracker{
14981499
Controller: externalfake.Controller{},
14991500
Cache: &informertest.FakeInformers{},
@@ -1558,7 +1559,7 @@ func TestReconcileMachinePoolMachines(t *testing.T) {
15581559

15591560
r := &MachinePoolReconciler{
15601561
Client: env,
1561-
ssaCache: ssa.NewCache(),
1562+
ssaCache: ssa.NewCache(testController),
15621563
}
15631564

15641565
scope := &scope{

internal/controllers/machine/machine_controller.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ import (
5353
"sigs.k8s.io/cluster-api/controllers/noderefutil"
5454
"sigs.k8s.io/cluster-api/feature"
5555
"sigs.k8s.io/cluster-api/internal/controllers/machine/drain"
56-
"sigs.k8s.io/cluster-api/internal/util/ssa"
5756
"sigs.k8s.io/cluster-api/util"
5857
"sigs.k8s.io/cluster-api/util/annotations"
5958
"sigs.k8s.io/cluster-api/util/cache"
@@ -107,7 +106,6 @@ type Reconciler struct {
107106
// nodeDeletionRetryTimeout determines how long the controller will retry deleting a node
108107
// during a single reconciliation.
109108
nodeDeletionRetryTimeout time.Duration
110-
ssaCache ssa.Cache
111109

112110
// reconcileDeleteCache is used to store when reconcileDelete should not be executed before a
113111
// specific time for a specific Request. This is used to implement rate-limiting to avoid
@@ -182,7 +180,6 @@ func (r *Reconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, opt
182180
Scheme: mgr.GetScheme(),
183181
PredicateLogger: r.predicateLog,
184182
}
185-
r.ssaCache = ssa.NewCache()
186183
r.reconcileDeleteCache = cache.New[cache.ReconcileEntry]()
187184
return nil
188185
}

internal/controllers/machine/machine_controller_test.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ import (
4848
"sigs.k8s.io/cluster-api/controllers/external"
4949
externalfake "sigs.k8s.io/cluster-api/controllers/external/fake"
5050
"sigs.k8s.io/cluster-api/feature"
51-
"sigs.k8s.io/cluster-api/internal/util/ssa"
5251
"sigs.k8s.io/cluster-api/util"
5352
"sigs.k8s.io/cluster-api/util/cache"
5453
"sigs.k8s.io/cluster-api/util/conditions"
@@ -958,7 +957,6 @@ func TestReconcileRequest(t *testing.T) {
958957
r := &Reconciler{
959958
Client: clientFake,
960959
ClusterCache: clustercache.NewFakeClusterCache(clientFake, client.ObjectKey{Name: testCluster.Name, Namespace: testCluster.Namespace}),
961-
ssaCache: ssa.NewCache(),
962960
recorder: record.NewFakeRecorder(10),
963961
reconcileDeleteCache: cache.New[cache.ReconcileEntry](),
964962
externalTracker: external.ObjectTracker{
@@ -1254,7 +1252,6 @@ func TestMachineConditions(t *testing.T) {
12541252
Client: clientFake,
12551253
recorder: record.NewFakeRecorder(10),
12561254
ClusterCache: clustercache.NewFakeClusterCache(clientFake, client.ObjectKey{Name: testCluster.Name, Namespace: testCluster.Namespace}),
1257-
ssaCache: ssa.NewCache(),
12581255
externalTracker: external.ObjectTracker{
12591256
Controller: externalfake.Controller{},
12601257
Cache: &informertest.FakeInformers{},

internal/controllers/machinedeployment/machinedeployment_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ func (r *Reconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, opt
114114
}
115115

116116
r.recorder = mgr.GetEventRecorderFor("machinedeployment-controller")
117-
r.ssaCache = ssa.NewCache()
117+
r.ssaCache = ssa.NewCache("machinedeployment")
118118
return nil
119119
}
120120

internal/controllers/machineset/machineset_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ func (r *Reconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, opt
154154
}
155155

156156
r.recorder = mgr.GetEventRecorderFor("machineset-controller")
157-
r.ssaCache = ssa.NewCache()
157+
r.ssaCache = ssa.NewCache("machineset")
158158
return nil
159159
}
160160

internal/controllers/machineset/machineset_controller_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1287,7 +1287,7 @@ func TestMachineSetReconciler_syncMachines(t *testing.T) {
12871287
// for Machines, InfrastructureMachines and BootstrapConfigs.
12881288
reconciler := &Reconciler{
12891289
Client: env,
1290-
ssaCache: ssa.NewCache(),
1290+
ssaCache: ssa.NewCache("test-controller"),
12911291
}
12921292
s := &scope{
12931293
machineSet: ms,

0 commit comments

Comments
 (0)