Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: change pro get run pod num #2007

Merged
merged 1 commit into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading