This is an automated email from the ASF dual-hosted git repository.

pbacsko pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/yunikorn-core.git


The following commit(s) were added to refs/heads/master by this push:
     new 23214ea5 [YUNIKORN-2371] Add failed headroom checks to the allocation 
log (#781)
23214ea5 is described below

commit 23214ea54db56b90edc50b78857c19a6c9152952
Author: Peter Bacsko <[email protected]>
AuthorDate: Thu Feb 1 00:54:25 2024 +0100

    [YUNIKORN-2371] Add failed headroom checks to the allocation log (#781)
    
    Closes: #781
    
    Signed-off-by: Peter Bacsko <[email protected]>
---
 pkg/scheduler/objects/application.go      |  5 +++
 pkg/scheduler/objects/application_test.go | 67 +++++++++++++++++++++++++++----
 2 files changed, 65 insertions(+), 7 deletions(-)

diff --git a/pkg/scheduler/objects/application.go 
b/pkg/scheduler/objects/application.go
index 8f1f49a5..17fb264a 100644
--- a/pkg/scheduler/objects/application.go
+++ b/pkg/scheduler/objects/application.go
@@ -57,6 +57,9 @@ var rateLimitedAppLog *log.RateLimitedLogger
 const (
        Soft string = "Soft"
        Hard string = "Hard"
+
+       NotEnoughUserQuota  = "Not enough user quota"
+       NotEnoughQueueQuota = "Not enough queue quota"
 )
 
 type PlaceholderData struct {
@@ -951,6 +954,7 @@ func (sa *Application) tryAllocate(headRoom 
*resources.Resource, allowPreemption
                // NOTE: preemption most likely will not help in this case. The 
chance that preemption helps is mall
                // as the preempted allocation must be for the same user in a 
different queue in the hierarchy...
                if !userHeadroom.FitInMaxUndef(request.GetAllocatedResource()) {
+                       request.LogAllocationFailure(NotEnoughUserQuota, true) 
// error message MUST be constant!
                        continue
                }
 
@@ -970,6 +974,7 @@ func (sa *Application) tryAllocate(headRoom 
*resources.Resource, allowPreemption
                                }
                        }
                        sa.appEvents.sendAppDoesNotFitEvent(request, headRoom)
+                       request.LogAllocationFailure(NotEnoughQueueQuota, true) 
// error message MUST be constant!
                        continue
                }
 
diff --git a/pkg/scheduler/objects/application_test.go 
b/pkg/scheduler/objects/application_test.go
index 684f50c4..b8286ff2 100644
--- a/pkg/scheduler/objects/application_test.go
+++ b/pkg/scheduler/objects/application_test.go
@@ -39,6 +39,15 @@ import (
        "github.com/apache/yunikorn-scheduler-interface/lib/go/si"
 )
 
+var (
+       nilNodeIterator = func() NodeIterator {
+               return nil
+       }
+       nilGetNode = func(string) *Node {
+               return nil
+       }
+)
+
 func setupUGM() {
        userManager := ugm.GetUserManager()
        userManager.ClearUserTrackers()
@@ -2272,13 +2281,7 @@ func TestAppDoesNotFitEvent(t *testing.T) {
        app.sortedRequests = sr
        attempts := 0
 
-       app.tryAllocate(headroom, true, time.Second, &attempts, func() 
NodeIterator {
-               return nil
-       }, func() NodeIterator {
-               return nil
-       }, func(s string) *Node {
-               return nil
-       })
+       app.tryAllocate(headroom, true, time.Second, &attempts, 
nilNodeIterator, nilNodeIterator, nilGetNode)
 
        noEvents := 0
        err = common.WaitFor(10*time.Millisecond, time.Second, func() bool {
@@ -2294,6 +2297,56 @@ func TestAppDoesNotFitEvent(t *testing.T) {
        assert.Equal(t, "alloc-0", records[1].ObjectID)
 }
 
+func TestAllocationFailures(t *testing.T) {
+       setupUGM()
+
+       res, err := resources.NewResourceFromConf(map[string]string{"memory": 
"100", "vcores": "10"})
+       assert.NilError(t, err)
+       headroom, err := 
resources.NewResourceFromConf(map[string]string{"memory": "0", "vcores": "0"})
+       assert.NilError(t, err)
+       ask := newAllocationAsk("alloc-0", "app-1", res)
+       app := newApplication(appID1, "default", "root")
+       queue, err := createRootQueue(nil)
+       assert.NilError(t, err, "queue create failed")
+       app.queue = queue
+       sr := sortedRequests{}
+       sr.insert(ask)
+       app.sortedRequests = sr
+       attempts := 0
+
+       // case #1: not enough queue headroom
+       app.tryAllocate(headroom, true, time.Second, &attempts, 
nilNodeIterator, nilNodeIterator, nilGetNode)
+       assert.Equal(t, 1, len(ask.allocLog))
+       assert.Equal(t, int32(1), ask.allocLog[NotEnoughQueueQuota].Count)
+
+       // case #2: not enough user quota
+       // create config with resource limits for "testuser"
+       conf := configs.QueueConfig{
+               Name:      "root",
+               Parent:    true,
+               SubmitACL: "*",
+               Limits: []configs.Limit{
+                       {
+                               Limit: "leaf queue limit",
+                               Users: []string{
+                                       "testuser",
+                               },
+                               MaxResources: map[string]string{
+                                       "memory": "1",
+                                       "vcores": "1",
+                               },
+                       },
+               },
+       }
+       err = ugm.GetUserManager().UpdateConfig(conf, "root")
+       assert.NilError(t, err)
+       headroom, err = 
resources.NewResourceFromConf(map[string]string{"memory": "1000", "vcores": 
"1000"})
+       assert.NilError(t, err)
+       app.tryAllocate(headroom, true, time.Second, &attempts, 
nilNodeIterator, nilNodeIterator, nilGetNode)
+       assert.Equal(t, 2, len(ask.allocLog))
+       assert.Equal(t, int32(1), ask.allocLog[NotEnoughUserQuota].Count)
+}
+
 func TestGetOutstandingRequests(t *testing.T) {
        // Create a sample Resource and AllocationAsk
        resMap := map[string]string{"memory": "100", "vcores": "10"}


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to