Skip to content

Commit

Permalink
perf: change pro get run pod num (#2007)
Browse files Browse the repository at this point in the history
Signed-off-by: 张启航 <[email protected]>
  • Loading branch information
ZhangSetSail authored Nov 13, 2024
1 parent 1329d10 commit a6a8f10
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
3 changes: 3 additions & 0 deletions api/handler/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,10 @@ func (c *clusterAction) GetClusterInfo(ctx context.Context) (*model.ClusterResou
query := fmt.Sprint(`rbd_api_exporter_cluster_pod_number`)
podNumber := c.prometheusCli.GetMetric(query, time.Now())
var instance string
var runPodNumber int
for _, podNum := range podNumber.MetricData.MetricValues {
instance = podNum.Metadata["instance"]
runPodNumber = int(podNum.Sample.Value())
}

query = fmt.Sprintf(`rbd_api_exporter_cluster_pod_memory{instance="%v"}`, instance)
Expand Down Expand Up @@ -274,6 +276,7 @@ func (c *clusterAction) GetClusterInfo(ctx context.Context) (*model.ClusterResou
ResourceProxyStatus: true,
K8sVersion: k8sutil.GetKubeVersion().String(),
NodeReady: nodeReady,
RunPodNumber: runPodNumber,
}

result.AllNode = len(nodes)
Expand Down
5 changes: 4 additions & 1 deletion api/handler/tenant.go
Original file line number Diff line number Diff line change
Expand Up @@ -477,8 +477,11 @@ func (t *TenantAction) initClusterResource(ctx context.Context) error {
for i := range usedNodeList {
node := usedNodeList[i]
time.Sleep(50 * time.Microsecond)
labelSelector := "creator=Rainbond"
podList, err := t.kubeClient.CoreV1().Pods(metav1.NamespaceAll).List(ctx, metav1.ListOptions{
FieldSelector: fields.SelectorFromSet(fields.Set{"spec.nodeName": node.Name}).String()})
FieldSelector: fields.SelectorFromSet(fields.Set{"spec.nodeName": node.Name}).String(),
LabelSelector: labelSelector,
})
if err != nil {
logrus.Errorf("get node %v pods error:%v", node.Name, err)
continue
Expand Down
5 changes: 3 additions & 2 deletions api/model/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
corev1 "k8s.io/api/core/v1"
)

//ClusterResource -
// ClusterResource -
type ClusterResource struct {
AllNode int `json:"all_node"`
NotReadyNode int `json:"notready_node"`
Expand All @@ -30,6 +30,7 @@ type ClusterResource struct {
ResourceProxyStatus bool `json:"resource_proxy_status"`
K8sVersion string `json:"k8s_version"`
NodeReady int32 `json:"node_ready"`
RunPodNumber int `json:"run_pod_number"`
}

// NodeResource is a collection of compute resource.
Expand Down Expand Up @@ -70,7 +71,7 @@ func (r *NodeResource) Add(rl corev1.ResourceList) {
}
}

//GatewayResource -
// GatewayResource -
type GatewayResource struct {
Name string `json:"name"`
Namespace string `json:"namespace"`
Expand Down

0 comments on commit a6a8f10

Please sign in to comment.