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

change dashboard resource format #338

Merged
merged 1 commit into from
Apr 4, 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
31 changes: 25 additions & 6 deletions internal/usecase/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,30 @@ func (u *DashboardUsecase) GetResources(ctx context.Context, organizationId stri
filteredClusters := funk.Filter(clusters, func(x model.Cluster) bool {
return x.Status != domain.ClusterStatus_DELETED
})

var normal, abnormal int
if filteredClusters != nil {
out.Stack = fmt.Sprintf("%d 개", len(filteredClusters.([]model.Cluster)))
} else {
out.Stack = "0 개"
for _, cluster := range filteredClusters.([]model.Cluster) {
clientSet, err := kubernetes.GetClientFromClusterId(ctx, cluster.ID.String())
if err != nil {
return out, errors.Wrap(err, "Failed to get client set for user cluster")
}
// get cluster info
clusterInfo, err := clientSet.CoreV1().Services("kube-system").List(context.TODO(), metav1.ListOptions{LabelSelector: "kubernetes.io/cluster-service"})
if err != nil {
abnormal++
log.Debugf(ctx, "Failed to get cluster info: %v\n", err)
continue
}
if clusterInfo.Items[0].ObjectMeta.Labels["kubernetes.io/cluster-service"] == "true" {
normal++
} else {
abnormal++
}
}
}
out.Stack.Normal = strconv.Itoa(normal)
out.Stack.Abnormal = strconv.Itoa(abnormal)

// CPU
/*
Expand All @@ -210,7 +229,7 @@ func (u *DashboardUsecase) GetResources(ctx context.Context, organizationId stri
cpu = cpu + cpuVal
}
}
out.Cpu = fmt.Sprintf("%d 개", cpu)
out.Cpu = strconv.Itoa(cpu)

// Memory
result, err = thanosClient.Get(ctx, "sum by (taco_cluster) (machine_memory_bytes)")
Expand All @@ -228,7 +247,7 @@ func (u *DashboardUsecase) GetResources(ctx context.Context, organizationId stri
memory = memory + memory_
}
}
out.Memory = fmt.Sprintf("%v GiB", math.Round(memory))
out.Memory = fmt.Sprintf("%v", math.Round(memory))

// Storage
result, err = thanosClient.Get(ctx, "sum by (taco_cluster) (kubelet_volume_stats_capacity_bytes)")
Expand All @@ -246,7 +265,7 @@ func (u *DashboardUsecase) GetResources(ctx context.Context, organizationId stri
storage = storage + storage_
}
}
out.Storage = fmt.Sprintf("%v GiB", math.Round(storage))
out.Storage = fmt.Sprintf("%v", math.Round(storage))

return
}
Expand Down
5 changes: 4 additions & 1 deletion pkg/domain/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,10 @@ type GetDashboardChartResponse struct {
}

type DashboardResource struct {
Stack string `json:"stack"`
Stack struct {
Normal string `json:"normal"`
Abnormal string `json:"abnormal"`
} `json:"stack"`
Cpu string `json:"cpu"`
Memory string `json:"memory"`
Storage string `json:"storage"`
Expand Down
Loading