Skip to content

Add Delay While fetching Volume Stats from Bucket #125

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pkg/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ const (
DefaultIAMEndPoint = "https://iam.cloud.ibm.com"
DefaultVolumesPerNode = 4

TimeDelayInMin float64 = 15

KPEncryptionAlgorithm = "AES256" // https://github.com/IBM/ibm-cos-sdk-go/blob/master/service/s3/api.go#L9130-L9136

S3FS = "s3fs"
Expand Down
63 changes: 41 additions & 22 deletions pkg/driver/nodeserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -24,13 +25,21 @@ import (
"k8s.io/klog/v2"
)

type NodeVolStats struct {
setTime time.Time
// capAvailable int64
capTotal int64
capUsed int64
}

// Implements Node Server csi.NodeServer
type nodeServer struct {
*S3Driver
Stats utils.StatsUtils
NodeID string
Mounter mounter.NewMounterFactory
MounterUtils mounterUtils.MounterUtils
Stats utils.StatsUtils
NodeID string
Mounter mounter.NewMounterFactory
MounterUtils mounterUtils.MounterUtils
VolumeIDAndTimeMap map[string]NodeVolStats
}

func (ns *nodeServer) NodeStageVolume(_ context.Context, req *csi.NodeStageVolumeRequest) (*csi.NodeStageVolumeResponse, error) {
Expand Down Expand Up @@ -214,31 +223,41 @@ func (ns *nodeServer) NodeGetVolumeStats(_ context.Context, req *csi.NodeGetVolu
}, nil
}

totalCap, err := ns.Stats.GetTotalCapacityFromPV(volumeID)
if err != nil {
return nil, err
}
timeSetInMap := ns.VolumeIDAndTimeMap[volumeID].setTime
if timeSetInMap.Second() == 0 || time.Since(timeSetInMap).Minutes() >= constants.TimeDelayInMin {
totalCap, err := ns.Stats.GetTotalCapacityFromPV(volumeID)
if err != nil {
return nil, err
}

capAsInt64, converted := totalCap.AsInt64()
if !converted {
capAsInt64 = capacity
}
klog.Info("NodeGetVolumeStats: Total Capacity of Volume: ", capAsInt64)
capAsInt64, converted := totalCap.AsInt64()
if !converted {
capAsInt64 = capacity
}
klog.Info("NodeGetVolumeStats: Total Capacity of Volume: ", capAsInt64)

capUsed, err := ns.Stats.GetBucketUsage(volumeID)
if err != nil {
return nil, err
}
capUsed, err := ns.Stats.GetBucketUsage(volumeID)
if err != nil {
return nil, err
}

// Since `capAvailable` can be negative and K8s will roundoff from int64 to uint64 resulting in misleading value
// capAvailable := capAsInt64 - capUsed

// Since `capAvailable` can be negative and K8s will roundoff from int64 to uint64 resulting in misleading value
// 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,
},
{
Expand Down
3 changes: 2 additions & 1 deletion pkg/driver/nodeserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,8 @@ func TestNodeGetVolumeStats(t *testing.T) {
t.Log("Testcase being executed", zap.String("testcase", tc.testCaseName))

nodeServer := nodeServer{
Stats: tc.driverStatsUtils,
Stats: tc.driverStatsUtils,
VolumeIDAndTimeMap: map[string]NodeVolStats{},
}
actualResp, actualErr := nodeServer.NodeGetVolumeStats(ctx, tc.req)

Expand Down
11 changes: 6 additions & 5 deletions pkg/driver/s3-driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,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,
S3Driver: d,
Stats: statsUtil,
NodeID: nodeID,
Mounter: mountObj,
MounterUtils: mounterUtil,
VolumeIDAndTimeMap: map[string]NodeVolStats{},
}
}

Expand Down