@@ -23,6 +23,7 @@ import (
23
23
24
24
"sigs.k8s.io/cluster-api-provider-gcp/cloud"
25
25
"sigs.k8s.io/cluster-api-provider-gcp/util/resourceurl"
26
+ "sigs.k8s.io/cluster-api-provider-gcp/util/telemetry"
26
27
27
28
"google.golang.org/api/iterator"
28
29
"google.golang.org/grpc/codes"
@@ -45,6 +46,11 @@ import (
45
46
46
47
// Reconcile reconcile GKE node pool.
47
48
func (s * Service ) Reconcile (ctx context.Context ) (ctrl.Result , error ) {
49
+ ctx , span := telemetry .Tracer ().Start (
50
+ ctx , "nodepools.Services.Reconcile" ,
51
+ )
52
+ defer span .End ()
53
+
48
54
log := log .FromContext (ctx )
49
55
log .Info ("Reconciling node pool resources" )
50
56
@@ -180,6 +186,11 @@ func (s *Service) Reconcile(ctx context.Context) (ctrl.Result, error) {
180
186
181
187
// Delete delete GKE node pool.
182
188
func (s * Service ) Delete (ctx context.Context ) (ctrl.Result , error ) {
189
+ ctx , span := telemetry .Tracer ().Start (
190
+ ctx , "nodepools.Services.Delete" ,
191
+ )
192
+ defer span .End ()
193
+
183
194
log := log .FromContext (ctx )
184
195
log .Info ("Deleting node pool resources" )
185
196
@@ -223,6 +234,11 @@ func (s *Service) Delete(ctx context.Context) (ctrl.Result, error) {
223
234
}
224
235
225
236
func (s * Service ) describeNodePool (ctx context.Context , log * logr.Logger ) (* containerpb.NodePool , error ) {
237
+ ctx , span := telemetry .Tracer ().Start (
238
+ ctx , "nodepools.Services.describeNodePool" ,
239
+ )
240
+ defer span .End ()
241
+
226
242
getNodePoolRequest := & containerpb.GetNodePoolRequest {
227
243
Name : s .scope .NodePoolFullName (),
228
244
}
@@ -242,6 +258,11 @@ func (s *Service) describeNodePool(ctx context.Context, log *logr.Logger) (*cont
242
258
}
243
259
244
260
func (s * Service ) getInstances (ctx context.Context , nodePool * containerpb.NodePool ) ([]* computepb.ManagedInstance , error ) {
261
+ ctx , span := telemetry .Tracer ().Start (
262
+ ctx , "nodepools.Services.getInstances" ,
263
+ )
264
+ defer span .End ()
265
+
245
266
instances := []* computepb.ManagedInstance {}
246
267
247
268
for _ , url := range nodePool .InstanceGroupUrls {
@@ -271,6 +292,11 @@ func (s *Service) getInstances(ctx context.Context, nodePool *containerpb.NodePo
271
292
}
272
293
273
294
func (s * Service ) createNodePool (ctx context.Context , log * logr.Logger ) error {
295
+ ctx , span := telemetry .Tracer ().Start (
296
+ ctx , "nodepools.Services.createNodePool" ,
297
+ )
298
+ defer span .End ()
299
+
274
300
log .V (2 ).Info ("Running pre-flight checks on machine pool before creation" )
275
301
if err := shared .ManagedMachinePoolPreflightCheck (s .scope .GCPManagedMachinePool , s .scope .MachinePool , s .scope .Region ()); err != nil {
276
302
return fmt .Errorf ("preflight checks on machine pool before creating: %w" , err )
@@ -291,6 +317,11 @@ func (s *Service) createNodePool(ctx context.Context, log *logr.Logger) error {
291
317
}
292
318
293
319
func (s * Service ) updateNodePoolVersionOrImage (ctx context.Context , updateNodePoolRequest * containerpb.UpdateNodePoolRequest ) error {
320
+ ctx , span := telemetry .Tracer ().Start (
321
+ ctx , "nodepools.Services.updateNodePoolVersionOrImage" ,
322
+ )
323
+ defer span .End ()
324
+
294
325
_ , err := s .scope .ManagedMachinePoolClient ().UpdateNodePool (ctx , updateNodePoolRequest )
295
326
if err != nil {
296
327
return err
@@ -300,6 +331,11 @@ func (s *Service) updateNodePoolVersionOrImage(ctx context.Context, updateNodePo
300
331
}
301
332
302
333
func (s * Service ) updateNodePoolAutoscaling (ctx context.Context , setNodePoolAutoscalingRequest * containerpb.SetNodePoolAutoscalingRequest ) error {
334
+ ctx , span := telemetry .Tracer ().Start (
335
+ ctx , "nodepools.Services.updateNodePoolAutoScaling" ,
336
+ )
337
+ defer span .End ()
338
+
303
339
_ , err := s .scope .ManagedMachinePoolClient ().SetNodePoolAutoscaling (ctx , setNodePoolAutoscalingRequest )
304
340
if err != nil {
305
341
return err
@@ -309,6 +345,11 @@ func (s *Service) updateNodePoolAutoscaling(ctx context.Context, setNodePoolAuto
309
345
}
310
346
311
347
func (s * Service ) updateNodePoolSize (ctx context.Context , setNodePoolSizeRequest * containerpb.SetNodePoolSizeRequest ) error {
348
+ ctx , span := telemetry .Tracer ().Start (
349
+ ctx , "nodepools.Services.updateNodePoolSize" ,
350
+ )
351
+ defer span .End ()
352
+
312
353
_ , err := s .scope .ManagedMachinePoolClient ().SetNodePoolSize (ctx , setNodePoolSizeRequest )
313
354
if err != nil {
314
355
return err
0 commit comments