Skip to content

Commit 8fc5b09

Browse files
- added skip observability to avoid nil pointer span creations
1 parent 4376ae5 commit 8fc5b09

File tree

3 files changed

+70
-39
lines changed

3 files changed

+70
-39
lines changed

internal/driver/controllerserver_helper.go

Lines changed: 68 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,10 @@ type VolumeParams struct {
104104
func (cs *ControllerServer) canAttach(ctx context.Context, instance *linodego.Instance) (canAttach bool, err error) {
105105
log := logger.GetLogger(ctx)
106106
log.V(4).Info("Checking if volume can be attached", "instance_id", instance.ID)
107-
_, span := observability.StartFunctionSpan(ctx)
108-
defer span.End()
107+
if !observability.SkipObservability {
108+
_, span := observability.StartFunctionSpan(ctx)
109+
defer span.End()
110+
}
109111

110112
// Get the maximum number of volume attachments allowed for the instance
111113
limit, err := cs.maxAllowedVolumeAttachments(ctx, instance)
@@ -128,8 +130,10 @@ func (cs *ControllerServer) canAttach(ctx context.Context, instance *linodego.In
128130
func (cs *ControllerServer) maxAllowedVolumeAttachments(ctx context.Context, instance *linodego.Instance) (int, error) {
129131
log := logger.GetLogger(ctx)
130132
log.V(4).Info("Calculating max volume attachments")
131-
_, span := observability.StartFunctionSpan(ctx)
132-
defer span.End()
133+
if !observability.SkipObservability {
134+
_, span := observability.StartFunctionSpan(ctx)
135+
defer span.End()
136+
}
133137

134138
// Check if the instance or its specs are nil
135139
if instance == nil || instance.Specs == nil {
@@ -152,8 +156,10 @@ func (cs *ControllerServer) maxAllowedVolumeAttachments(ctx context.Context, ins
152156
func (cs *ControllerServer) getContentSourceVolume(ctx context.Context, contentSource *csi.VolumeContentSource, accessibilityRequirements *csi.TopologyRequirement) (volKey *linodevolumes.LinodeVolumeKey, err error) {
153157
log := logger.GetLogger(ctx)
154158
log.V(4).Info("Attempting to get content source volume")
155-
_, span := observability.StartFunctionSpan(ctx)
156-
defer span.End()
159+
if !observability.SkipObservability {
160+
_, span := observability.StartFunctionSpan(ctx)
161+
defer span.End()
162+
}
157163

158164
if contentSource == nil {
159165
return volKey, nil // Return nil if no content source is provided
@@ -209,8 +215,10 @@ func (cs *ControllerServer) getContentSourceVolume(ctx context.Context, contentS
209215
func (cs *ControllerServer) attemptCreateLinodeVolume(ctx context.Context, label, tags, volumeEncryption string, sizeGB int, sourceVolume *linodevolumes.LinodeVolumeKey, region string) (*linodego.Volume, error) {
210216
log := logger.GetLogger(ctx)
211217
log.V(4).Info("Attempting to create Linode volume", "label", label, "sizeGB", sizeGB, "tags", tags, "encryptionStatus", volumeEncryption, "region", region)
212-
_, span := observability.StartFunctionSpan(ctx)
213-
defer span.End()
218+
if !observability.SkipObservability {
219+
_, span := observability.StartFunctionSpan(ctx)
220+
defer span.End()
221+
}
214222

215223
// List existing volumes with the specified label
216224
jsonFilter, err := json.Marshal(map[string]string{"label": label})
@@ -262,8 +270,10 @@ func getRegionFromTopology(requirements *csi.TopologyRequirement) string {
262270
func (cs *ControllerServer) createLinodeVolume(ctx context.Context, label, tags, encryptionStatus string, sizeGB int, region string) (*linodego.Volume, error) {
263271
log := logger.GetLogger(ctx)
264272
log.V(4).Info("Creating Linode volume", "label", label, "sizeGB", sizeGB, "tags", tags, "encryptionStatus", encryptionStatus, "region", region)
265-
_, span := observability.StartFunctionSpan(ctx)
266-
defer span.End()
273+
if !observability.SkipObservability {
274+
_, span := observability.StartFunctionSpan(ctx)
275+
defer span.End()
276+
}
267277

268278
// Prepare the volume creation request with region, label, and size.
269279
volumeReq := linodego.VolumeCreateOptions{
@@ -293,8 +303,10 @@ func (cs *ControllerServer) createLinodeVolume(ctx context.Context, label, tags,
293303
func (cs *ControllerServer) isEncryptionSupported(ctx context.Context, region string) (bool, error) {
294304
log := logger.GetLogger(ctx)
295305
log.V(4).Info("Checking if encryption is supported for region", "region", region)
296-
_, span := observability.StartFunctionSpan(ctx)
297-
defer span.End()
306+
if !observability.SkipObservability {
307+
_, span := observability.StartFunctionSpan(ctx)
308+
defer span.End()
309+
}
298310

299311
// Get the specifications of specified region from Linode API
300312
regionDetails, err := cs.client.GetRegion(ctx, region)
@@ -319,8 +331,10 @@ func (cs *ControllerServer) isEncryptionSupported(ctx context.Context, region st
319331
func (cs *ControllerServer) cloneLinodeVolume(ctx context.Context, label string, sourceID int) (*linodego.Volume, error) {
320332
log := logger.GetLogger(ctx)
321333
log.V(4).Info("Cloning Linode volume", "label", label, "source_vol_id", sourceID)
322-
_, span := observability.StartFunctionSpan(ctx)
323-
defer span.End()
334+
if !observability.SkipObservability {
335+
_, span := observability.StartFunctionSpan(ctx)
336+
defer span.End()
337+
}
324338

325339
result, err := cs.client.CloneVolume(ctx, sourceID, label)
326340
if err != nil {
@@ -423,8 +437,10 @@ func (cs *ControllerServer) validateCreateVolumeRequest(ctx context.Context, req
423437
log := logger.GetLogger(ctx)
424438
log.V(4).Info("Entering validateCreateVolumeRequest()", "req", req)
425439
defer log.V(4).Info("Exiting validateCreateVolumeRequest()")
426-
_, span := observability.StartFunctionSpan(ctx)
427-
defer span.End()
440+
if !observability.SkipObservability {
441+
_, span := observability.StartFunctionSpan(ctx)
442+
defer span.End()
443+
}
428444

429445
// Check if the volume name is empty; if so, return an error indicating no volume name was provided.
430446
if req.GetName() == "" {
@@ -453,8 +469,10 @@ func (cs *ControllerServer) prepareVolumeParams(ctx context.Context, req *csi.Cr
453469
log := logger.GetLogger(ctx)
454470
log.V(4).Info("Entering prepareVolumeParams()", "req", req)
455471
defer log.V(4).Info("Exiting prepareVolumeParams()")
456-
_, span := observability.StartFunctionSpan(ctx)
457-
defer span.End()
472+
if !observability.SkipObservability {
473+
_, span := observability.StartFunctionSpan(ctx)
474+
defer span.End()
475+
}
458476

459477
// By default, encryption is disabled
460478
encryptionStatus := "disabled"
@@ -514,8 +532,10 @@ func (cs *ControllerServer) createVolumeContext(ctx context.Context, req *csi.Cr
514532
log := logger.GetLogger(ctx)
515533
log.V(4).Info("Entering createVolumeContext()", "req", req)
516534
defer log.V(4).Info("Exiting createVolumeContext()")
517-
_, span := observability.StartFunctionSpan(ctx)
518-
defer span.End()
535+
if !observability.SkipObservability {
536+
_, span := observability.StartFunctionSpan(ctx)
537+
defer span.End()
538+
}
519539

520540
volumeContext := make(map[string]string)
521541

@@ -538,8 +558,10 @@ func (cs *ControllerServer) createAndWaitForVolume(ctx context.Context, name str
538558
log := logger.GetLogger(ctx)
539559
log.V(4).Info("Entering createAndWaitForVolume()", "name", name, "sizeGB", sizeGB, "tags", parameters[VolumeTags], "encryptionStatus", encryptionStatus, "region", region)
540560
defer log.V(4).Info("Exiting createAndWaitForVolume()")
541-
_, span := observability.StartFunctionSpan(ctx)
542-
defer span.End()
561+
if !observability.SkipObservability {
562+
_, span := observability.StartFunctionSpan(ctx)
563+
defer span.End()
564+
}
543565

544566
vol, err := cs.attemptCreateLinodeVolume(ctx, name, parameters[VolumeTags], encryptionStatus, sizeGB, sourceInfo, region)
545567
if err != nil {
@@ -574,8 +596,10 @@ func (cs *ControllerServer) prepareCreateVolumeResponse(ctx context.Context, vol
574596
log := logger.GetLogger(ctx)
575597
log.V(4).Info("Entering prepareCreateVolumeResponse()", "vol", vol)
576598
defer log.V(4).Info("Exiting prepareCreateVolumeResponse()")
577-
_, span := observability.StartFunctionSpan(ctx)
578-
defer span.End()
599+
if !observability.SkipObservability {
600+
_, span := observability.StartFunctionSpan(ctx)
601+
defer span.End()
602+
}
579603

580604
key := linodevolumes.CreateLinodeVolumeKey(vol.ID, vol.Label)
581605
resp := &csi.CreateVolumeResponse{
@@ -614,8 +638,10 @@ func (cs *ControllerServer) validateControllerPublishVolumeRequest(ctx context.C
614638
log := logger.GetLogger(ctx)
615639
log.V(4).Info("Entering validateControllerPublishVolumeRequest()", "req", req)
616640
defer log.V(4).Info("Exiting validateControllerPublishVolumeRequest()")
617-
_, span := observability.StartFunctionSpan(ctx)
618-
defer span.End()
641+
if !observability.SkipObservability {
642+
_, span := observability.StartFunctionSpan(ctx)
643+
defer span.End()
644+
}
619645

620646
// extract the linode ID from the request
621647
linodeID, err = linodevolumes.NodeIdAsInt("ControllerPublishVolume", req)
@@ -659,8 +685,10 @@ func (cs *ControllerServer) getAndValidateVolume(ctx context.Context, volumeID i
659685
log := logger.GetLogger(ctx)
660686
log.V(4).Info("Entering getAndValidateVolume()", "volumeID", volumeID, "linodeID", instance.ID)
661687
defer log.V(4).Info("Exiting getAndValidateVolume()")
662-
_, span := observability.StartFunctionSpan(ctx)
663-
defer span.End()
688+
if !observability.SkipObservability {
689+
_, span := observability.StartFunctionSpan(ctx)
690+
defer span.End()
691+
}
664692

665693
volume, err := cs.client.GetVolume(ctx, volumeID)
666694
if linodego.IsNotFound(err) {
@@ -694,8 +722,10 @@ func (cs *ControllerServer) getInstance(ctx context.Context, linodeID int) (*lin
694722
log := logger.GetLogger(ctx)
695723
log.V(4).Info("Entering getInstance()", "linodeID", linodeID)
696724
defer log.V(4).Info("Exiting getInstance()")
697-
_, span := observability.StartFunctionSpan(ctx)
698-
defer span.End()
725+
if !observability.SkipObservability {
726+
_, span := observability.StartFunctionSpan(ctx)
727+
defer span.End()
728+
}
699729

700730
instance, err := cs.client.GetInstance(ctx, linodeID)
701731
if linodego.IsNotFound(err) {
@@ -718,8 +748,10 @@ func (cs *ControllerServer) checkAttachmentCapacity(ctx context.Context, instanc
718748
log := logger.GetLogger(ctx)
719749
log.V(4).Info("Entering checkAttachmentCapacity()", "linodeID", instance.ID)
720750
defer log.V(4).Info("Exiting checkAttachmentCapacity()")
721-
_, span := observability.StartFunctionSpan(ctx)
722-
defer span.End()
751+
if !observability.SkipObservability {
752+
_, span := observability.StartFunctionSpan(ctx)
753+
defer span.End()
754+
}
723755

724756
canAttach, err := cs.canAttach(ctx, instance)
725757
if err != nil {
@@ -746,8 +778,10 @@ func (cs *ControllerServer) attachVolume(ctx context.Context, volumeID, linodeID
746778
log := logger.GetLogger(ctx)
747779
log.V(4).Info("Entering attachVolume()", "volume_id", volumeID, "node_id", linodeID)
748780
defer log.V(4).Info("Exiting attachVolume()")
749-
_, span := observability.StartFunctionSpan(ctx)
750-
defer span.End()
781+
if !observability.SkipObservability {
782+
_, span := observability.StartFunctionSpan(ctx)
783+
defer span.End()
784+
}
751785

752786
persist := false
753787
_, err := cs.client.AttachVolume(ctx, volumeID, &linodego.VolumeAttachOptions{

internal/driver/driver.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ func (linodeDriver *LinodeDriver) SetupLinodeDriver(
144144

145145
if linodeDriver.enableTracing == True {
146146
observability.InitTracer(ctx, "linode-csi-driver", linodeDriver.vendorVersion, linodeDriver.tracingPort)
147+
observability.SkipObservability = false
147148
}
148149

149150
log.V(2).Info("LinodeDriver setup completed successfully")

pkg/observability/tracker.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
var (
2323
Tracer tracer.Tracer
2424
TracerProvider *trace.TracerProvider
25-
SkipObservability bool
25+
SkipObservability = true
2626
)
2727

2828
// InitOtelTracing initializes the OpenTelemetry tracing and returns an exporter.
@@ -153,10 +153,6 @@ func UnaryServerInterceptorWithParams() grpc.UnaryServerInterceptor {
153153

154154
// StartFunctionSpan creates a tracing span using the calling function's name
155155
func StartFunctionSpan(ctx context.Context) (context.Context, tracer.Span) {
156-
if SkipObservability {
157-
return ctx, nil
158-
}
159-
160156
// Get the name of the current function
161157
pc, file, line, ok := runtime.Caller(1) // Retrieve all outputs
162158

0 commit comments

Comments
 (0)