Skip to content

Commit 49c1ea2

Browse files
committed
instrument GCP machine + GCPCluster controllers
1 parent dcfb15b commit 49c1ea2

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed

controllers/gcpcluster_controller.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ import (
2323
"github.com/GoogleCloudPlatform/k8s-cloud-provider/pkg/cloud/filter"
2424
"github.com/GoogleCloudPlatform/k8s-cloud-provider/pkg/cloud/meta"
2525
"github.com/pkg/errors"
26+
"go.opentelemetry.io/otel/attribute"
27+
"go.opentelemetry.io/otel/trace"
2628
apierrors "k8s.io/apimachinery/pkg/api/errors"
2729
infrav1 "sigs.k8s.io/cluster-api-provider-gcp/api/v1beta1"
2830
"sigs.k8s.io/cluster-api-provider-gcp/cloud"
@@ -32,6 +34,7 @@ import (
3234
"sigs.k8s.io/cluster-api-provider-gcp/cloud/services/compute/networks"
3335
"sigs.k8s.io/cluster-api-provider-gcp/cloud/services/compute/subnets"
3436
"sigs.k8s.io/cluster-api-provider-gcp/util/reconciler"
37+
"sigs.k8s.io/cluster-api-provider-gcp/util/telemetry"
3538
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
3639
"sigs.k8s.io/cluster-api/util"
3740
"sigs.k8s.io/cluster-api/util/annotations"
@@ -62,6 +65,14 @@ type GCPClusterReconciler struct {
6265
func (r *GCPClusterReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
6366
log := log.FromContext(ctx).WithValues("controller", "GCPCluster")
6467

68+
ctx, span := telemetry.Tracer().Start(
69+
ctx, "controllers.GCPClusterReconciler.SetupWithManager",
70+
trace.WithAttributes(
71+
attribute.String("controller", "GCPCluster"),
72+
),
73+
)
74+
defer span.End()
75+
6576
c, err := ctrl.NewControllerManagedBy(mgr).
6677
WithOptions(options).
6778
For(&infrav1.GCPCluster{}).
@@ -106,6 +117,17 @@ func (r *GCPClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request)
106117
defer cancel()
107118

108119
log := log.FromContext(ctx)
120+
121+
ctx, span := telemetry.Tracer().Start(
122+
ctx, "controllers.GCPClusterReconciler.Reconcile",
123+
trace.WithAttributes(
124+
attribute.String("name", req.Name),
125+
attribute.String("namespace", req.Namespace),
126+
attribute.String("kind", "GCPCluster"),
127+
),
128+
)
129+
defer span.End()
130+
109131
gcpCluster := &infrav1.GCPCluster{}
110132
err := r.Get(ctx, req.NamespacedName, gcpCluster)
111133
if err != nil {
@@ -161,6 +183,12 @@ func (r *GCPClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request)
161183

162184
func (r *GCPClusterReconciler) reconcile(ctx context.Context, clusterScope *scope.ClusterScope) (ctrl.Result, error) {
163185
log := log.FromContext(ctx)
186+
187+
ctx, span := telemetry.Tracer().Start(
188+
ctx, "controllers.GCPClusterReconciler.reconcile",
189+
)
190+
defer span.End()
191+
164192
log.Info("Reconciling GCPCluster")
165193

166194
controllerutil.AddFinalizer(clusterScope.GCPCluster, infrav1.ClusterFinalizer)
@@ -227,6 +255,12 @@ func (r *GCPClusterReconciler) reconcile(ctx context.Context, clusterScope *scop
227255

228256
func (r *GCPClusterReconciler) reconcileDelete(ctx context.Context, clusterScope *scope.ClusterScope) (ctrl.Result, error) {
229257
log := log.FromContext(ctx)
258+
259+
ctx, span := telemetry.Tracer().Start(
260+
ctx, "controllers.GCPClusterReconciler.reconcileDelete",
261+
)
262+
defer span.End()
263+
230264
log.Info("Reconciling Delete GCPCluster")
231265

232266
reconcilers := []cloud.Reconciler{

controllers/gcpmachine_controller.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,14 @@ import (
2222
"time"
2323

2424
"github.com/pkg/errors"
25+
"go.opentelemetry.io/otel/attribute"
26+
"go.opentelemetry.io/otel/trace"
2527
apierrors "k8s.io/apimachinery/pkg/api/errors"
2628
infrav1 "sigs.k8s.io/cluster-api-provider-gcp/api/v1beta1"
2729
"sigs.k8s.io/cluster-api-provider-gcp/cloud/scope"
2830
"sigs.k8s.io/cluster-api-provider-gcp/cloud/services/compute/instances"
2931
"sigs.k8s.io/cluster-api-provider-gcp/util/reconciler"
32+
"sigs.k8s.io/cluster-api-provider-gcp/util/telemetry"
3033
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
3134
capierrors "sigs.k8s.io/cluster-api/errors"
3235
"sigs.k8s.io/cluster-api/util"
@@ -57,6 +60,15 @@ type GCPMachineReconciler struct {
5760

5861
func (r *GCPMachineReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
5962
log := ctrl.LoggerFrom(ctx)
63+
64+
ctx, span := telemetry.Tracer().Start(
65+
ctx, "controllers.GCPMachineReconciler.SetupWithManager",
66+
trace.WithAttributes(
67+
attribute.String("controller", "GCPMachine"),
68+
),
69+
)
70+
defer span.End()
71+
6072
c, err := ctrl.NewControllerManagedBy(mgr).
6173
WithOptions(options).
6274
For(&infrav1.GCPMachine{}).
@@ -136,6 +148,17 @@ func (r *GCPMachineReconciler) Reconcile(ctx context.Context, req ctrl.Request)
136148
defer cancel()
137149

138150
log := ctrl.LoggerFrom(ctx)
151+
152+
ctx, span := telemetry.Tracer().Start(
153+
ctx, "controllers.GCPMachineReconciler.Reconcile",
154+
trace.WithAttributes(
155+
attribute.String("name", req.Name),
156+
attribute.String("namespace", req.Namespace),
157+
attribute.String("kind", "GCPMachine"),
158+
),
159+
)
160+
defer span.End()
161+
139162
gcpMachine := &infrav1.GCPMachine{}
140163
err := r.Get(ctx, req.NamespacedName, gcpMachine)
141164
if err != nil {
@@ -218,6 +241,12 @@ func (r *GCPMachineReconciler) Reconcile(ctx context.Context, req ctrl.Request)
218241

219242
func (r *GCPMachineReconciler) reconcile(ctx context.Context, machineScope *scope.MachineScope) (ctrl.Result, error) {
220243
log := log.FromContext(ctx)
244+
245+
ctx, span := telemetry.Tracer().Start(
246+
ctx, "controllers.GCPMachineReconciler.reconcile",
247+
)
248+
defer span.End()
249+
221250
log.Info("Reconciling GCPMachine")
222251

223252
controllerutil.AddFinalizer(machineScope.GCPMachine, infrav1.MachineFinalizer)
@@ -252,6 +281,12 @@ func (r *GCPMachineReconciler) reconcile(ctx context.Context, machineScope *scop
252281

253282
func (r *GCPMachineReconciler) reconcileDelete(ctx context.Context, machineScope *scope.MachineScope) (_ ctrl.Result, reterr error) {
254283
log := log.FromContext(ctx)
284+
285+
ctx, span := telemetry.Tracer().Start(
286+
ctx, "controllers.GCPMachineReconciler.reconcileDelete",
287+
)
288+
defer span.End()
289+
255290
log.Info("Reconciling Delete GCPMachine")
256291

257292
if err := instances.New(machineScope).Delete(ctx); err != nil {

0 commit comments

Comments
 (0)