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-2042] REST API for specific queue #687

Closed
wants to merge 11 commits into from

Conversation

steinsgateted
Copy link
Contributor

@steinsgateted steinsgateted commented Oct 29, 2023

What is this PR for?

Expose a REST API for specific queue:
/ws/v1/partition/%s/queue/%s/
Other modifications:
1
Modify the test items, which were not actually tested originally.
pkg/scheduler/objects/queue_test.go TestGetPartitionQueueDAOInfo function

What type of PR is it?

  • - Bug Fix
  • - Improvement
  • - Feature
  • - Documentation
  • - Hot Fix
  • - Refactoring

Todos

  • - Task

What is the Jira issue?

https://issues.apache.org/jira/projects/YUNIKORN/issues/YUNIKORN-2042

How should this be tested?

example:http://localhost:9080/ws/v1/partition/default/queue/root.namespaces.level1.level2

Screenshots (if appropriate)

Questions:

  • - The licenses files need update.
  • - There is breaking changes for older versions.
  • - It needs documentation.

@steinsgateted steinsgateted self-assigned this Oct 29, 2023
@codecov
Copy link

codecov bot commented Oct 29, 2023

Codecov Report

Attention: Patch coverage is 78.12500% with 7 lines in your changes are missing coverage. Please review.

Project coverage is 79.23%. Comparing base (3148d2b) to head (b624e9f).

Files Patch % Lines
pkg/scheduler/objects/queue.go 50.00% 2 Missing and 2 partials ⚠️
pkg/webservice/handlers.go 91.30% 1 Missing and 1 partial ⚠️
pkg/scheduler/partition.go 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #687      +/-   ##
==========================================
+ Coverage   79.22%   79.23%   +0.01%     
==========================================
  Files          82       82              
  Lines       11346    11372      +26     
==========================================
+ Hits         8989     9011      +22     
- Misses       2037     2039       +2     
- Partials      320      322       +2     

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

Copy link
Contributor

@wilfred-s wilfred-s left a comment

Choose a reason for hiding this comment

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

I was expecting an API that would return a specific queue with its details. In this case we return a subtree rooted at a certain point. I would have expected just the one queue to be returned as a lightweight object without the whole subtree attached. There is no difference for a leaf queue but further up the hierarchy there is.

pkg/webservice/handlers.go Outdated Show resolved Hide resolved
pkg/webservice/handlers.go Outdated Show resolved Hide resolved
pkg/webservice/handlers.go Outdated Show resolved Hide resolved
Copy link
Member

@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.

@steinsgateted nice patch. there are some minor comments, and please take a look. thanks!

for _, child := range childes {
queueInfo.ChildrenNames = append(queueInfo.ChildrenNames, child.Name)
}
// we have held the read lock so following method should not take lock again.
Copy link
Member

Choose a reason for hiding this comment

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

those code is almost equal to GetPartitionQueueDAOInfo. Could you do a bit refactor for them?

