@@ -23,11 +23,17 @@ import (
23
23
"google.golang.org/api/compute/v1"
24
24
"k8s.io/utils/pointer"
25
25
"sigs.k8s.io/cluster-api-provider-gcp/cloud/gcperrors"
26
+ "sigs.k8s.io/cluster-api-provider-gcp/util/telemetry"
26
27
"sigs.k8s.io/controller-runtime/pkg/log"
27
28
)
28
29
29
30
// Reconcile reconcile cluster control-plane loadbalancer compoenents.
30
31
func (s * Service ) Reconcile (ctx context.Context ) error {
32
+ ctx , span := telemetry .Tracer ().Start (
33
+ ctx , "loadbalancers.Services.Reconcile" ,
34
+ )
35
+ defer span .End ()
36
+
31
37
log := log .FromContext (ctx )
32
38
log .Info ("Reconciling loadbalancer resources" )
33
39
instancegroups , err := s .createOrGetInstanceGroups (ctx )
@@ -60,6 +66,11 @@ func (s *Service) Reconcile(ctx context.Context) error {
60
66
61
67
// Delete delete cluster control-plane loadbalancer compoenents.
62
68
func (s * Service ) Delete (ctx context.Context ) error {
69
+ ctx , span := telemetry .Tracer ().Start (
70
+ ctx , "loadbalancers.Services.Delete" ,
71
+ )
72
+ defer span .End ()
73
+
63
74
log := log .FromContext (ctx )
64
75
log .Info ("Deleting loadbalancer resources" )
65
76
if err := s .deleteForwardingRule (ctx ); err != nil {
@@ -86,6 +97,11 @@ func (s *Service) Delete(ctx context.Context) error {
86
97
}
87
98
88
99
func (s * Service ) createOrGetInstanceGroups (ctx context.Context ) ([]* compute.InstanceGroup , error ) {
100
+ ctx , span := telemetry .Tracer ().Start (
101
+ ctx , "loadbalancers.Services.createOrGetInstanceGroups" ,
102
+ )
103
+ defer span .End ()
104
+
89
105
log := log .FromContext (ctx )
90
106
fd := s .scope .FailureDomains ()
91
107
zones := make ([]string , 0 , len (fd ))
@@ -130,6 +146,11 @@ func (s *Service) createOrGetInstanceGroups(ctx context.Context) ([]*compute.Ins
130
146
}
131
147
132
148
func (s * Service ) createOrGetHealthCheck (ctx context.Context ) (* compute.HealthCheck , error ) {
149
+ ctx , span := telemetry .Tracer ().Start (
150
+ ctx , "loadbalancers.Services.createOrGetHealthCheck" ,
151
+ )
152
+ defer span .End ()
153
+
133
154
log := log .FromContext (ctx )
134
155
healthcheckSpec := s .scope .HealthCheckSpec ()
135
156
log .V (2 ).Info ("Looking for healthcheck" , "name" , healthcheckSpec .Name )
@@ -157,6 +178,11 @@ func (s *Service) createOrGetHealthCheck(ctx context.Context) (*compute.HealthCh
157
178
}
158
179
159
180
func (s * Service ) createOrGetBackendService (ctx context.Context , instancegroups []* compute.InstanceGroup , healthcheck * compute.HealthCheck ) (* compute.BackendService , error ) {
181
+ ctx , span := telemetry .Tracer ().Start (
182
+ ctx , "loadbalancers.Services.createOrGetBackendService" ,
183
+ )
184
+ defer span .End ()
185
+
160
186
log := log .FromContext (ctx )
161
187
backends := make ([]* compute.Backend , 0 , len (instancegroups ))
162
188
for _ , group := range instancegroups {
@@ -202,6 +228,11 @@ func (s *Service) createOrGetBackendService(ctx context.Context, instancegroups
202
228
}
203
229
204
230
func (s * Service ) createOrGetTargetTCPProxy (ctx context.Context , service * compute.BackendService ) (* compute.TargetTcpProxy , error ) {
231
+ ctx , span := telemetry .Tracer ().Start (
232
+ ctx , "loadbalancers.Services.createOrGetTargetTCPProxy" ,
233
+ )
234
+ defer span .End ()
235
+
205
236
log := log .FromContext (ctx )
206
237
targetSpec := s .scope .TargetTCPProxySpec ()
207
238
targetSpec .Service = service .SelfLink
@@ -229,6 +260,11 @@ func (s *Service) createOrGetTargetTCPProxy(ctx context.Context, service *comput
229
260
}
230
261
231
262
func (s * Service ) createOrGetAddress (ctx context.Context ) (* compute.Address , error ) {
263
+ ctx , span := telemetry .Tracer ().Start (
264
+ ctx , "loadbalancers.Services.createOrGetAddress" ,
265
+ )
266
+ defer span .End ()
267
+
232
268
log := log .FromContext (ctx )
233
269
addrSpec := s .scope .AddressSpec ()
234
270
log .V (2 ).Info ("Looking for address" , "name" , addrSpec .Name )
@@ -259,6 +295,11 @@ func (s *Service) createOrGetAddress(ctx context.Context) (*compute.Address, err
259
295
}
260
296
261
297
func (s * Service ) createForwardingRule (ctx context.Context , target * compute.TargetTcpProxy , addr * compute.Address ) error {
298
+ ctx , span := telemetry .Tracer ().Start (
299
+ ctx , "loadbalancers.Services.createForwardingRule" ,
300
+ )
301
+ defer span .End ()
302
+
262
303
log := log .FromContext (ctx )
263
304
spec := s .scope .ForwardingRuleSpec ()
264
305
key := meta .GlobalKey (spec .Name )
@@ -289,6 +330,11 @@ func (s *Service) createForwardingRule(ctx context.Context, target *compute.Targ
289
330
}
290
331
291
332
func (s * Service ) deleteForwardingRule (ctx context.Context ) error {
333
+ ctx , span := telemetry .Tracer ().Start (
334
+ ctx , "loadbalancers.Services.deleteForwardingRule" ,
335
+ )
336
+ defer span .End ()
337
+
292
338
log := log .FromContext (ctx )
293
339
spec := s .scope .ForwardingRuleSpec ()
294
340
key := meta .GlobalKey (spec .Name )
@@ -303,6 +349,11 @@ func (s *Service) deleteForwardingRule(ctx context.Context) error {
303
349
}
304
350
305
351
func (s * Service ) deleteAddress (ctx context.Context ) error {
352
+ ctx , span := telemetry .Tracer ().Start (
353
+ ctx , "loadbalancers.Services.deleteAddress" ,
354
+ )
355
+ defer span .End ()
356
+
306
357
log := log .FromContext (ctx )
307
358
spec := s .scope .AddressSpec ()
308
359
key := meta .GlobalKey (spec .Name )
@@ -316,6 +367,11 @@ func (s *Service) deleteAddress(ctx context.Context) error {
316
367
}
317
368
318
369
func (s * Service ) deleteTargetTCPProxy (ctx context.Context ) error {
370
+ ctx , span := telemetry .Tracer ().Start (
371
+ ctx , "loadbalancers.Services.deleteTargetTCPProxy" ,
372
+ )
373
+ defer span .End ()
374
+
319
375
log := log .FromContext (ctx )
320
376
spec := s .scope .TargetTCPProxySpec ()
321
377
key := meta .GlobalKey (spec .Name )
@@ -330,6 +386,11 @@ func (s *Service) deleteTargetTCPProxy(ctx context.Context) error {
330
386
}
331
387
332
388
func (s * Service ) deleteBackendService (ctx context.Context ) error {
389
+ ctx , span := telemetry .Tracer ().Start (
390
+ ctx , "loadbalancers.Services.deleteBackendService" ,
391
+ )
392
+ defer span .End ()
393
+
333
394
log := log .FromContext (ctx )
334
395
spec := s .scope .BackendServiceSpec ()
335
396
key := meta .GlobalKey (spec .Name )
@@ -344,6 +405,11 @@ func (s *Service) deleteBackendService(ctx context.Context) error {
344
405
}
345
406
346
407
func (s * Service ) deleteHealthCheck (ctx context.Context ) error {
408
+ ctx , span := telemetry .Tracer ().Start (
409
+ ctx , "loadbalancers.Services.deleteHealthCheck" ,
410
+ )
411
+ defer span .End ()
412
+
347
413
log := log .FromContext (ctx )
348
414
spec := s .scope .HealthCheckSpec ()
349
415
key := meta .GlobalKey (spec .Name )
@@ -358,6 +424,11 @@ func (s *Service) deleteHealthCheck(ctx context.Context) error {
358
424
}
359
425
360
426
func (s * Service ) deleteInstanceGroups (ctx context.Context ) error {
427
+ ctx , span := telemetry .Tracer ().Start (
428
+ ctx , "loadbalancers.Services.deleteInstanceGroups" ,
429
+ )
430
+ defer span .End ()
431
+
361
432
log := log .FromContext (ctx )
362
433
for zone := range s .scope .Network ().APIServerInstanceGroups {
363
434
spec := s .scope .InstanceGroupSpec (zone )
0 commit comments