Skip to content

Commit 46cc901

Browse files
authored
[Refactor] Improved Logging for IdentityServer (#220)
* 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>
1 parent fd0b7a4 commit 46cc901

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

internal/driver/identityserver.go

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,17 @@ import (
2323
"google.golang.org/grpc/codes"
2424
"google.golang.org/grpc/status"
2525
"google.golang.org/protobuf/types/known/wrapperspb"
26-
"k8s.io/klog/v2"
2726
)
2827

28+
// IdentityServer implements the CSI Identity service for the Linode Block Storage CSI Driver.
2929
type IdentityServer struct {
3030
driver *LinodeDriver
3131

3232
csi.UnimplementedIdentityServer
3333
}
3434

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

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

53-
// GetPluginInfo(context.Context, *GetPluginInfoRequest) (*GetPluginInfoResponse, error)
55+
// GetPluginInfo returns information about the CSI plugin.
56+
// This method is REQUIRED for the Identity service as per the CSI spec.
57+
// It returns the name and version of the CSI plugin.
5458
func (linodeIdentity *IdentityServer) GetPluginInfo(ctx context.Context, req *csi.GetPluginInfoRequest) (*csi.GetPluginInfoResponse, error) {
55-
klog.V(5).Infof("Using default GetPluginInfo")
59+
log, _, done := logger.GetLogger(ctx).WithMethod("GetPluginInfo")
60+
defer done()
61+
62+
log.V(2).Info("Processing request")
5663

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

74+
// GetPluginCapabilities returns the capabilities of the CSI plugin.
75+
// This method is REQUIRED for the Identity service as per the CSI spec.
76+
// It informs the CO of the supported features by this plugin.
6777
func (linodeIdentity *IdentityServer) GetPluginCapabilities(ctx context.Context, req *csi.GetPluginCapabilitiesRequest) (*csi.GetPluginCapabilitiesResponse, error) {
68-
klog.V(5).Infof("Using default GetPluginCapabilities")
78+
log, _, done := logger.GetLogger(ctx).WithMethod("GetPluginCapabilities")
79+
defer done()
80+
81+
log.V(2).Info("Processing request")
82+
6983
return &csi.GetPluginCapabilitiesResponse{
7084
Capabilities: []*csi.PluginCapability{
7185
{
@@ -98,8 +112,15 @@ func (linodeIdentity *IdentityServer) GetPluginCapabilities(ctx context.Context,
98112
}, nil
99113
}
100114

115+
// Probe checks if the plugin is ready to serve requests.
116+
// This method is REQUIRED for the Identity service as per the CSI spec.
117+
// It allows the CO to check the readiness of the plugin.
101118
func (linodeIdentity *IdentityServer) Probe(ctx context.Context, req *csi.ProbeRequest) (*csi.ProbeResponse, error) {
102-
klog.V(4).Infof("Probe called with args: %#v", req)
119+
log, _, done := logger.GetLogger(ctx).WithMethod("Probe")
120+
defer done()
121+
122+
log.V(2).Info("Processing request")
123+
103124
linodeIdentity.driver.readyMu.Lock()
104125
defer linodeIdentity.driver.readyMu.Unlock()
105126

0 commit comments

Comments
 (0)