Skip to content

Commit 58d7ed6

Browse files
authored
[Refactor] Adding structured logging to Nodeserver (#218)
* Implement structured logging and improve error handling - Add Logger struct with context-aware logging methods - Refactor NodeServer methods to use structured logging - Update main.go to initialize and use the new logger - Adjust unit tests to accommodate new logging structure --------- Co-authored-by: Khaja Omer <komer@akamai.com>
1 parent 767dd67 commit 58d7ed6

15 files changed

+329
-131
lines changed

go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ go 1.22.5
44

55
require (
66
github.com/container-storage-interface/spec v1.10.0
7+
github.com/go-logr/logr v1.4.1
8+
github.com/google/uuid v1.6.0
79
github.com/ianschenck/envflag v0.0.0-20140720210342-9111d830d133
810
github.com/linode/go-metadata v0.2.0
911
github.com/linode/linodego v1.35.0
@@ -19,7 +21,6 @@ require (
1921
)
2022

2123
require (
22-
github.com/go-logr/logr v1.4.1 // indirect
2324
github.com/go-resty/resty/v2 v2.13.1 // indirect
2425
github.com/moby/sys/mountinfo v0.6.2 // indirect
2526
golang.org/x/text v0.16.0 // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeN
5353
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
5454
github.com/google/gofuzz v1.1.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
5555
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
56+
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
57+
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
5658
github.com/googleapis/gnostic v0.4.1/go.mod h1:LRhVm6pbyptWbWbuZ38d1eyptfvIytN3ir6b65WBswg=
5759
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
5860
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=

internal/driver/controllerserver.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ func (cs *ControllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
230230
}
231231

232232
klog.V(4).Infoln("[CreateVolume] volume created successfully", map[string]interface{}{
233-
"response": resp,
233+
"response": resp,
234234
})
235235
return resp, nil
236236
}

internal/driver/driver.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ limitations under the License.
1515
*/
1616

1717
import (
18+
"context"
1819
"errors"
1920
"fmt"
2021
"regexp"
@@ -24,10 +25,10 @@ import (
2425
"github.com/container-storage-interface/spec/lib/go/csi"
2526
linodeclient "github.com/linode/linode-blockstorage-csi-driver/pkg/linode-client"
2627

28+
"github.com/linode/linode-blockstorage-csi-driver/pkg/logger"
2729
mountmanager "github.com/linode/linode-blockstorage-csi-driver/pkg/mount-manager"
2830
"google.golang.org/grpc/codes"
2931
"google.golang.org/grpc/status"
30-
"k8s.io/klog/v2"
3132
"k8s.io/mount-utils"
3233
)
3334

@@ -106,7 +107,7 @@ func (linodeDriver *LinodeDriver) SetupLinodeDriver(
106107
if err != nil {
107108
return fmt.Errorf("new node server: %w", err)
108109
}
109-
110+
110111
linodeDriver.ids, err = NewIdentityServer(linodeDriver)
111112
if err != nil {
112113
return fmt.Errorf("new identity server: %w", err)
@@ -135,10 +136,11 @@ func (linodeDriver *LinodeDriver) ValidateControllerServiceRequest(c csi.Control
135136
return status.Error(codes.InvalidArgument, "Invalid controller service request")
136137
}
137138

138-
func (linodeDriver *LinodeDriver) Run(endpoint string) {
139-
klog.V(4).Infof("Driver: %v", linodeDriver.name)
139+
func (linodeDriver *LinodeDriver) Run(ctx context.Context, endpoint string) {
140+
log := logger.GetLogger(ctx)
141+
log.V(4).Info("Driver", "name", linodeDriver.name)
140142
if len(linodeDriver.volumeLabelPrefix) > 0 {
141-
klog.V(4).Infof("BS Volume Prefix: %v", linodeDriver.volumeLabelPrefix)
143+
log.V(4).Info("BS Volume Prefix", "prefix", linodeDriver.volumeLabelPrefix)
142144
}
143145

144146
linodeDriver.readyMu.Lock()

internal/driver/driver_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package driver
22

33
import (
4+
"context"
45
"fmt"
56
"net/http/httptest"
67
"os"
@@ -53,8 +54,8 @@ func TestDriverSuite(t *testing.T) {
5354
defer mockCtrl.Finish()
5455

5556
mounter := &mount.SafeFormatAndMount{
56-
Interface: mocks.NewMockMounter(mockCtrl),
57-
Exec: mocks.NewMockExecutor(mockCtrl),
57+
Interface: mocks.NewMockMounter(mockCtrl),
58+
Exec: mocks.NewMockExecutor(mockCtrl),
5859
}
5960
deviceUtils := mocks.NewMockDeviceUtils(mockCtrl)
6061
fileSystem := mocks.NewMockFileSystem(mockCtrl)
@@ -77,11 +78,10 @@ func TestDriverSuite(t *testing.T) {
7778
t.Fatalf("Failed to setup Linode Driver: %v", err)
7879
}
7980

80-
go linodeDriver.Run(endpoint)
81+
go linodeDriver.Run(context.Background(), endpoint)
8182

8283
// TODO: fix sanity checks for e2e, disable for ci
8384
// cfg := sanity.NewTestConfig()
8485
// cfg.Address = endpoint
8586
// sanity.Test(t, cfg)
8687
}
87-

internal/driver/identityserver.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func (linodeIdentity *IdentityServer) GetPluginCapabilities(ctx context.Context,
8080
// 2. Delete and recreate the pod that is using the PVC(or scale replicas accordingly)
8181
// 3. This operation should detach and re-attach the volume to the newly created pod allowing you to use the updated size
8282
VolumeExpansion: &csi.PluginCapability_VolumeExpansion{
83-
Type: csi.PluginCapability_VolumeExpansion_OFFLINE,
83+
Type: csi.PluginCapability_VolumeExpansion_ONLINE,
8484
},
8585
},
8686
},

0 commit comments

Comments
 (0)