-
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
Merged
wongma7
merged 1 commit into
kubernetes-sigs:master
from
AndyXiangLi:volume-stat-metrics
Jan 11, 2021
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ package driver | |
import ( | ||
"context" | ||
"errors" | ||
"os" | ||
"reflect" | ||
"strings" | ||
"testing" | ||
|
@@ -1162,6 +1163,31 @@ func TestNodeUnpublishVolume(t *testing.T) { | |
expectErr(t, err, codes.InvalidArgument) | ||
}, | ||
}, | ||
{ | ||
name: "fail error on unmount", | ||
testFunc: func(t *testing.T) { | ||
mockCtl := gomock.NewController(t) | ||
defer mockCtl.Finish() | ||
|
||
mockMetadata := mocks.NewMockMetadataService(mockCtl) | ||
mockMounter := mocks.NewMockMounter(mockCtl) | ||
|
||
awsDriver := &nodeService{ | ||
metadata: mockMetadata, | ||
mounter: mockMounter, | ||
inFlight: internal.NewInFlight(), | ||
} | ||
|
||
req := &csi.NodeUnpublishVolumeRequest{ | ||
TargetPath: targetPath, | ||
VolumeId: "vol-test", | ||
} | ||
|
||
mockMounter.EXPECT().Unmount(gomock.Eq(targetPath)).Return(errors.New("test Unmount error")) | ||
_, err := awsDriver.NodeUnpublishVolume(context.TODO(), req) | ||
expectErr(t, err, codes.Internal) | ||
}, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
|
@@ -1170,32 +1196,127 @@ func TestNodeUnpublishVolume(t *testing.T) { | |
} | ||
|
||
func TestNodeGetVolumeStats(t *testing.T) { | ||
mockCtl := gomock.NewController(t) | ||
defer mockCtl.Finish() | ||
testCases := []struct { | ||
name string | ||
testFunc func(t *testing.T) | ||
}{ | ||
{ | ||
name: "success normal", | ||
testFunc: func(t *testing.T) { | ||
mockCtl := gomock.NewController(t) | ||
defer mockCtl.Finish() | ||
|
||
mockMetadata := mocks.NewMockMetadataService(mockCtl) | ||
mockMounter := mocks.NewMockMounter(mockCtl) | ||
mockMetadata := mocks.NewMockMetadataService(mockCtl) | ||
mockMounter := mocks.NewMockMounter(mockCtl) | ||
VolumePath := "./test" | ||
err := os.MkdirAll(VolumePath, 0644) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. fixed |
||
if err != nil { | ||
t.Fatalf("fail to create dir: %v", err) | ||
} | ||
defer os.RemoveAll(VolumePath) | ||
|
||
awsDriver := nodeService{ | ||
metadata: mockMetadata, | ||
mounter: mockMounter, | ||
inFlight: internal.NewInFlight(), | ||
} | ||
mockMounter.EXPECT().ExistsPath(VolumePath).Return(true, nil) | ||
|
||
awsDriver := nodeService{ | ||
metadata: mockMetadata, | ||
mounter: mockMounter, | ||
inFlight: internal.NewInFlight(), | ||
} | ||
|
||
expErrCode := codes.Unimplemented | ||
req := &csi.NodeGetVolumeStatsRequest{ | ||
VolumeId: "vol-test", | ||
VolumePath: VolumePath, | ||
} | ||
_, err = awsDriver.NodeGetVolumeStats(context.TODO(), req) | ||
if err != nil { | ||
t.Fatalf("Expect no error but got: %v", err) | ||
} | ||
}, | ||
}, | ||
{ | ||
name: "fail path not exist", | ||
testFunc: func(t *testing.T) { | ||
mockCtl := gomock.NewController(t) | ||
defer mockCtl.Finish() | ||
|
||
req := &csi.NodeGetVolumeStatsRequest{} | ||
_, err := awsDriver.NodeGetVolumeStats(context.TODO(), req) | ||
if err == nil { | ||
t.Fatalf("Expected error code %d, got nil", expErrCode) | ||
} | ||
srvErr, ok := status.FromError(err) | ||
if !ok { | ||
t.Fatalf("Could not get error status code from error: %v", srvErr) | ||
mockMetadata := mocks.NewMockMetadataService(mockCtl) | ||
mockMounter := mocks.NewMockMounter(mockCtl) | ||
VolumePath := "/test" | ||
|
||
mockMounter.EXPECT().ExistsPath(VolumePath).Return(false, nil) | ||
|
||
awsDriver := nodeService{ | ||
metadata: mockMetadata, | ||
mounter: mockMounter, | ||
inFlight: internal.NewInFlight(), | ||
} | ||
|
||
req := &csi.NodeGetVolumeStatsRequest{ | ||
VolumeId: "vol-test", | ||
VolumePath: VolumePath, | ||
} | ||
_, err := awsDriver.NodeGetVolumeStats(context.TODO(), req) | ||
expectErr(t, err, codes.NotFound) | ||
}, | ||
}, | ||
{ | ||
name: "fail can't determine block device", | ||
testFunc: func(t *testing.T) { | ||
mockCtl := gomock.NewController(t) | ||
defer mockCtl.Finish() | ||
|
||
mockMetadata := mocks.NewMockMetadataService(mockCtl) | ||
mockMounter := mocks.NewMockMounter(mockCtl) | ||
VolumePath := "/test" | ||
|
||
mockMounter.EXPECT().ExistsPath(VolumePath).Return(true, nil) | ||
|
||
awsDriver := nodeService{ | ||
metadata: mockMetadata, | ||
mounter: mockMounter, | ||
inFlight: internal.NewInFlight(), | ||
} | ||
|
||
req := &csi.NodeGetVolumeStatsRequest{ | ||
VolumeId: "vol-test", | ||
VolumePath: VolumePath, | ||
} | ||
_, err := awsDriver.NodeGetVolumeStats(context.TODO(), req) | ||
expectErr(t, err, codes.Internal) | ||
}, | ||
}, | ||
{ | ||
name: "fail error calling existsPath", | ||
testFunc: func(t *testing.T) { | ||
mockCtl := gomock.NewController(t) | ||
defer mockCtl.Finish() | ||
|
||
mockMetadata := mocks.NewMockMetadataService(mockCtl) | ||
mockMounter := mocks.NewMockMounter(mockCtl) | ||
VolumePath := "/test" | ||
|
||
mockMounter.EXPECT().ExistsPath(VolumePath).Return(false, errors.New("get existsPath call fail")) | ||
|
||
awsDriver := nodeService{ | ||
metadata: mockMetadata, | ||
mounter: mockMounter, | ||
inFlight: internal.NewInFlight(), | ||
} | ||
|
||
req := &csi.NodeGetVolumeStatsRequest{ | ||
VolumeId: "vol-test", | ||
VolumePath: VolumePath, | ||
} | ||
_, err := awsDriver.NodeGetVolumeStats(context.TODO(), req) | ||
expectErr(t, err, codes.Internal) | ||
}, | ||
}, | ||
} | ||
if srvErr.Code() != expErrCode { | ||
t.Fatalf("Expected error code %d, got %d message %s", expErrCode, srvErr.Code(), srvErr.Message()) | ||
|
||
for _, tc := range testCases { | ||
t.Run(tc.name, tc.testFunc) | ||
} | ||
|
||
} | ||
|
||
func TestNodeGetCapabilities(t *testing.T) { | ||
|
@@ -1226,6 +1347,13 @@ func TestNodeGetCapabilities(t *testing.T) { | |
}, | ||
}, | ||
}, | ||
{ | ||
Type: &csi.NodeServiceCapability_Rpc{ | ||
Rpc: &csi.NodeServiceCapability_RPC{ | ||
Type: csi.NodeServiceCapability_RPC_GET_VOLUME_STATS, | ||
}, | ||
}, | ||
}, | ||
} | ||
expResp := &csi.NodeGetCapabilitiesResponse{Capabilities: caps} | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.