chenyulin0719 commented on code in PR #762:
URL: https://github.com/apache/yunikorn-core/pull/762#discussion_r1442570437


##########
pkg/webservice/handlers.go:
##########
@@ -418,6 +420,80 @@ func getNodesUtilJSON(partition 
*scheduler.PartitionContext, name string) *dao.N
        }
 }
 
+func getNodeUtilisations(w http.ResponseWriter, r *http.Request) {
+       writeHeaders(w)
+       var result []*dao.PartitionNodesUtilDAOInfo
+       for _, part := range schedulerContext.GetPartitionMapClone() {
+               partitionNodesUtilJSON := getPartitionNodesUtilJSON(part)
+               result = append(result, partitionNodesUtilJSON)
+       }
+
+       if err := json.NewEncoder(w).Encode(result); err != nil {
+               buildJSONErrorResponse(w, err.Error(), 
http.StatusInternalServerError)
+       }
+}
+
+// getPartitionNodesUtilJSON retrieves the utilization of all resource types 
for nodes within a specific partition.
+func getPartitionNodesUtilJSON(partition *scheduler.PartitionContext) 
*dao.PartitionNodesUtilDAOInfo {
+       type UtilizationBucket struct {
+               NodeCount []int      // 10 buckets, each bucket contains number 
of nodes
+               NodeList  [][]string // 10 buckets, each bucket contains node 
name list
+       }
+       resourceBuckets := make(map[string]*UtilizationBucket) // key is 
resource type, value is UtilizationBucket
+
+       // put nodes to buckets
+       for _, node := range partition.GetNodes() {
+               capacity := node.GetCapacity()
+               resourceAllocated := node.GetAllocatedResource()
+               absUsedCapacity := resources.CalculateAbsUsedCapacity(capacity, 
resourceAllocated)
+
+               // append to bucket based on resource type, only count if node 
advertises the resource
+               for resourceType := range capacity.Resources {
+                       idx := 0
+                       if absValue, ok := 
absUsedCapacity.Resources[resourceType]; ok {

Review Comment:
   That's as expected.
   If a key existing in capacity but not in absUsedCapacity(Not used before),  
the node should be count in 0%-10% bucket. (idx=0)
   
   ex:
   If node has GCP/TPU, but never used those resource before.  
   The absUsedCapacity won't have the abs value of GCP/TPU.
   
   We will count the node to 0-10% bucket.
   - resourceBuckets["GPU"].NodeCount[0]++
   - resourceBuckets["TPU"].NodeCount[0]++
   
   



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to