-
Notifications
You must be signed in to change notification settings - Fork 807
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
add volume stats metrics - #677
add volume stats metrics - #677
Conversation
Hi @AndyXiangLi. Thanks for your PR. I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
}, | ||
}, | ||
}, nil | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you post output of this passing csi sanity tests? I assume it did but just to be sure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, sanity test is passed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you clarify in the PR description? Ideally with the output.
/ok-to-test |
Pull Request Test Coverage Report for Build 1450
💛 - Coveralls |
938a448
to
29e2b72
Compare
pkg/driver/statter.go
Outdated
|
||
var _ Statter = realStatter{} | ||
|
||
type realStatter struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should name this simply statter
.
pkg/driver/statter.go
Outdated
|
||
func (fakeStatter) StatFS(path string) (available, capacity, used, inodesFree, inodes, inodesUsed int64, err error) { | ||
// Assume the file exists and give some dummy values back | ||
return 1, 1, 1, 1, 1, 1, nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why don't you return back whatever is passed to this function? It'd be more useful for testing.
pkg/driver/statter.go
Outdated
"golang.org/x/sys/unix" | ||
) | ||
|
||
type Statter interface { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add some documentation? It'd be really helpful going forward.
pkg/driver/node.go
Outdated
strOut := strings.TrimSpace(string(output)) | ||
gotSizeBytes, err := strconv.ParseInt(strOut, 10, 64) | ||
if err != nil { | ||
return -1, fmt.Errorf("failed to parse size %s into int a size", strOut) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: failed to parse size %s as int
pkg/driver/statter.go
Outdated
return false, err | ||
} | ||
|
||
return (st.Mode & unix.S_IFMT) == unix.S_IFBLK, nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm going to assume this only works on unix?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, right now it is only working for unix
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's fine. I see you've added the checks for windows, which is good enough for now. I'm OK with only working on unix, but we shouldn't break windows.
Supersedes #589. |
fyi, test case failed === RUN TestNodeGetVolumeStats |
b69f5cd
to
ddaa68b
Compare
d254890
to
179a992
Compare
/approve |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple comments, good work!
Also, looks like you'll need to improve the coverage 😅
pkg/driver/statter.go
Outdated
return false, err | ||
} | ||
|
||
return (st.Mode & unix.S_IFMT) == unix.S_IFBLK, nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's fine. I see you've added the checks for windows, which is good enough for now. I'm OK with only working on unix, but we shouldn't break windows.
pkg/driver/statter.go
Outdated
} | ||
|
||
// Available is blocks available * fragment size | ||
available = int64(statfs.Bavail) * int64(statfs.Bsize) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are all these fields guaranteed to be present if unix.Statfs
succeeds?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, they are all system level variables to my understanding, and we should be able to get all the following value in one call: Type Bsize Blocks Bfree Bavail Files Ffree Fsid NamelenFrsize Flags Spare
pkg/driver/statter.go
Outdated
// Capacity is total block count * fragment size | ||
capacity = int64(statfs.Blocks) * int64(statfs.Bsize) | ||
// Usage is block being used * fragment size (aka block size). | ||
used = (int64(statfs.Blocks) - int64(statfs.Bfree)) * int64(statfs.Bsize) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably do something like if used < 0 { used = 0 }
and maybe log a warning for sanity.
pkg/driver/statter.go
Outdated
inodes = int64(statfs.Files) | ||
inodesFree = int64(statfs.Ffree) | ||
inodesUsed = inodes - inodesFree | ||
return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I got confused for a moment here. God I hate the named return :)
Can you also add a comment to clarify the unit of these values? I'd assume they're bytes.
pkg/driver/node.go
Outdated
isBlock, err := d.statter.IsBlockDevice(req.VolumePath) | ||
|
||
if err != nil { | ||
return nil, status.Errorf(codes.NotFound, "failed to determine whether %s is block device: %v", req.VolumePath, err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this be codes.Internal
?
}, | ||
}, | ||
}, nil | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you clarify in the PR description? Ideally with the output.
pkg/driver/sanity_test.go
Outdated
@@ -73,6 +76,15 @@ func TestSanity(t *testing.T) { | |||
sanity.Test(t, config) | |||
} | |||
|
|||
func createDir(targetPath string) (string, error) { | |||
if err := os.MkdirAll(targetPath, 0755); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
755 looks too permissive to me. 644 should be good for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually we need write and exec permit here, minimum 300 will work. But 755 is the default permit sanity_test used to mkdir, so I kept it..
https://github.com/kubernetes-csi/csi-test/blob/054980205e4fc45ab9e940e39bdfd71066d96d87/pkg/sanity/sanity.go#L365
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't sure why we would need exec on a folder. TIL :) https://unix.stackexchange.com/a/150456
pkg/driver/sanity_test.go
Outdated
@@ -73,6 +76,15 @@ func TestSanity(t *testing.T) { | |||
sanity.Test(t, config) | |||
} | |||
|
|||
func createDir(targetPath string) (string, error) { | |||
if err := os.MkdirAll(targetPath, 0755); err != nil { | |||
if !os.IsExist(err) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can use IsNotExist
here.
@@ -309,13 +321,48 @@ func (f *fakeMounter) GetDeviceName(mountPath string) (string, int, error) { | |||
} | |||
|
|||
func (f *fakeMounter) MakeFile(pathname string) error { | |||
file, err := os.OpenFile(pathname, os.O_CREATE, os.FileMode(0644)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's fine, I'm not too familiar with sanity but seems mocking the mount is common pattern. https://github.com/kubernetes-sigs/gcp-compute-persistent-disk-csi-driver/blob/2014365ea7b3405e024be1d9552aa30d44da4a8b/pkg/mount-manager/fake-safe-mounter.go#L28
I think the sanity test is still testing everything in the driver code surrounding wheerever it actually tries to call "Mount/Statfs".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be fine as long as we don't modify the mount, but if we do that we risk silently failing sanity tests.
@AndyXiangLi can you add a note to the actual mount code? That it's mirrored here and any modification should be applied here too. Not ideal, but I'd feel safer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ayberk Sure will do that, and as we talked off line, I think it would be better if we can extract those three functions out of mounter in the future.
b88f7c1
to
13bf1a3
Compare
81b5c9d
to
e7e5d3e
Compare
mounter: mockMounter, | ||
inFlight: internal.NewInFlight(), | ||
} | ||
err := os.MkdirAll(VolumePath, 0644) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like there are some indentation problems in this file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
e7e5d3e
to
f7ec047
Compare
/lgtm |
I'll manually merge, coverage decrease is because of getBlockSizeBytes which is not easy to exercise and anyway coveralls is not supposed to be required! ( longstanding TODO to fix this). /approve |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: AndyXiangLi, wongma7 The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Is this a bug fix or adding new feature?
Fixes #223
Fixes #499
What is this PR about? / Why do we need it?
Implement Volume stats metrics
What testing is done?
Sanity test passed
Added unit test for the change
Validate volume status can be logged in the ebs-plugin in node pod