Skip to content
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

[YUNIKORN-2190] Using empty array to replace null response from /ws/v1/partition/{partitionName}/usage/users #755

Merged
merged 3 commits into from
Dec 15, 2023

Conversation

brandboat
Copy link
Member

What is this PR for?

The endpoint /ws/v1/partition/{partitionName}/usage/users and /ws/v1/partition/{partitionName}/usage/groups
will return nil when user / group usages are nonexistent. The return type is expected to be array, so it seems to me the empty array is more suitable to be returned.

What type of PR is it?

  • - Improvement

Todos

N/A

What is the Jira issue?

https://issues.apache.org/jira/browse/YUNIKORN-2190

How should this be tested?

covered by unit tests

Screenshots (if appropriate)

N/A

Questions:

N/A

Copy link
Contributor

@chia7712 chia7712 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@brandboat thanks for this patch. a couple of comments below.

@@ -823,7 +823,7 @@ func getUsersResourceUsage(w http.ResponseWriter, _ *http.Request) {
writeHeaders(w)
userManager := ugm.GetUserManager()
usersResources := userManager.GetUsersResources()
var result []*dao.UserResourceUsageDAOInfo
result := []*dao.UserResourceUsageDAOInfo{}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about using make with initial capacity?

result := make([]*dao.UserResourceUsageDAOInfo, len(usersResources))

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 for that

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I think it has to be result := make([]*dao.UserResourceUsageDAOInfo, 0, len(usersResources)) so that appending starts at position 0.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The even faster solution is to use this:

	result := make([]*dao.UserResourceUsageDAOInfo, len(usersResources))
	for i, tracker := range usersResources {
		result[i] = tracker.GetUserResourceUsageDAOInfo()
	}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already addressed comments, thank you for everyone's valuable suggestions !

@@ -859,7 +859,7 @@ func getGroupsResourceUsage(w http.ResponseWriter, r *http.Request) {
writeHeaders(w)
userManager := ugm.GetUserManager()
groupsResources := userManager.GetGroupsResources()
var result []*dao.GroupResourceUsageDAOInfo
result := []*dao.GroupResourceUsageDAOInfo{}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Copy link
Contributor

@chia7712 chia7712 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

overall +1, one small question left.

@@ -1500,7 +1500,7 @@ func TestUsersAndGroupsResourceUsage(t *testing.T) {
assert.NilError(t, err, "Get Groups Resource Usage Handler request failed")

var groupsResourceUsageDao []*dao.GroupResourceUsageDAOInfo
var expGroupsResourceUsageDao []*dao.GroupResourceUsageDAOInfo
expGroupsResourceUsageDao := []*dao.GroupResourceUsageDAOInfo{}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pardon me, is this change related to PR? or it is a potential issue?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it's related. Since the response from the code you mentioned is now empty array instead of nil as we changed the behavior in this pr.

IMO, the test should be adjusted as follows: set up a scenario where the group resource usage is not empty, ensuring that there is content in groupsResourceUsageDao. Otherwise, it appears to be duplicating the functionality of TestEmptyGroupsResourceUsageHandler.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO, the test should be adjusted as follows: set up a scenario where the group resource usage is not empty, ensuring that there is content in groupsResourceUsageDao. Otherwise, it appears to be duplicating the functionality of TestEmptyGroupsResourceUsageHandler.

that makes sense to me. Please make sure the test is NOT duplicate to TestEmptyGroupsResourceUsageHandler

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@brandboat Empty response is one of the basic test cases while hitting those API's. So, can we add the test related changes in TestUsersAndGroupsResourceUsage itself instead of two new & separate test methods?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already addressed comments in the latest commit, many thanks !

…1/partition/{partitionName}/usage/users

also make the same change to /ws/v1/partition/{partitionName}/usage/groups
Copy link

codecov bot commented Dec 14, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (62271e5) 77.72% compared to head (aaafc9c) 77.75%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #755      +/-   ##
==========================================
+ Coverage   77.72%   77.75%   +0.02%     
==========================================
  Files          82       82              
  Lines       13430    13430              
==========================================
+ Hits        10439    10442       +3     
+ Misses       2664     2662       -2     
+ Partials      327      326       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -1405,7 +1422,7 @@ func TestFullStateDumpPath(t *testing.T) {
}

func TestSpecificUserAndGroupResourceUsage(t *testing.T) {
prepareUserAndGroupContext(t)
prepareUserAndGroupContext(t, configDefault)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(this is not related to this PR)
it seems the configDefault does not include any group/user, so all asserts in this test case are related to "nonexistent" case, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it seems the configDefault does not include any group/user, so all asserts in this test case are related to "nonexistent" case, right?

You're correct, except for the test case under comment // Test existed user query. I believe the test case mentioned in that comment is missing an assertion to verify the existence of the user resource testuser.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is unrelated to this PR, so I file ticket (https://issues.apache.org/jira/browse/YUNIKORN-2272) to trace it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, already take over the ticket, will come up with another pr ASAP.

Copy link
Contributor

@pbacsko pbacsko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 LGTM

Copy link
Contributor

@chia7712 chia7712 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@chia7712 chia7712 merged commit 246fe2c into apache:master Dec 15, 2023
3 checks passed
@brandboat brandboat deleted the YUNIKORN-2190 branch December 15, 2023 01:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants