Skip to content

Commit 7e60c01

Browse files
meobilivangrichardcase
authored andcommitted
instrument exp/controllers
1 parent 02380f5 commit 7e60c01

File tree

3 files changed

+99
-0
lines changed

3 files changed

+99
-0
lines changed

exp/controllers/gcpmanagedcluster_controller.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import (
2424
"github.com/GoogleCloudPlatform/k8s-cloud-provider/pkg/cloud/filter"
2525
"github.com/GoogleCloudPlatform/k8s-cloud-provider/pkg/cloud/meta"
2626
"github.com/pkg/errors"
27+
"go.opentelemetry.io/otel/attribute"
28+
"go.opentelemetry.io/otel/trace"
2729
apierrors "k8s.io/apimachinery/pkg/api/errors"
2830
"k8s.io/apimachinery/pkg/types"
2931
"k8s.io/klog/v2"
@@ -33,6 +35,7 @@ import (
3335
"sigs.k8s.io/cluster-api-provider-gcp/cloud/services/compute/subnets"
3436
infrav1exp "sigs.k8s.io/cluster-api-provider-gcp/exp/api/v1beta1"
3537
"sigs.k8s.io/cluster-api-provider-gcp/util/reconciler"
38+
"sigs.k8s.io/cluster-api-provider-gcp/util/telemetry"
3639
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
3740
"sigs.k8s.io/cluster-api/util"
3841
"sigs.k8s.io/cluster-api/util/annotations"
@@ -68,6 +71,16 @@ func (r *GCPManagedClusterReconciler) Reconcile(ctx context.Context, req ctrl.Re
6871

6972
log := log.FromContext(ctx)
7073

74+
ctx, span := telemetry.Tracer().Start(
75+
ctx, "controllers.GCPManagedClusterReconciler.Reconcile",
76+
trace.WithAttributes(
77+
attribute.String("name", req.Name),
78+
attribute.String("namespace", req.Namespace),
79+
attribute.String("kind", "GCPManagedCluster"),
80+
),
81+
)
82+
defer span.End()
83+
7184
gcpCluster := &infrav1exp.GCPManagedCluster{}
7285
err := r.Get(ctx, req.NamespacedName, gcpCluster)
7386
if err != nil {
@@ -142,6 +155,14 @@ func (r *GCPManagedClusterReconciler) Reconcile(ctx context.Context, req ctrl.Re
142155
func (r *GCPManagedClusterReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
143156
log := ctrl.LoggerFrom(ctx)
144157

158+
ctx, span := telemetry.Tracer().Start(
159+
ctx, "controllers.GCPManagedClusterReconciler.SetupWithManager",
160+
trace.WithAttributes(
161+
attribute.String("controller", "GCPManagedClusterReconciler"),
162+
),
163+
)
164+
defer span.End()
165+
145166
c, err := ctrl.NewControllerManagedBy(mgr).
146167
WithOptions(options).
147168
For(&infrav1exp.GCPManagedCluster{}).
@@ -169,6 +190,12 @@ func (r *GCPManagedClusterReconciler) SetupWithManager(ctx context.Context, mgr
169190

170191
func (r *GCPManagedClusterReconciler) reconcile(ctx context.Context, clusterScope *scope.ManagedClusterScope) error {
171192
log := log.FromContext(ctx).WithValues("controller", "gcpmanagedcluster")
193+
194+
ctx, span := telemetry.Tracer().Start(
195+
ctx, "controllers.GCPManagedClusterReconciler.reconcile",
196+
)
197+
defer span.End()
198+
172199
log.Info("Reconciling GCPManagedCluster")
173200

174201
controllerutil.AddFinalizer(clusterScope.GCPManagedCluster, infrav1exp.ClusterFinalizer)
@@ -226,6 +253,12 @@ func (r *GCPManagedClusterReconciler) reconcile(ctx context.Context, clusterScop
226253

227254
func (r *GCPManagedClusterReconciler) reconcileDelete(ctx context.Context, clusterScope *scope.ManagedClusterScope) (ctrl.Result, error) {
228255
log := log.FromContext(ctx).WithValues("controller", "gcpmanagedcluster", "action", "delete")
256+
257+
ctx, span := telemetry.Tracer().Start(
258+
ctx, "controllers.GCPManagedClusterReconciler.reconcileDelete",
259+
)
260+
defer span.End()
261+
229262
log.Info("Reconciling Delete GCPManagedCluster")
230263

231264
if clusterScope.GCPManagedControlPlane != nil {

exp/controllers/gcpmanagedcontrolplane_controller.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import (
2121
"fmt"
2222
"time"
2323

24+
"go.opentelemetry.io/otel/attribute"
25+
"go.opentelemetry.io/otel/trace"
2426
"sigs.k8s.io/cluster-api/util/annotations"
2527

2628
"github.com/pkg/errors"
@@ -30,6 +32,7 @@ import (
3032
"sigs.k8s.io/cluster-api-provider-gcp/cloud/services/container/clusters"
3133
infrav1exp "sigs.k8s.io/cluster-api-provider-gcp/exp/api/v1beta1"
3234
"sigs.k8s.io/cluster-api-provider-gcp/util/reconciler"
35+
"sigs.k8s.io/cluster-api-provider-gcp/util/telemetry"
3336
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
3437
"sigs.k8s.io/cluster-api/util"
3538
"sigs.k8s.io/cluster-api/util/conditions"
@@ -63,6 +66,14 @@ type GCPManagedControlPlaneReconciler struct {
6366
func (r *GCPManagedControlPlaneReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
6467
log := log.FromContext(ctx).WithValues("controller", "GCPManagedControlPlane")
6568

69+
ctx, span := telemetry.Tracer().Start(
70+
ctx, "controllers.GCPManagedControlPlaneReconciler.SetupWithManager",
71+
trace.WithAttributes(
72+
attribute.String("controller", "GCPManagedControlPlane"),
73+
),
74+
)
75+
defer span.End()
76+
6677
gcpManagedControlPlane := &infrav1exp.GCPManagedControlPlane{}
6778
c, err := ctrl.NewControllerManagedBy(mgr).
6879
WithOptions(options).
@@ -90,6 +101,16 @@ func (r *GCPManagedControlPlaneReconciler) Reconcile(ctx context.Context, req ct
90101

91102
log := ctrl.LoggerFrom(ctx)
92103

104+
ctx, span := telemetry.Tracer().Start(
105+
ctx, "controllers.GCPManagedControlPlaneReconciler.Reconcile",
106+
trace.WithAttributes(
107+
attribute.String("name", req.Name),
108+
attribute.String("namespace", req.Namespace),
109+
attribute.String("kind", "GCPManagedControlPlane"),
110+
),
111+
)
112+
defer span.End()
113+
93114
// Get the control plane instance
94115
gcpManagedControlPlane := &infrav1exp.GCPManagedControlPlane{}
95116
if err := r.Client.Get(ctx, req.NamespacedName, gcpManagedControlPlane); err != nil {
@@ -154,6 +175,12 @@ func (r *GCPManagedControlPlaneReconciler) Reconcile(ctx context.Context, req ct
154175

155176
func (r *GCPManagedControlPlaneReconciler) reconcile(ctx context.Context, managedControlPlaneScope *scope.ManagedControlPlaneScope) (ctrl.Result, error) {
156177
log := log.FromContext(ctx).WithValues("controller", "gcpmanagedcontrolplane")
178+
179+
ctx, span := telemetry.Tracer().Start(
180+
ctx, "controllers.GCPManagedControlPlaneReconciler.reconcile",
181+
)
182+
defer span.End()
183+
157184
log.Info("Reconciling GCPManagedControlPlane")
158185

159186
controllerutil.AddFinalizer(managedControlPlaneScope.GCPManagedControlPlane, infrav1exp.ManagedControlPlaneFinalizer)
@@ -192,6 +219,12 @@ func (r *GCPManagedControlPlaneReconciler) reconcile(ctx context.Context, manage
192219

193220
func (r *GCPManagedControlPlaneReconciler) reconcileDelete(ctx context.Context, managedControlPlaneScope *scope.ManagedControlPlaneScope) (ctrl.Result, error) {
194221
log := log.FromContext(ctx).WithValues("controller", "gcpmanagedcontrolplane", "action", "delete")
222+
223+
ctx, span := telemetry.Tracer().Start(
224+
ctx, "controllers.GCPManagedControlPlaneReconciler.reconcileDelete",
225+
)
226+
defer span.End()
227+
195228
log.Info("Deleting GCPManagedControlPlane")
196229

197230
reconcilers := map[string]cloud.ReconcilerWithResult{

exp/controllers/gcpmanagedmachinepool_controller.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import (
2424
"github.com/go-logr/logr"
2525
"github.com/googleapis/gax-go/v2/apierror"
2626
"github.com/pkg/errors"
27+
"go.opentelemetry.io/otel/attribute"
28+
"go.opentelemetry.io/otel/trace"
2729
"google.golang.org/grpc/codes"
2830
apierrors "k8s.io/apimachinery/pkg/api/errors"
2931
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -41,6 +43,7 @@ import (
4143
"sigs.k8s.io/cluster-api-provider-gcp/cloud/scope"
4244
infrav1exp "sigs.k8s.io/cluster-api-provider-gcp/exp/api/v1beta1"
4345
"sigs.k8s.io/cluster-api-provider-gcp/util/reconciler"
46+
"sigs.k8s.io/cluster-api-provider-gcp/util/telemetry"
4447
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
4548
"sigs.k8s.io/cluster-api/util"
4649
"sigs.k8s.io/cluster-api/util/predicates"
@@ -149,6 +152,14 @@ func managedControlPlaneToManagedMachinePoolMapFunc(c client.Client, gvk schema.
149152
func (r *GCPManagedMachinePoolReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
150153
log := log.FromContext(ctx).WithValues("controller", "GCPManagedMachinePool")
151154

155+
ctx, span := telemetry.Tracer().Start(
156+
ctx, "controllers.GCPManagedMachinePoolReconciler.SetupWithManager",
157+
trace.WithAttributes(
158+
attribute.String("controller", "GCPManagedMachinePool"),
159+
),
160+
)
161+
defer span.End()
162+
152163
gvk, err := apiutil.GVKForObject(new(infrav1exp.GCPManagedMachinePool), mgr.GetScheme())
153164
if err != nil {
154165
return errors.Wrapf(err, "failed to find GVK for GCPManagedMachinePool")
@@ -227,6 +238,16 @@ func (r *GCPManagedMachinePoolReconciler) Reconcile(ctx context.Context, req ctr
227238
ctx, cancel := context.WithTimeout(ctx, reconciler.DefaultedLoopTimeout(r.ReconcileTimeout))
228239
defer cancel()
229240

241+
ctx, span := telemetry.Tracer().Start(
242+
ctx, "controllers.GCPManagedMachinePoolReconciler.Reconcile",
243+
trace.WithAttributes(
244+
attribute.String("name", req.Name),
245+
attribute.String("namespace", req.Namespace),
246+
attribute.String("kind", "GCPManagedMachinePool"),
247+
),
248+
)
249+
defer span.End()
250+
230251
log := ctrl.LoggerFrom(ctx)
231252

232253
// Get the managed machine pool
@@ -318,6 +339,12 @@ func (r *GCPManagedMachinePoolReconciler) Reconcile(ctx context.Context, req ctr
318339

319340
func (r *GCPManagedMachinePoolReconciler) reconcile(ctx context.Context, managedMachinePoolScope *scope.ManagedMachinePoolScope) (ctrl.Result, error) {
320341
log := log.FromContext(ctx).WithValues("controller", "gcpmanagedmachinepool")
342+
343+
ctx, span := telemetry.Tracer().Start(
344+
ctx, "controllers.GCPManagedMachinePoolReconciler.reconcile",
345+
)
346+
defer span.End()
347+
321348
log.Info("Reconciling GCPManagedMachinePool")
322349

323350
controllerutil.AddFinalizer(managedMachinePoolScope.GCPManagedMachinePool, infrav1exp.ManagedMachinePoolFinalizer)
@@ -360,6 +387,12 @@ func (r *GCPManagedMachinePoolReconciler) reconcile(ctx context.Context, managed
360387

361388
func (r *GCPManagedMachinePoolReconciler) reconcileDelete(ctx context.Context, managedMachinePoolScope *scope.ManagedMachinePoolScope) (ctrl.Result, error) {
362389
log := log.FromContext(ctx).WithValues("controller", "gcpmanagedmachinepool", "action", "delete")
390+
391+
ctx, span := telemetry.Tracer().Start(
392+
ctx, "controllers.GCPManagedMachinePoolReconciler.reconcileDelete",
393+
)
394+
defer span.End()
395+
363396
log.Info("Deleting GCPManagedMachinePool")
364397

365398
reconcilers := map[string]cloud.ReconcilerWithResult{

0 commit comments

Comments
 (0)