Skip to content

Commit

Permalink
[Refactor] Improved Logging for IdentityServer (#220)
Browse files Browse the repository at this point in the history
* Improve logging for IdentityServer:
- Add comments for IdentityServer struct and methods
- Implement structured logging using logger.GetLogger
- Remove dependency on k8s.io/klog/v2
- Add log entries for request processing
---------

Co-authored-by: Khaja Omer <komer@akamai.com>
  • Loading branch information
komer3 and Khaja Omer authored Sep 9, 2024
1 parent fd0b7a4 commit 46cc901
Showing 1 changed file with 26 additions and 5 deletions.
31 changes: 26 additions & 5 deletions internal/driver/identityserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,17 @@ import (
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/types/known/wrapperspb"
"k8s.io/klog/v2"
)

// IdentityServer implements the CSI Identity service for the Linode Block Storage CSI Driver.
type IdentityServer struct {
driver *LinodeDriver

csi.UnimplementedIdentityServer
}

// NewIdentityServer creates and initializes a new IdentityServer.
// It takes a context and a LinodeDriver as input and returns a pointer to IdentityServer and an error.
func NewIdentityServer(ctx context.Context, linodeDriver *LinodeDriver) (*IdentityServer, error) {
log := logger.GetLogger(ctx)

Expand All @@ -50,9 +52,14 @@ func NewIdentityServer(ctx context.Context, linodeDriver *LinodeDriver) (*Identi
return identityServer, nil
}

// GetPluginInfo(context.Context, *GetPluginInfoRequest) (*GetPluginInfoResponse, error)
// GetPluginInfo returns information about the CSI plugin.
// This method is REQUIRED for the Identity service as per the CSI spec.
// It returns the name and version of the CSI plugin.
func (linodeIdentity *IdentityServer) GetPluginInfo(ctx context.Context, req *csi.GetPluginInfoRequest) (*csi.GetPluginInfoResponse, error) {
klog.V(5).Infof("Using default GetPluginInfo")
log, _, done := logger.GetLogger(ctx).WithMethod("GetPluginInfo")
defer done()

log.V(2).Info("Processing request")

if linodeIdentity.driver.name == "" {
return nil, status.Error(codes.Unavailable, "Driver name not configured")
Expand All @@ -64,8 +71,15 @@ func (linodeIdentity *IdentityServer) GetPluginInfo(ctx context.Context, req *cs
}, nil
}

// GetPluginCapabilities returns the capabilities of the CSI plugin.
// This method is REQUIRED for the Identity service as per the CSI spec.
// It informs the CO of the supported features by this plugin.
func (linodeIdentity *IdentityServer) GetPluginCapabilities(ctx context.Context, req *csi.GetPluginCapabilitiesRequest) (*csi.GetPluginCapabilitiesResponse, error) {
klog.V(5).Infof("Using default GetPluginCapabilities")
log, _, done := logger.GetLogger(ctx).WithMethod("GetPluginCapabilities")
defer done()

log.V(2).Info("Processing request")

return &csi.GetPluginCapabilitiesResponse{
Capabilities: []*csi.PluginCapability{
{
Expand Down Expand Up @@ -98,8 +112,15 @@ func (linodeIdentity *IdentityServer) GetPluginCapabilities(ctx context.Context,
}, nil
}

// Probe checks if the plugin is ready to serve requests.
// This method is REQUIRED for the Identity service as per the CSI spec.
// It allows the CO to check the readiness of the plugin.
func (linodeIdentity *IdentityServer) Probe(ctx context.Context, req *csi.ProbeRequest) (*csi.ProbeResponse, error) {
klog.V(4).Infof("Probe called with args: %#v", req)
log, _, done := logger.GetLogger(ctx).WithMethod("Probe")
defer done()

log.V(2).Info("Processing request")

linodeIdentity.driver.readyMu.Lock()
defer linodeIdentity.driver.readyMu.Unlock()

Expand Down

0 comments on commit 46cc901

Please sign in to comment.