func (sq *Queue) GetSingleQueueDAOInfo() dao.PartitionQueueDAOInfo {
queueInfo := dao.PartitionQueueDAOInfo{}
childes := sq.GetCopyOfChildren()
queueInfo.ChildrenNames = make([]string, 0, len(childes))
Copy link
Member

Choose a reason for hiding this comment

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

maybe GetPartitionQueueDAOInfo could fill up this field also?

pkg/webservice/routes.go Outdated Show resolved Hide resolved
@steinsgateted
Copy link
Contributor Author

steinsgateted commented Feb 4, 2024

@wilfred-s @chia7712
Sorry for the late reply, thanks for the review.

  1. The default is to display information about a single queue.
    Only the Chidren QueueName is displayed, not all the information of the Chidren Queue (single level).
    /ws/v1/partition/%s/queue/%s/exclude=children

  2. Display all information about Chidren Queue (subtree).
    /ws/v1/partition/%s/queue/%s/include=children

A few changes:

  • In pkg/scheduler/objects/queue.go, change GetPartitionQueueDAOInfo() to GetPartitionQueueDAOInfo(exclude bool)

    exclude is true, which means there is no children Queue Object, and only the children's queue path will be recorded.

  • In pkg/webservice/handlers_test.go, assertAppStateAllow function rename to assertAppStateNotAllow

  • In pkg/webservice/handlers_test.go, assertActiveStateAllow function rename to assertActiveStateNotAllow

  • In pkg/webservice/handlers_test.go, add new function assertQueueInvalid

Also, I would like some clarifications.
Do we recommend renaming the QueueName of PartitionQueueDAOInfo to QueuePath?
Because it is actually QueuePath
queueInfo.QueueName = sq.QueuePath

Copy link
Contributor

@wilfred-s wilfred-s left a comment

Choose a reason for hiding this comment

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

almost there, some small simplifications and cleanup requested

Comment on lines 630 to 639
children := sq.GetCopyOfChildren()
queueInfo.Children = make([]dao.PartitionQueueDAOInfo, 0, len(children))
if exclude {
for _, child := range children {
queueInfo.ChildrenNames = append(queueInfo.ChildrenNames, child.QueuePath)
}
} else {
for _, child := range children {
queueInfo.Children = append(queueInfo.Children, child.GetPartitionQueueDAOInfo(false))
}
Copy link
Contributor

Choose a reason for hiding this comment

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

refactor: only need to get a copy of children if we need to recurse into them:

if !exclude {
	children := sq.GetCopyOfChildren()
	queueInfo.Children = make([]dao.PartitionQueueDAOInfo, 0, len(children))
	for _, child := range children {
		queueInfo.Children = append(queueInfo.Children, child.GetPartitionQueueDAOInfo(false))
	}
}

Leave adding the child path names to the locked code below

Copy link
Contributor

Choose a reason for hiding this comment

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

Add this:

for _, child := range children {
	queueInfo.ChildrenNames = append(queueInfo.ChildrenNames, child.QueuePath)
}

around properties for loop line 660

Comment on lines 669 to 686
// The default is to exclude children
queueDao := queue.GetPartitionQueueDAOInfo(true)
// exclude children
if exclude := strings.ToLower(r.URL.Query().Get("exclude")); exclude != "" {
if exclude != "children" {
buildJSONErrorResponse(w, "Only following exclude is allowed: children", http.StatusBadRequest)
return
}
}
// include children
if include := strings.ToLower(r.URL.Query().Get("include")); include != "" {
if include == "children" {
queueDao = queue.GetPartitionQueueDAOInfo(false)
} else {
buildJSONErrorResponse(w, "Only following include is allowed: children", http.StatusBadRequest)
return
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

A simple subtree query parameter is a much more elegant solution.
If the parameter is there we call GetPartitionQueueDAOInfo(true) otherwise GetPartitionQueueDAOInfo(false) The default, and not present, is false so code wise it would look a bit like this:

queueDao := queue.GetPartitionQueueDAOInfo(r.URL.Query().Has("subtree"))

It checks for the presence of the key subtree

@steinsgateted
Copy link
Contributor Author

@wilfred-s Thank you for your review. I modified.

Copy link
Contributor

@wilfred-s wilfred-s left a comment

Choose a reason for hiding this comment

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

LGTM +1
Adding to the 1.5 release

@wilfred-s wilfred-s closed this in e9805c9 Feb 26, 2024
wilfred-s pushed a commit that referenced this pull request Feb 26, 2024
Expose a REST API for specific queue:
  /ws/v1/partition/%s/queue/%s
  /ws/v1/partition/%s/queue/%s?aubtree

The call takes one query parameter "subtree" if provided the whole tree
of queues rooted at the level requested in the call will be returned. If
"subtree" is not set only the queue requested will be returned

Closes: #687

Signed-off-by: Wilfred Spiegelenburg <[email protected]>
(cherry picked from commit e9805c9)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants