From a00ac7de0894b9f6d3540ad8b4a69a9307464474 Mon Sep 17 00:00:00 2001 From: Ashima-Ashima1 Date: Thu, 23 May 2024 09:07:10 +0530 Subject: [PATCH 01/10] fetch stats after time interval Signed-off-by: Ashima-Ashima1 --- .secrets.baseline | 2 +- pkg/driver/nodeserver.go | 110 ++++++++++++++++++++++++++++----------- 2 files changed, 81 insertions(+), 31 deletions(-) diff --git a/.secrets.baseline b/.secrets.baseline index 47b4853b..5f21888a 100644 --- a/.secrets.baseline +++ b/.secrets.baseline @@ -3,7 +3,7 @@ "files": "go.sum|^.secrets.baseline$", "lines": null }, - "generated_at": "2024-05-21T09:58:56Z", + "generated_at": "2024-05-22T07:40:17Z", "plugins_used": [ { "name": "AWSKeyDetector" diff --git a/pkg/driver/nodeserver.go b/pkg/driver/nodeserver.go index 8151d1b5..25eb1f9f 100644 --- a/pkg/driver/nodeserver.go +++ b/pkg/driver/nodeserver.go @@ -12,6 +12,7 @@ package driver import ( "fmt" + "time" "github.com/IBM/ibm-object-csi-driver/pkg/constants" "github.com/IBM/ibm-object-csi-driver/pkg/mounter" @@ -186,6 +187,9 @@ func (ns *nodeServer) NodeGetVolumeStats(_ context.Context, req *csi.NodeGetVolu return nil, status.Error(codes.InvalidArgument, "Path Doesn't exist") } + var err error + var resp *csi.NodeGetVolumeStatsResponse + klog.V(2).Info("NodeGetVolumeStats: Start getting Stats") // Making direct call to fs library for the sake of simplicity. That way we don't need to initialize VolumeStatsUtils. If there is a need for VolumeStatsUtils to grow bigger then we can use it _, capacity, _, inodes, inodesFree, inodesUsed, err := ns.Stats.FSInfo(volumePath) @@ -201,36 +205,82 @@ func (ns *nodeServer) NodeGetVolumeStats(_ context.Context, req *csi.NodeGetVolu }, nil } - capUsed, totalCap, err := ns.Stats.GetBucketUsage(volumeID) - if err != nil { - return nil, err - } - - capAsInt64, converted := totalCap.AsInt64() - if !converted { - capAsInt64 = capacity - } - - klog.Info("NodeGetVolumeStats: Total Capacity of Volume: ", capAsInt64) - - capAvailable := capAsInt64 - capUsed - - resp := &csi.NodeGetVolumeStatsResponse{ - Usage: []*csi.VolumeUsage{ - { - Available: capAvailable, - Total: capAsInt64, - Used: capUsed, - Unit: csi.VolumeUsage_BYTES, - }, - { - Available: inodesFree, - Total: inodes, - Used: inodesUsed, - Unit: csi.VolumeUsage_INODES, - }, - }, - } + timeDelay := time.NewTicker(1 * time.Minute) + quit := make(chan struct{}) + + go func() { + for { + select { + case <-timeDelay.C: + capUsed, totalCap, err := ns.Stats.GetBucketUsage(volumeID) + if err != nil { + return + } + + capAsInt64, converted := totalCap.AsInt64() + if !converted { + capAsInt64 = capacity + } + + klog.Info("NodeGetVolumeStats: Total Capacity of Volume: ", capAsInt64) + + capAvailable := capAsInt64 - capUsed + + resp = &csi.NodeGetVolumeStatsResponse{ + Usage: []*csi.VolumeUsage{ + { + Available: capAvailable, + Total: capAsInt64, + Used: capUsed, + Unit: csi.VolumeUsage_BYTES, + }, + { + Available: inodesFree, + Total: inodes, + Used: inodesUsed, + Unit: csi.VolumeUsage_INODES, + }, + }, + } + return + + case <-quit: + timeDelay.Stop() + return + } + } + }() + + // capUsed, totalCap, err := ns.Stats.GetBucketUsage(volumeID) + // if err != nil { + // return nil, err + // } + + // capAsInt64, converted := totalCap.AsInt64() + // if !converted { + // capAsInt64 = capacity + // } + + // klog.Info("NodeGetVolumeStats: Total Capacity of Volume: ", capAsInt64) + + // capAvailable := capAsInt64 - capUsed + + // resp := &csi.NodeGetVolumeStatsResponse{ + // Usage: []*csi.VolumeUsage{ + // { + // Available: capAvailable, + // Total: capAsInt64, + // Used: capUsed, + // Unit: csi.VolumeUsage_BYTES, + // }, + // { + // Available: inodesFree, + // Total: inodes, + // Used: inodesUsed, + // Unit: csi.VolumeUsage_INODES, + // }, + // }, + // } klog.V(2).Info("NodeGetVolumeStats: Volume Stats ", resp) return resp, nil From 3d9c6c97369ee56d9e405ceb23f798c2d12c5bc7 Mon Sep 17 00:00:00 2001 From: Ashima-Ashima1 Date: Thu, 23 May 2024 09:41:29 +0530 Subject: [PATCH 02/10] fetch stats after time interval Signed-off-by: Ashima-Ashima1 --- pkg/driver/nodeserver.go | 175 +++++++++++++++++++++------------------ 1 file changed, 96 insertions(+), 79 deletions(-) diff --git a/pkg/driver/nodeserver.go b/pkg/driver/nodeserver.go index 25eb1f9f..4813ea16 100644 --- a/pkg/driver/nodeserver.go +++ b/pkg/driver/nodeserver.go @@ -25,6 +25,8 @@ import ( "k8s.io/klog/v2" ) +var setTime time.Time + // Implements Node Server csi.NodeServer type nodeServer struct { *S3Driver @@ -187,12 +189,9 @@ func (ns *nodeServer) NodeGetVolumeStats(_ context.Context, req *csi.NodeGetVolu return nil, status.Error(codes.InvalidArgument, "Path Doesn't exist") } - var err error - var resp *csi.NodeGetVolumeStatsResponse - klog.V(2).Info("NodeGetVolumeStats: Start getting Stats") // Making direct call to fs library for the sake of simplicity. That way we don't need to initialize VolumeStatsUtils. If there is a need for VolumeStatsUtils to grow bigger then we can use it - _, capacity, _, inodes, inodesFree, inodesUsed, err := ns.Stats.FSInfo(volumePath) + available, capacity, usage, inodes, inodesFree, inodesUsed, err := ns.Stats.FSInfo(volumePath) if err != nil { data := map[string]string{"VolumeId": volumeID, "Error": err.Error()} @@ -205,82 +204,100 @@ func (ns *nodeServer) NodeGetVolumeStats(_ context.Context, req *csi.NodeGetVolu }, nil } - timeDelay := time.NewTicker(1 * time.Minute) - quit := make(chan struct{}) - - go func() { - for { - select { - case <-timeDelay.C: - capUsed, totalCap, err := ns.Stats.GetBucketUsage(volumeID) - if err != nil { - return - } - - capAsInt64, converted := totalCap.AsInt64() - if !converted { - capAsInt64 = capacity - } - - klog.Info("NodeGetVolumeStats: Total Capacity of Volume: ", capAsInt64) - - capAvailable := capAsInt64 - capUsed - - resp = &csi.NodeGetVolumeStatsResponse{ - Usage: []*csi.VolumeUsage{ - { - Available: capAvailable, - Total: capAsInt64, - Used: capUsed, - Unit: csi.VolumeUsage_BYTES, - }, - { - Available: inodesFree, - Total: inodes, - Used: inodesUsed, - Unit: csi.VolumeUsage_INODES, - }, - }, - } - return - - case <-quit: - timeDelay.Stop() - return - } + if setTime.Second() == 0 { + setTime = time.Now() + + capUsed, totalCap, err := ns.Stats.GetBucketUsage(volumeID) + if err != nil { + return nil, err + } + + capAsInt64, converted := totalCap.AsInt64() + if !converted { + capAsInt64 = capacity + } + + klog.Info("NodeGetVolumeStats: Total Capacity of Volume: ", capAsInt64) + + capAvailable := capAsInt64 - capUsed + + resp := &csi.NodeGetVolumeStatsResponse{ + Usage: []*csi.VolumeUsage{ + { + Available: capAvailable, + Total: capAsInt64, + Used: capUsed, + Unit: csi.VolumeUsage_BYTES, + }, + { + Available: inodesFree, + Total: inodes, + Used: inodesUsed, + Unit: csi.VolumeUsage_INODES, + }, + }, + } + + klog.V(2).Info("NodeGetVolumeStats: Volume Stats ", resp) + return resp, nil + } + + currentTime := time.Now() + timeDiff := currentTime.Sub(setTime).Minutes() + klog.V(2).Info("NodeGetVolumeStats: Time Difference ", timeDiff, " min") + + if timeDiff >= 2 { + capUsed, totalCap, err := ns.Stats.GetBucketUsage(volumeID) + if err != nil { + return nil, err } - }() - - // capUsed, totalCap, err := ns.Stats.GetBucketUsage(volumeID) - // if err != nil { - // return nil, err - // } - - // capAsInt64, converted := totalCap.AsInt64() - // if !converted { - // capAsInt64 = capacity - // } - - // klog.Info("NodeGetVolumeStats: Total Capacity of Volume: ", capAsInt64) - - // capAvailable := capAsInt64 - capUsed - - // resp := &csi.NodeGetVolumeStatsResponse{ - // Usage: []*csi.VolumeUsage{ - // { - // Available: capAvailable, - // Total: capAsInt64, - // Used: capUsed, - // Unit: csi.VolumeUsage_BYTES, - // }, - // { - // Available: inodesFree, - // Total: inodes, - // Used: inodesUsed, - // Unit: csi.VolumeUsage_INODES, - // }, - // }, - // } + + capAsInt64, converted := totalCap.AsInt64() + if !converted { + capAsInt64 = capacity + } + + klog.Info("NodeGetVolumeStats: Total Capacity of Volume: ", capAsInt64) + + capAvailable := capAsInt64 - capUsed + + resp := &csi.NodeGetVolumeStatsResponse{ + Usage: []*csi.VolumeUsage{ + { + Available: capAvailable, + Total: capAsInt64, + Used: capUsed, + Unit: csi.VolumeUsage_BYTES, + }, + { + Available: inodesFree, + Total: inodes, + Used: inodesUsed, + Unit: csi.VolumeUsage_INODES, + }, + }, + } + + klog.V(2).Info("NodeGetVolumeStats: Volume Stats ", resp) + return resp, nil + } + + resp := &csi.NodeGetVolumeStatsResponse{ + Usage: []*csi.VolumeUsage{ + { + Available: available, + Total: capacity, + Used: usage, + Unit: csi.VolumeUsage_BYTES, + }, + { + Available: inodesFree, + Total: inodes, + Used: inodesUsed, + Unit: csi.VolumeUsage_INODES, + }, + }, + } klog.V(2).Info("NodeGetVolumeStats: Volume Stats ", resp) return resp, nil From 4786f9a64e8b9fa305b63b518f6653bee60c8574 Mon Sep 17 00:00:00 2001 From: Ashima-Ashima1 Date: Thu, 23 May 2024 09:43:30 +0530 Subject: [PATCH 03/10] fetch stats after time interval Signed-off-by: Ashima-Ashima1 --- pkg/driver/nodeserver.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pkg/driver/nodeserver.go b/pkg/driver/nodeserver.go index 4813ea16..03be936b 100644 --- a/pkg/driver/nodeserver.go +++ b/pkg/driver/nodeserver.go @@ -26,6 +26,7 @@ import ( ) var setTime time.Time +var timeDelayInMin float64 = 5 // Implements Node Server csi.NodeServer type nodeServer struct { @@ -246,7 +247,7 @@ func (ns *nodeServer) NodeGetVolumeStats(_ context.Context, req *csi.NodeGetVolu timeDiff := currentTime.Sub(setTime).Minutes() klog.V(2).Info("NodeGetVolumeStats: Time Difference ", timeDiff, " min") - if timeDiff >= 2 { + if timeDiff >= timeDelayInMin { capUsed, totalCap, err := ns.Stats.GetBucketUsage(volumeID) if err != nil { return nil, err @@ -278,6 +279,8 @@ func (ns *nodeServer) NodeGetVolumeStats(_ context.Context, req *csi.NodeGetVolu }, } + setTime = currentTime + klog.V(2).Info("NodeGetVolumeStats: Volume Stats ", resp) return resp, nil } From b1ac8db684d979cf6c9f23926817639086036c8f Mon Sep 17 00:00:00 2001 From: Ashima-Ashima1 Date: Thu, 23 May 2024 10:27:18 +0530 Subject: [PATCH 04/10] fetch stats after time interval Signed-off-by: Ashima-Ashima1 --- deploy/ibmCloud/kustomization.yaml | 4 +- pkg/driver/nodeserver.go | 82 +++++------------------------- 2 files changed, 14 insertions(+), 72 deletions(-) diff --git a/deploy/ibmCloud/kustomization.yaml b/deploy/ibmCloud/kustomization.yaml index 0c3d5844..4dffccbd 100644 --- a/deploy/ibmCloud/kustomization.yaml +++ b/deploy/ibmCloud/kustomization.yaml @@ -13,8 +13,8 @@ images: newName: k8s.gcr.io/sig-storage/csi-provisioner newTag: v3.4.1 - name: cos-driver-image - newName: icr.io/ibm/ibm-object-csi-driver - newTag: v1.0.2-alpha + newName: docker.io/ashimagarg/stats + newTag: "04" - name: driver-registrar-image newName: k8s.gcr.io/sig-storage/csi-node-driver-registrar newTag: v2.6.3 diff --git a/pkg/driver/nodeserver.go b/pkg/driver/nodeserver.go index 03be936b..907495bb 100644 --- a/pkg/driver/nodeserver.go +++ b/pkg/driver/nodeserver.go @@ -22,11 +22,13 @@ import ( "golang.org/x/net/context" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" + "k8s.io/apimachinery/pkg/api/resource" "k8s.io/klog/v2" ) var setTime time.Time var timeDelayInMin float64 = 5 +var capAvailable, capAsInt64, capUsed int64 // Implements Node Server csi.NodeServer type nodeServer struct { @@ -192,7 +194,7 @@ func (ns *nodeServer) NodeGetVolumeStats(_ context.Context, req *csi.NodeGetVolu klog.V(2).Info("NodeGetVolumeStats: Start getting Stats") // Making direct call to fs library for the sake of simplicity. That way we don't need to initialize VolumeStatsUtils. If there is a need for VolumeStatsUtils to grow bigger then we can use it - available, capacity, usage, inodes, inodesFree, inodesUsed, err := ns.Stats.FSInfo(volumePath) + _, capacity, _, inodes, inodesFree, inodesUsed, err := ns.Stats.FSInfo(volumePath) if err != nil { data := map[string]string{"VolumeId": volumeID, "Error": err.Error()} @@ -205,92 +207,32 @@ func (ns *nodeServer) NodeGetVolumeStats(_ context.Context, req *csi.NodeGetVolu }, nil } - if setTime.Second() == 0 { + if setTime.Second() == 0 || time.Since(setTime).Minutes() >= timeDelayInMin { setTime = time.Now() - capUsed, totalCap, err := ns.Stats.GetBucketUsage(volumeID) - if err != nil { - return nil, err - } - - capAsInt64, converted := totalCap.AsInt64() - if !converted { - capAsInt64 = capacity - } - - klog.Info("NodeGetVolumeStats: Total Capacity of Volume: ", capAsInt64) - - capAvailable := capAsInt64 - capUsed - - resp := &csi.NodeGetVolumeStatsResponse{ - Usage: []*csi.VolumeUsage{ - { - Available: capAvailable, - Total: capAsInt64, - Used: capUsed, - Unit: csi.VolumeUsage_BYTES, - }, - { - Available: inodesFree, - Total: inodes, - Used: inodesUsed, - Unit: csi.VolumeUsage_INODES, - }, - }, - } - - klog.V(2).Info("NodeGetVolumeStats: Volume Stats ", resp) - return resp, nil - } + var totalCap resource.Quantity + var converted bool - currentTime := time.Now() - timeDiff := currentTime.Sub(setTime).Minutes() - klog.V(2).Info("NodeGetVolumeStats: Time Difference ", timeDiff, " min") - - if timeDiff >= timeDelayInMin { - capUsed, totalCap, err := ns.Stats.GetBucketUsage(volumeID) + capUsed, totalCap, err = ns.Stats.GetBucketUsage(volumeID) if err != nil { return nil, err } - capAsInt64, converted := totalCap.AsInt64() + capAsInt64, converted = totalCap.AsInt64() if !converted { capAsInt64 = capacity } - klog.Info("NodeGetVolumeStats: Total Capacity of Volume: ", capAsInt64) - capAvailable := capAsInt64 - capUsed - - resp := &csi.NodeGetVolumeStatsResponse{ - Usage: []*csi.VolumeUsage{ - { - Available: capAvailable, - Total: capAsInt64, - Used: capUsed, - Unit: csi.VolumeUsage_BYTES, - }, - { - Available: inodesFree, - Total: inodes, - Used: inodesUsed, - Unit: csi.VolumeUsage_INODES, - }, - }, - } - - setTime = currentTime - - klog.V(2).Info("NodeGetVolumeStats: Volume Stats ", resp) - return resp, nil + capAvailable = capAsInt64 - capUsed } resp := &csi.NodeGetVolumeStatsResponse{ Usage: []*csi.VolumeUsage{ { - Available: available, - Total: capacity, - Used: usage, + Available: capAvailable, + Total: capAsInt64, + Used: capUsed, Unit: csi.VolumeUsage_BYTES, }, { From e85de13f85910c948cad42ff642e7f778924bf9b Mon Sep 17 00:00:00 2001 From: Ashima-Ashima1 Date: Thu, 23 May 2024 11:26:22 +0530 Subject: [PATCH 05/10] fetch stats after time interval Signed-off-by: Ashima-Ashima1 --- pkg/constants/constants.go | 2 ++ pkg/driver/nodeserver.go | 3 +-- pkg/driver/nodeserver_test.go | 5 ++++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/pkg/constants/constants.go b/pkg/constants/constants.go index 2fba23d4..6100f4a5 100644 --- a/pkg/constants/constants.go +++ b/pkg/constants/constants.go @@ -4,6 +4,8 @@ const ( DefaultIAMEndPoint = "https://iam.cloud.ibm.com" DefaultVolumesPerNode = 4 + TimeDelayInMin float64 = 5 + KPEncryptionAlgorithm = "AES256" // https://github.com/IBM/ibm-cos-sdk-go/blob/master/service/s3/api.go#L9130-L9136 S3FS = "s3fs" diff --git a/pkg/driver/nodeserver.go b/pkg/driver/nodeserver.go index 907495bb..26edae45 100644 --- a/pkg/driver/nodeserver.go +++ b/pkg/driver/nodeserver.go @@ -27,7 +27,6 @@ import ( ) var setTime time.Time -var timeDelayInMin float64 = 5 var capAvailable, capAsInt64, capUsed int64 // Implements Node Server csi.NodeServer @@ -207,7 +206,7 @@ func (ns *nodeServer) NodeGetVolumeStats(_ context.Context, req *csi.NodeGetVolu }, nil } - if setTime.Second() == 0 || time.Since(setTime).Minutes() >= timeDelayInMin { + if setTime.Second() == 0 || time.Since(setTime).Minutes() >= constants.TimeDelayInMin { setTime = time.Now() var totalCap resource.Quantity diff --git a/pkg/driver/nodeserver_test.go b/pkg/driver/nodeserver_test.go index c68d7d27..f514ad25 100644 --- a/pkg/driver/nodeserver_test.go +++ b/pkg/driver/nodeserver_test.go @@ -20,6 +20,7 @@ import ( "errors" "reflect" "testing" + "time" "github.com/IBM/ibm-object-csi-driver/pkg/constants" "github.com/IBM/ibm-object-csi-driver/pkg/mounter" @@ -464,7 +465,7 @@ func TestNodeGetVolumeStats(t *testing.T) { expectedErr: errors.New("Path Doesn't exist"), }, { - testCaseName: "Negative: Failed to getg volume stats", + testCaseName: "Negative: Failed to get volume stats", req: &csi.NodeGetVolumeStatsRequest{ VolumeId: testVolumeID, VolumePath: testTargetPath, @@ -507,6 +508,8 @@ func TestNodeGetVolumeStats(t *testing.T) { nodeServer := nodeServer{ Stats: tc.driverStatsUtils, } + + setTime = time.Time{} actualResp, actualErr := nodeServer.NodeGetVolumeStats(ctx, tc.req) if tc.expectedErr != nil { From 8f79148b60783130fcea8fc62ffe239dca85d4b8 Mon Sep 17 00:00:00 2001 From: Ashima-Ashima1 Date: Thu, 23 May 2024 11:30:59 +0530 Subject: [PATCH 06/10] fetch stats after time interval Signed-off-by: Ashima-Ashima1 --- deploy/ibmCloud/kustomization.yaml | 4 ++-- pkg/driver/nodeserver.go | 6 +++--- pkg/driver/nodeserver_test.go | 4 ++-- pkg/driver/s3-driver.go | 2 ++ 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/deploy/ibmCloud/kustomization.yaml b/deploy/ibmCloud/kustomization.yaml index 4dffccbd..360728ae 100644 --- a/deploy/ibmCloud/kustomization.yaml +++ b/deploy/ibmCloud/kustomization.yaml @@ -13,8 +13,8 @@ images: newName: k8s.gcr.io/sig-storage/csi-provisioner newTag: v3.4.1 - name: cos-driver-image - newName: docker.io/ashimagarg/stats - newTag: "04" + newName: icr.io/ibm/ibm-object-csi-driver + newTag: v1.0.2-alpha - name: driver-registrar-image newName: k8s.gcr.io/sig-storage/csi-node-driver-registrar newTag: v2.6.3 diff --git a/pkg/driver/nodeserver.go b/pkg/driver/nodeserver.go index 26edae45..bbb4589f 100644 --- a/pkg/driver/nodeserver.go +++ b/pkg/driver/nodeserver.go @@ -26,7 +26,6 @@ import ( "k8s.io/klog/v2" ) -var setTime time.Time var capAvailable, capAsInt64, capUsed int64 // Implements Node Server csi.NodeServer @@ -36,6 +35,7 @@ type nodeServer struct { NodeID string Mounter mounter.NewMounterFactory MounterUtils mounterUtils.MounterUtils + SetTime time.Time } func (ns *nodeServer) NodeStageVolume(_ context.Context, req *csi.NodeStageVolumeRequest) (*csi.NodeStageVolumeResponse, error) { @@ -206,8 +206,8 @@ func (ns *nodeServer) NodeGetVolumeStats(_ context.Context, req *csi.NodeGetVolu }, nil } - if setTime.Second() == 0 || time.Since(setTime).Minutes() >= constants.TimeDelayInMin { - setTime = time.Now() + if ns.SetTime.Second() == 0 || time.Since(ns.SetTime).Minutes() >= constants.TimeDelayInMin { + ns.SetTime = time.Now() var totalCap resource.Quantity var converted bool diff --git a/pkg/driver/nodeserver_test.go b/pkg/driver/nodeserver_test.go index f514ad25..6dcb252a 100644 --- a/pkg/driver/nodeserver_test.go +++ b/pkg/driver/nodeserver_test.go @@ -506,10 +506,10 @@ func TestNodeGetVolumeStats(t *testing.T) { t.Log("Testcase being executed", zap.String("testcase", tc.testCaseName)) nodeServer := nodeServer{ - Stats: tc.driverStatsUtils, + Stats: tc.driverStatsUtils, + SetTime: time.Time{}, } - setTime = time.Time{} actualResp, actualErr := nodeServer.NodeGetVolumeStats(ctx, tc.req) if tc.expectedErr != nil { diff --git a/pkg/driver/s3-driver.go b/pkg/driver/s3-driver.go index b9216bf6..7bd66ff4 100644 --- a/pkg/driver/s3-driver.go +++ b/pkg/driver/s3-driver.go @@ -18,6 +18,7 @@ package driver import ( "fmt" + "time" "github.com/IBM/ibm-csi-common/pkg/utils" "github.com/IBM/ibm-object-csi-driver/pkg/mounter" @@ -142,6 +143,7 @@ func newNodeServer(d *S3Driver, statsUtil pkgUtils.StatsUtils, nodeID string, mo NodeID: nodeID, Mounter: mountObj, MounterUtils: mounterUtil, + SetTime: time.Time{}, } } From 2808dbbdda0efd2e0a330f7dfd1bf14cbd592a26 Mon Sep 17 00:00:00 2001 From: Ashima-Ashima1 Date: Thu, 23 May 2024 11:32:59 +0530 Subject: [PATCH 07/10] fetch stats after time interval Signed-off-by: Ashima-Ashima1 --- deploy/ibmCloud/kustomization.yaml | 2 +- pkg/constants/constants.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/deploy/ibmCloud/kustomization.yaml b/deploy/ibmCloud/kustomization.yaml index 360728ae..0c3d5844 100644 --- a/deploy/ibmCloud/kustomization.yaml +++ b/deploy/ibmCloud/kustomization.yaml @@ -13,7 +13,7 @@ images: newName: k8s.gcr.io/sig-storage/csi-provisioner newTag: v3.4.1 - name: cos-driver-image - newName: icr.io/ibm/ibm-object-csi-driver + newName: icr.io/ibm/ibm-object-csi-driver newTag: v1.0.2-alpha - name: driver-registrar-image newName: k8s.gcr.io/sig-storage/csi-node-driver-registrar diff --git a/pkg/constants/constants.go b/pkg/constants/constants.go index 6100f4a5..05e5c94b 100644 --- a/pkg/constants/constants.go +++ b/pkg/constants/constants.go @@ -4,7 +4,7 @@ const ( DefaultIAMEndPoint = "https://iam.cloud.ibm.com" DefaultVolumesPerNode = 4 - TimeDelayInMin float64 = 5 + TimeDelayInMin float64 = 15 KPEncryptionAlgorithm = "AES256" // https://github.com/IBM/ibm-cos-sdk-go/blob/master/service/s3/api.go#L9130-L9136 From 9d17dfe0c254d9db56e8bcb986de8f82a95af7ff Mon Sep 17 00:00:00 2001 From: Ashima-Ashima1 Date: Thu, 23 May 2024 12:27:48 +0530 Subject: [PATCH 08/10] fetch stats after fixed time interval Signed-off-by: Ashima-Ashima1 --- .secrets.baseline | 2 +- pkg/driver/nodeserver.go | 15 ++++++++------- pkg/driver/nodeserver_test.go | 4 ++-- pkg/driver/s3-driver.go | 12 ++++++------ 4 files changed, 17 insertions(+), 16 deletions(-) diff --git a/.secrets.baseline b/.secrets.baseline index 5f21888a..d9776038 100644 --- a/.secrets.baseline +++ b/.secrets.baseline @@ -3,7 +3,7 @@ "files": "go.sum|^.secrets.baseline$", "lines": null }, - "generated_at": "2024-05-22T07:40:17Z", + "generated_at": "2024-05-23T06:56:54Z", "plugins_used": [ { "name": "AWSKeyDetector" diff --git a/pkg/driver/nodeserver.go b/pkg/driver/nodeserver.go index bbb4589f..dd23522c 100644 --- a/pkg/driver/nodeserver.go +++ b/pkg/driver/nodeserver.go @@ -31,11 +31,11 @@ var capAvailable, capAsInt64, capUsed int64 // Implements Node Server csi.NodeServer type nodeServer struct { *S3Driver - Stats utils.StatsUtils - NodeID string - Mounter mounter.NewMounterFactory - MounterUtils mounterUtils.MounterUtils - SetTime time.Time + Stats utils.StatsUtils + NodeID string + Mounter mounter.NewMounterFactory + MounterUtils mounterUtils.MounterUtils + VolumeIDAndTimeMap map[string]time.Time } func (ns *nodeServer) NodeStageVolume(_ context.Context, req *csi.NodeStageVolumeRequest) (*csi.NodeStageVolumeResponse, error) { @@ -206,8 +206,9 @@ func (ns *nodeServer) NodeGetVolumeStats(_ context.Context, req *csi.NodeGetVolu }, nil } - if ns.SetTime.Second() == 0 || time.Since(ns.SetTime).Minutes() >= constants.TimeDelayInMin { - ns.SetTime = time.Now() + timeSetInMap := ns.VolumeIDAndTimeMap[volumeID] + if timeSetInMap.Second() == 0 || time.Since(timeSetInMap).Minutes() >= constants.TimeDelayInMin { + ns.VolumeIDAndTimeMap[volumeID] = time.Now() var totalCap resource.Quantity var converted bool diff --git a/pkg/driver/nodeserver_test.go b/pkg/driver/nodeserver_test.go index 6dcb252a..832f9e50 100644 --- a/pkg/driver/nodeserver_test.go +++ b/pkg/driver/nodeserver_test.go @@ -506,8 +506,8 @@ func TestNodeGetVolumeStats(t *testing.T) { t.Log("Testcase being executed", zap.String("testcase", tc.testCaseName)) nodeServer := nodeServer{ - Stats: tc.driverStatsUtils, - SetTime: time.Time{}, + Stats: tc.driverStatsUtils, + VolumeIDAndTimeMap: map[string]time.Time{}, } actualResp, actualErr := nodeServer.NodeGetVolumeStats(ctx, tc.req) diff --git a/pkg/driver/s3-driver.go b/pkg/driver/s3-driver.go index 7bd66ff4..a839bd64 100644 --- a/pkg/driver/s3-driver.go +++ b/pkg/driver/s3-driver.go @@ -138,12 +138,12 @@ func newControllerServer(d *S3Driver, statsUtil pkgUtils.StatsUtils, s3cosSessio func newNodeServer(d *S3Driver, statsUtil pkgUtils.StatsUtils, nodeID string, mountObj mounter.NewMounterFactory, mounterUtil mounterUtils.MounterUtils) *nodeServer { return &nodeServer{ - S3Driver: d, - Stats: statsUtil, - NodeID: nodeID, - Mounter: mountObj, - MounterUtils: mounterUtil, - SetTime: time.Time{}, + S3Driver: d, + Stats: statsUtil, + NodeID: nodeID, + Mounter: mountObj, + MounterUtils: mounterUtil, + VolumeIDAndTimeMap: map[string]time.Time{}, } } From afdab99cb973863069abdc92b6f3869b9b048eaf Mon Sep 17 00:00:00 2001 From: Ashima-Ashima1 Date: Thu, 23 May 2024 12:29:06 +0530 Subject: [PATCH 09/10] minor changes Signed-off-by: Ashima-Ashima1 --- pkg/driver/nodeserver_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/pkg/driver/nodeserver_test.go b/pkg/driver/nodeserver_test.go index 832f9e50..94445a7d 100644 --- a/pkg/driver/nodeserver_test.go +++ b/pkg/driver/nodeserver_test.go @@ -509,7 +509,6 @@ func TestNodeGetVolumeStats(t *testing.T) { Stats: tc.driverStatsUtils, VolumeIDAndTimeMap: map[string]time.Time{}, } - actualResp, actualErr := nodeServer.NodeGetVolumeStats(ctx, tc.req) if tc.expectedErr != nil { From 730970a803171e0dd15a381885118d72a623ed95 Mon Sep 17 00:00:00 2001 From: Ashima-Ashima1 Date: Thu, 23 May 2024 13:12:23 +0530 Subject: [PATCH 10/10] fetch stats after fixed time interval Signed-off-by: Ashima-Ashima1 --- pkg/driver/nodeserver.go | 36 ++++++++++++++++++++--------------- pkg/driver/nodeserver_test.go | 3 +-- pkg/driver/s3-driver.go | 3 +-- 3 files changed, 23 insertions(+), 19 deletions(-) diff --git a/pkg/driver/nodeserver.go b/pkg/driver/nodeserver.go index dd23522c..17186afa 100644 --- a/pkg/driver/nodeserver.go +++ b/pkg/driver/nodeserver.go @@ -22,11 +22,15 @@ import ( "golang.org/x/net/context" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" - "k8s.io/apimachinery/pkg/api/resource" "k8s.io/klog/v2" ) -var capAvailable, capAsInt64, capUsed int64 +type NodeVolStats struct { + setTime time.Time + capAvailable int64 + capTotal int64 + capUsed int64 +} // Implements Node Server csi.NodeServer type nodeServer struct { @@ -35,7 +39,7 @@ type nodeServer struct { NodeID string Mounter mounter.NewMounterFactory MounterUtils mounterUtils.MounterUtils - VolumeIDAndTimeMap map[string]time.Time + VolumeIDAndTimeMap map[string]NodeVolStats } func (ns *nodeServer) NodeStageVolume(_ context.Context, req *csi.NodeStageVolumeRequest) (*csi.NodeStageVolumeResponse, error) { @@ -206,33 +210,35 @@ func (ns *nodeServer) NodeGetVolumeStats(_ context.Context, req *csi.NodeGetVolu }, nil } - timeSetInMap := ns.VolumeIDAndTimeMap[volumeID] + timeSetInMap := ns.VolumeIDAndTimeMap[volumeID].setTime if timeSetInMap.Second() == 0 || time.Since(timeSetInMap).Minutes() >= constants.TimeDelayInMin { - ns.VolumeIDAndTimeMap[volumeID] = time.Now() - - var totalCap resource.Quantity - var converted bool - - capUsed, totalCap, err = ns.Stats.GetBucketUsage(volumeID) + capUsed, totalCap, err := ns.Stats.GetBucketUsage(volumeID) if err != nil { return nil, err } - capAsInt64, converted = totalCap.AsInt64() + capAsInt64, converted := totalCap.AsInt64() if !converted { capAsInt64 = capacity } klog.Info("NodeGetVolumeStats: Total Capacity of Volume: ", capAsInt64) - capAvailable = capAsInt64 - capUsed + capAvailable := capAsInt64 - capUsed + + ns.VolumeIDAndTimeMap[volumeID] = NodeVolStats{ + setTime: time.Now(), + capAvailable: capAvailable, + capTotal: capAsInt64, + capUsed: capUsed, + } } resp := &csi.NodeGetVolumeStatsResponse{ Usage: []*csi.VolumeUsage{ { - Available: capAvailable, - Total: capAsInt64, - Used: capUsed, + Available: ns.VolumeIDAndTimeMap[volumeID].capAvailable, + Total: ns.VolumeIDAndTimeMap[volumeID].capTotal, + Used: ns.VolumeIDAndTimeMap[volumeID].capUsed, Unit: csi.VolumeUsage_BYTES, }, { diff --git a/pkg/driver/nodeserver_test.go b/pkg/driver/nodeserver_test.go index 94445a7d..fb6b7ef0 100644 --- a/pkg/driver/nodeserver_test.go +++ b/pkg/driver/nodeserver_test.go @@ -20,7 +20,6 @@ import ( "errors" "reflect" "testing" - "time" "github.com/IBM/ibm-object-csi-driver/pkg/constants" "github.com/IBM/ibm-object-csi-driver/pkg/mounter" @@ -507,7 +506,7 @@ func TestNodeGetVolumeStats(t *testing.T) { nodeServer := nodeServer{ Stats: tc.driverStatsUtils, - VolumeIDAndTimeMap: map[string]time.Time{}, + VolumeIDAndTimeMap: map[string]NodeVolStats{}, } actualResp, actualErr := nodeServer.NodeGetVolumeStats(ctx, tc.req) diff --git a/pkg/driver/s3-driver.go b/pkg/driver/s3-driver.go index a839bd64..ec8ce36c 100644 --- a/pkg/driver/s3-driver.go +++ b/pkg/driver/s3-driver.go @@ -18,7 +18,6 @@ package driver import ( "fmt" - "time" "github.com/IBM/ibm-csi-common/pkg/utils" "github.com/IBM/ibm-object-csi-driver/pkg/mounter" @@ -143,7 +142,7 @@ func newNodeServer(d *S3Driver, statsUtil pkgUtils.StatsUtils, nodeID string, mo NodeID: nodeID, Mounter: mountObj, MounterUtils: mounterUtil, - VolumeIDAndTimeMap: map[string]time.Time{}, + VolumeIDAndTimeMap: map[string]NodeVolStats{}, } }