Skip to content

Commit

Permalink
[YUNIKORN-2175] Add queue headRoom for Rest API querying (#727)
Browse files Browse the repository at this point in the history
Closes: #727

Signed-off-by: Peter Bacsko <pbacsko@cloudera.com>
  • Loading branch information
zhuqi-lucas authored and pbacsko committed Nov 23, 2023
1 parent 82b35ad commit a9dcab4
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 10 deletions.
3 changes: 1 addition & 2 deletions pkg/scheduler/objects/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -994,8 +994,7 @@ func (sa *Application) tryAllocate(headRoom *resources.Resource, allowPreemption
}
}
}

sa.appEvents.sendAppDoesNotFitEvent(request)
sa.appEvents.sendAppDoesNotFitEvent(request, headRoom)
continue
}

Expand Down
7 changes: 4 additions & 3 deletions pkg/scheduler/objects/application_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"golang.org/x/time/rate"

"github.com/apache/yunikorn-core/pkg/common"
"github.com/apache/yunikorn-core/pkg/common/resources"
"github.com/apache/yunikorn-core/pkg/events"
"github.com/apache/yunikorn-scheduler-interface/lib/go/si"
)
Expand All @@ -35,11 +36,11 @@ type applicationEvents struct {
limiter *rate.Limiter
}

func (evt *applicationEvents) sendAppDoesNotFitEvent(request *AllocationAsk) {
func (evt *applicationEvents) sendAppDoesNotFitEvent(request *AllocationAsk, headroom *resources.Resource) {
if !evt.eventSystem.IsEventTrackingEnabled() || !evt.limiter.Allow() {
return
}
message := fmt.Sprintf("Application %s does not fit into %s queue", request.GetApplicationID(), evt.app.queuePath)
message := fmt.Sprintf("Application %s does not fit into %s queue (request resoure %s, headroom %s)", request.GetApplicationID(), evt.app.queuePath, request.GetAllocatedResource(), headroom)
event := events.CreateRequestEventRecord(request.GetAllocationKey(), request.GetApplicationID(), message, request.GetAllocatedResource())
evt.eventSystem.AddEvent(event)
}
Expand All @@ -48,7 +49,7 @@ func (evt *applicationEvents) sendPlaceholderLargerEvent(ph *Allocation, request
if !evt.eventSystem.IsEventTrackingEnabled() {
return
}
message := fmt.Sprintf("Task group '%s' in application '%s': allocation resources '%s' are not matching placeholder '%s' allocation with ID '%s'", ph.GetTaskGroup(), evt.app.ApplicationID, request.GetAllocatedResource().String(), ph.GetAllocatedResource().String(), ph.GetAllocationKey())
message := fmt.Sprintf("Task group '%s' in application '%s': allocation resources '%s' are not matching placeholder '%s' allocation with ID '%s'", ph.GetTaskGroup(), evt.app.ApplicationID, request.GetAllocatedResource(), ph.GetAllocatedResource(), ph.GetAllocationKey())
event := events.CreateRequestEventRecord(ph.GetAllocationKey(), evt.app.ApplicationID, message, request.GetAllocatedResource())
evt.eventSystem.AddEvent(event)
}
Expand Down
7 changes: 4 additions & 3 deletions pkg/scheduler/objects/application_events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"gotest.tools/v3/assert"

"github.com/apache/yunikorn-core/pkg/common"
"github.com/apache/yunikorn-core/pkg/common/resources"
"github.com/apache/yunikorn-scheduler-interface/lib/go/si"
)

Expand Down Expand Up @@ -55,15 +56,15 @@ func TestSendAppDoesNotFitEvent(t *testing.T) {
}
mock := newEventSystemMockDisabled()
appEvents := newApplicationEvents(app, mock)
appEvents.sendAppDoesNotFitEvent(&AllocationAsk{})
appEvents.sendAppDoesNotFitEvent(&AllocationAsk{}, &resources.Resource{})
assert.Equal(t, 0, len(mock.events), "unexpected event")

mock = newEventSystemMock()
appEvents = newApplicationEvents(app, mock)
appEvents.sendAppDoesNotFitEvent(&AllocationAsk{
applicationID: appID0,
allocationKey: aKey,
})
}, &resources.Resource{})
assert.Equal(t, 1, len(mock.events), "event was not generated")
}

Expand All @@ -82,7 +83,7 @@ func TestSendAppDoesNotFitEventWithRateLimiter(t *testing.T) {
appEvents.sendAppDoesNotFitEvent(&AllocationAsk{
applicationID: appID0,
allocationKey: aKey,
})
}, &resources.Resource{})
time.Sleep(10 * time.Millisecond)
}
assert.Equal(t, 1, len(mock.events), "event was not generated")
Expand Down
1 change: 1 addition & 0 deletions pkg/scheduler/objects/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,7 @@ func (sq *Queue) GetPartitionQueueDAOInfo() dao.PartitionQueueDAOInfo {
queueInfo.GuaranteedResource = sq.guaranteedResource.DAOMap()
queueInfo.AllocatedResource = sq.allocatedResource.DAOMap()
queueInfo.PreemptingResource = sq.preemptingResource.DAOMap()
queueInfo.HeadRoom = sq.getHeadRoom().DAOMap()
queueInfo.IsLeaf = sq.isLeaf
queueInfo.IsManaged = sq.isManaged
queueInfo.CurrentPriority = sq.getCurrentPriority()
Expand Down
5 changes: 3 additions & 2 deletions pkg/scheduler/objects/queue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1708,8 +1708,9 @@ func TestGetPartitionQueueDAOInfo(t *testing.T) {
// test resources
root.maxResource = getResource(t)
root.guaranteedResource = getResource(t)
assert.DeepEqual(t, root.GetMaxResource().DAOMap(), root.GetMaxResource().DAOMap())
assert.DeepEqual(t, root.GetGuaranteedResource().DAOMap(), root.GetGuaranteedResource().DAOMap())
assert.DeepEqual(t, root.GetMaxResource().DAOMap(), root.GetPartitionQueueDAOInfo().MaxResource)
assert.DeepEqual(t, root.GetGuaranteedResource().DAOMap(), root.GetPartitionQueueDAOInfo().GuaranteedResource)
assert.DeepEqual(t, root.getHeadRoom().DAOMap(), root.GetPartitionQueueDAOInfo().HeadRoom)

// test allocatingAcceptedApps
root.allocatingAcceptedApps = getAllocatingAcceptedApps()
Expand Down
1 change: 1 addition & 0 deletions pkg/webservice/dao/queue_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type PartitionQueueDAOInfo struct {
GuaranteedResource map[string]int64 `json:"guaranteedResource,omitempty"`
AllocatedResource map[string]int64 `json:"allocatedResource,omitempty"`
PreemptingResource map[string]int64 `json:"preemptingResource,omitempty"`
HeadRoom map[string]int64 `json:"headroom,omitempty"`
IsLeaf bool `json:"isLeaf"` // no omitempty, a false value gives a quick way to understand whether it's leaf.
IsManaged bool `json:"isManaged"` // no omitempty, a false value gives a quick way to understand whether it's managed.
Properties map[string]string `json:"properties,omitempty"`
Expand Down

0 comments on commit a9dcab4

Please sign in to comment.