Skip to content

Commit 3b7168c

Browse files
authored
Fix number of API replicas shown in cortex cluster info cmd (#2140)
1 parent 9c2c3a7 commit 3b7168c

File tree

3 files changed

+23
-12
lines changed

3 files changed

+23
-12
lines changed

cli/cmd/cluster.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -887,7 +887,7 @@ func printInfoNodes(infoResponse *schema.InfoResponse) {
887887
numAPIInstances := len(infoResponse.NodeInfos)
888888

889889
var totalReplicas int
890-
var doesClusterHaveGPUs, doesClusterHaveInfs bool
890+
var doesClusterHaveGPUs, doesClusterHaveInfs, doesClusterHaveAsyncAPIs bool
891891
for _, nodeInfo := range infoResponse.NodeInfos {
892892
totalReplicas += nodeInfo.NumReplicas
893893
if nodeInfo.ComputeUserCapacity.GPU > 0 {
@@ -896,6 +896,9 @@ func printInfoNodes(infoResponse *schema.InfoResponse) {
896896
if nodeInfo.ComputeUserCapacity.Inf > 0 {
897897
doesClusterHaveInfs = true
898898
}
899+
if nodeInfo.NumAsyncGatewayReplicas > 0 {
900+
doesClusterHaveAsyncAPIs = true
901+
}
899902
}
900903

901904
var pendingReplicasStr string
@@ -913,6 +916,7 @@ func printInfoNodes(infoResponse *schema.InfoResponse) {
913916
{Title: "instance type"},
914917
{Title: "lifecycle"},
915918
{Title: "replicas"},
919+
{Title: "async gateway replicas", Hidden: !doesClusterHaveAsyncAPIs},
916920
{Title: "CPU (requested / total allocatable)"},
917921
{Title: "memory (requested / total allocatable)"},
918922
{Title: "GPU (requested / total allocatable)", Hidden: !doesClusterHaveGPUs},
@@ -930,7 +934,7 @@ func printInfoNodes(infoResponse *schema.InfoResponse) {
930934
memStr := nodeInfo.ComputeUserRequested.Mem.String() + " / " + nodeInfo.ComputeUserCapacity.Mem.String()
931935
gpuStr := s.Int64(nodeInfo.ComputeUserRequested.GPU) + " / " + s.Int64(nodeInfo.ComputeUserCapacity.GPU)
932936
infStr := s.Int64(nodeInfo.ComputeUserRequested.Inf) + " / " + s.Int64(nodeInfo.ComputeUserCapacity.Inf)
933-
rows = append(rows, []interface{}{nodeInfo.InstanceType, lifecycle, nodeInfo.NumReplicas, cpuStr, memStr, gpuStr, infStr})
937+
rows = append(rows, []interface{}{nodeInfo.InstanceType, lifecycle, nodeInfo.NumReplicas, nodeInfo.NumAsyncGatewayReplicas, cpuStr, memStr, gpuStr, infStr})
934938
}
935939

936940
t := table.Table{

pkg/operator/endpoints/info.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ func getNodeInfos() ([]schema.NodeInfo, int, error) {
106106
pod := pods[i]
107107

108108
_, isAPIPod := pod.Labels["apiName"]
109+
asyncDeploymentType, isAsyncPod := pod.Labels["cortex.dev/async"]
109110

110111
if pod.Spec.NodeName == "" && isAPIPod {
111112
numPendingReplicas++
@@ -118,7 +119,12 @@ func getNodeInfos() ([]schema.NodeInfo, int, error) {
118119
}
119120

120121
if isAPIPod {
121-
node.NumReplicas++
122+
if !isAsyncPod || asyncDeploymentType == "api" {
123+
node.NumReplicas++
124+
}
125+
if !isAsyncPod || asyncDeploymentType == "gateway" {
126+
node.NumAsyncGatewayReplicas++
127+
}
122128
}
123129

124130
cpu, mem, gpu, inf := k8s.TotalPodCompute(&pod.Spec)

pkg/operator/schema/schema.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,16 @@ type InfoResponse struct {
3131
}
3232

3333
type NodeInfo struct {
34-
Name string `json:"name"`
35-
NodeGroupName string `json:"nodegroup_name"`
36-
InstanceType string `json:"instance_type"`
37-
IsSpot bool `json:"is_spot"`
38-
Price float64 `json:"price"`
39-
NumReplicas int `json:"num_replicas"`
40-
ComputeUserCapacity userconfig.Compute `json:"compute_user_capacity"` // the total resources available to the user on a node
41-
ComputeAvailable userconfig.Compute `json:"compute_available"` // unused resources on a node
42-
ComputeUserRequested userconfig.Compute `json:"compute_user_requested"` // total resources requested by user on a node
34+
Name string `json:"name"`
35+
NodeGroupName string `json:"nodegroup_name"`
36+
InstanceType string `json:"instance_type"`
37+
IsSpot bool `json:"is_spot"`
38+
Price float64 `json:"price"`
39+
NumReplicas int `json:"num_replicas"`
40+
NumAsyncGatewayReplicas int `json:"num_async_gateway_replicas"`
41+
ComputeUserCapacity userconfig.Compute `json:"compute_user_capacity"` // the total resources available to the user on a node
42+
ComputeAvailable userconfig.Compute `json:"compute_available"` // unused resources on a node
43+
ComputeUserRequested userconfig.Compute `json:"compute_user_requested"` // total resources requested by user on a node
4344
}
4445

4546
type DeployResult struct {

0 commit comments

Comments
 (0)