You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@yunikorn.apache.org by GitBox <gi...@apache.org> on 2022/07/18 00:12:54 UTC

[GitHub] [yunikorn-core] wilfred-s commented on a diff in pull request #423: [YUNIKORN-1263] Add pending requests to applciation object in REST API

wilfred-s commented on code in PR #423:
URL: https://github.com/apache/yunikorn-core/pull/423#discussion_r922914933


##########
pkg/scheduler/objects/allocation_ask.go:
##########
@@ -51,10 +52,17 @@ type AllocationAsk struct {
 	requiredNode     string
 	allowPreemption  bool
 	originator       bool
+	allocLog         map[string]*AllocationLogEntry
 
 	sync.RWMutex
 }
 
+type AllocationLogEntry struct {
+	Message   string
+	Timestamp time.Time

Review Comment:
   Timestamp is ambiguous. If count > 1 the timestamp is linked to the latest occurrence. That either needs to show in the name or we need two: first  occurrence and most recent occurrence timestamp.



##########
pkg/webservice/handlers.go:
##########
@@ -224,6 +226,42 @@ func getApplicationJSON(app *objects.Application) *dao.ApplicationDAOInfo {
 		}
 		allocationInfo = append(allocationInfo, allocInfo)
 	}
+	for _, req := range requests {

Review Comment:
   Move all this processing into its own function. Do the sorting in there as per comment earlier around unlocked sorting.



##########
pkg/scheduler/objects/allocation_ask.go:
##########
@@ -188,6 +197,48 @@ func (aa *AllocationAsk) GetAllocatedResource() *resources.Resource {
 	return aa.AllocatedResource
 }
 
+// LogSchedulingFailure keeps track of preconditions not being met for an allocation
+func (aa *AllocationAsk) LogAllocationFailure(message string, allocate bool) {
+	// for now, don't log reservations
+	if !allocate {
+		return
+	}
+
+	aa.Lock()
+	defer aa.Unlock()
+
+	entry, ok := aa.allocLog[message]
+	if !ok {
+		entry = &AllocationLogEntry{
+			Message: message,
+		}
+		aa.allocLog[message] = entry
+	}
+	entry.Timestamp = time.Now()
+	entry.Count++
+}
+
+// GetSchedulingLog returns a list of log entries corresponding to allocation preconditions not being met
+func (aa *AllocationAsk) GetAllocationLog() []*AllocationLogEntry {

Review Comment:
   Comment differs from real function name



##########
pkg/webservice/dao/allocation_ask_info.go:
##########
@@ -0,0 +1,42 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
+package dao
+
+type AllocationAskLogDAOInfo struct {
+	Message   string `json:"message"`
+	Timestamp int64  `json:"timestamp"`
+	Count     int32  `json:"count"`
+}
+
+type AllocationAskDAOInfo struct {
+	AllocationKey      string                    `json:"allocationKey"`
+	AllocationTags     map[string]string         `json:"allocationTags"`
+	RequestTime        int64                     `json:"requestTime"`
+	ResourcePerAlloc   map[string]int64          `json:"resource"`
+	PendingCount       int32                     `json:"pendingCount"`
+	Priority           string                    `json:"priority"`
+	QueueName          string                    `json:"queueName"`
+	RequiredNodeID     *string                   `json:"requiredNodeId"`

Review Comment:
   Why handle this one different than other optional values in objects?
   A simple empty string would suffice, unless we go back and do this for all optional values.



##########
pkg/scheduler/objects/allocation_ask.go:
##########
@@ -188,6 +197,48 @@ func (aa *AllocationAsk) GetAllocatedResource() *resources.Resource {
 	return aa.AllocatedResource
 }
 
+// LogSchedulingFailure keeps track of preconditions not being met for an allocation
+func (aa *AllocationAsk) LogAllocationFailure(message string, allocate bool) {
+	// for now, don't log reservations
+	if !allocate {
+		return
+	}
+
+	aa.Lock()
+	defer aa.Unlock()
+
+	entry, ok := aa.allocLog[message]
+	if !ok {
+		entry = &AllocationLogEntry{
+			Message: message,
+		}
+		aa.allocLog[message] = entry
+	}
+	entry.Timestamp = time.Now()
+	entry.Count++
+}
+
+// GetSchedulingLog returns a list of log entries corresponding to allocation preconditions not being met
+func (aa *AllocationAsk) GetAllocationLog() []*AllocationLogEntry {
+	aa.RLock()
+	defer aa.RUnlock()
+
+	res := make([]*AllocationLogEntry, len(aa.allocLog))
+	i := 0
+	for _, log := range aa.allocLog {
+		res[i] = &AllocationLogEntry{
+			Message:   log.Message,
+			Timestamp: log.Timestamp,
+			Count:     log.Count,
+		}
+		i++
+	}
+	sort.SliceStable(res, func(i, j int) bool {
+		return res[i].Timestamp.Before(res[j].Timestamp)

Review Comment:
   Can we sort outside of the lock? This could even be postponed to the web handling when it is all done out of band.



##########
pkg/scheduler/objects/allocation_ask.go:
##########
@@ -188,6 +197,48 @@ func (aa *AllocationAsk) GetAllocatedResource() *resources.Resource {
 	return aa.AllocatedResource
 }
 
+// LogSchedulingFailure keeps track of preconditions not being met for an allocation
+func (aa *AllocationAsk) LogAllocationFailure(message string, allocate bool) {

Review Comment:
   Comment differs from real function name



##########
pkg/webservice/handlers.go:
##########
@@ -224,6 +226,42 @@ func getApplicationJSON(app *objects.Application) *dao.ApplicationDAOInfo {
 		}
 		allocationInfo = append(allocationInfo, allocInfo)
 	}
+	for _, req := range requests {
+		count := req.GetPendingAskRepeat()
+		if count > 0 {
+			nodeID := req.GetRequiredNode()
+			nodePtr := &nodeID
+			if nodeID == "" {
+				nodePtr = nil
+			}

Review Comment:
   See comment above on other optional values.



##########
pkg/scheduler/objects/application.go:
##########
@@ -1387,6 +1386,17 @@ func (sa *Application) getPlaceholderAllocations() []*Allocation {
 	return allocations
 }
 
+// get a copy of all requests of the application
+func (sa *Application) GetAllRequests() []*AllocationAsk {
+	sa.RLock()
+	defer sa.RUnlock()
+	var requests []*AllocationAsk
+	for _, req := range sa.requests {
+		requests = append(requests, req)
+	}
+	return requests
+}

Review Comment:
   Code duplication we already have an unlocked `getAllReqeusts()` This locked version should be a wrapper around the unlocked version. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@yunikorn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org