Skip to content

Commit 2213873

Browse files
meobilivangrichardcase
authored andcommitted
instrument GCP machine + GCPCluster controllers
1 parent f899af8 commit 2213873

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)
@@ -228,6 +256,12 @@ func (r *GCPClusterReconciler) reconcile(ctx context.Context, clusterScope *scop
228256

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

233267
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
"sigs.k8s.io/cluster-api/util"
3235
"sigs.k8s.io/cluster-api/util/annotations"
@@ -56,6 +59,15 @@ type GCPMachineReconciler struct {
5659

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

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

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

222251
controllerutil.AddFinalizer(machineScope.GCPMachine, infrav1.MachineFinalizer)
@@ -251,6 +280,12 @@ func (r *GCPMachineReconciler) reconcile(ctx context.Context, machineScope *scop
251280

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

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

0 commit comments

Comments
 (0)