Skip to content

Commit

Permalink
Merge pull request openinfradev#412 from seungkyua/20240422_change_wo…
Browse files Browse the repository at this point in the history
…rkload_dashboard

20240422 change workload dashboard
  • Loading branch information
seungkyua authored Apr 22, 2024
2 parents f02321d + c5b63a1 commit 5c16eea
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 154 deletions.
46 changes: 18 additions & 28 deletions api/swagger/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -12775,35 +12775,14 @@ const docTemplate = `{
"github_com_openinfradev_tks-api_pkg_domain.GetDashboardWorkloadResponse": {
"type": "object",
"properties": {
"cronJobCount": {
"type": "integer"
},
"cronJobPodCount": {
"type": "integer"
},
"daemonSetCount": {
"type": "integer"
},
"daemonSetPodCount": {
"type": "integer"
},
"deploymentCount": {
"type": "integer"
},
"deploymentPodCount": {
"type": "integer"
},
"jobCount": {
"type": "integer"
},
"jobPodCount": {
"type": "integer"
},
"statefulSetCount": {
"type": "integer"
"data": {
"type": "array",
"items": {
"$ref": "#/definitions/github_com_openinfradev_tks-api_pkg_domain.WorkloadData"
}
},
"statefulSetPodCount": {
"type": "integer"
"title": {
"type": "string"
}
}
},
Expand Down Expand Up @@ -16121,6 +16100,17 @@ const docTemplate = `{
}
}
},
"github_com_openinfradev_tks-api_pkg_domain.WorkloadData": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"value": {
"type": "integer"
}
}
},
"github_com_openinfradev_tks-api_pkg_domain_admin.AddPermittedPolicyTemplatesForOrganizationRequest": {
"type": "object",
"properties": {
Expand Down
46 changes: 18 additions & 28 deletions api/swagger/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -12769,35 +12769,14 @@
"github_com_openinfradev_tks-api_pkg_domain.GetDashboardWorkloadResponse": {
"type": "object",
"properties": {
"cronJobCount": {
"type": "integer"
},
"cronJobPodCount": {
"type": "integer"
},
"daemonSetCount": {
"type": "integer"
},
"daemonSetPodCount": {
"type": "integer"
},
"deploymentCount": {
"type": "integer"
},
"deploymentPodCount": {
"type": "integer"
},
"jobCount": {
"type": "integer"
},
"jobPodCount": {
"type": "integer"
},
"statefulSetCount": {
"type": "integer"
"data": {
"type": "array",
"items": {
"$ref": "#/definitions/github_com_openinfradev_tks-api_pkg_domain.WorkloadData"
}
},
"statefulSetPodCount": {
"type": "integer"
"title": {
"type": "string"
}
}
},
Expand Down Expand Up @@ -16115,6 +16094,17 @@
}
}
},
"github_com_openinfradev_tks-api_pkg_domain.WorkloadData": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"value": {
"type": "integer"
}
}
},
"github_com_openinfradev_tks-api_pkg_domain_admin.AddPermittedPolicyTemplatesForOrganizationRequest": {
"type": "object",
"properties": {
Expand Down
33 changes: 13 additions & 20 deletions api/swagger/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1794,26 +1794,12 @@ definitions:
type: object
github_com_openinfradev_tks-api_pkg_domain.GetDashboardWorkloadResponse:
properties:
cronJobCount:
type: integer
cronJobPodCount:
type: integer
daemonSetCount:
type: integer
daemonSetPodCount:
type: integer
deploymentCount:
type: integer
deploymentPodCount:
type: integer
jobCount:
type: integer
jobPodCount:
type: integer
statefulSetCount:
type: integer
statefulSetPodCount:
type: integer
data:
items:
$ref: '#/definitions/github_com_openinfradev_tks-api_pkg_domain.WorkloadData'
type: array
title:
type: string
type: object
github_com_openinfradev_tks-api_pkg_domain.GetMandatoryPoliciesResponse:
properties:
Expand Down Expand Up @@ -4021,6 +4007,13 @@ definitions:
widgetKey:
type: string
type: object
github_com_openinfradev_tks-api_pkg_domain.WorkloadData:
properties:
name:
type: string
value:
type: integer
type: object
github_com_openinfradev_tks-api_pkg_domain_admin.AddPermittedPolicyTemplatesForOrganizationRequest:
properties:
policyTemplateIds:
Expand Down
77 changes: 9 additions & 68 deletions internal/usecase/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -870,43 +870,20 @@ func (u *DashboardUsecase) GetWorkload(ctx context.Context, organizationId strin
return nil, err
}

dwr := &domain.GetDashboardWorkloadResponse{}
dwr := &domain.GetDashboardWorkloadResponse{Title: "자원별 Pod 배포 현황"}

// Deployment count
var count int
query := fmt.Sprintf("count (kube_deployment_status_replicas_available{taco_cluster=~'%s'} != 0)", clusterIdStr)
// Deployment pod count
count := 0
query := fmt.Sprintf("sum (kube_deployment_status_replicas_available{taco_cluster=~'%s'} )", clusterIdStr)
wm, err := thanosClient.GetWorkload(ctx, query)
if err != nil {
return nil, err
}
if len(wm.Data.Result) > 0 && len(wm.Data.Result[0].Value) > 1 {
count, _ = strconv.Atoi(wm.Data.Result[0].Value[1].(string))
}
dwr.DeploymentCount = count

// Deployment pod count
count = 0
query = fmt.Sprintf("sum (kube_deployment_status_replicas_available{taco_cluster=~'%s'} )", clusterIdStr)
wm, err = thanosClient.GetWorkload(ctx, query)
if err != nil {
return nil, err
}
if len(wm.Data.Result) > 0 && len(wm.Data.Result[0].Value) > 1 {
count, _ = strconv.Atoi(wm.Data.Result[0].Value[1].(string))
}
dwr.DeploymentPodCount = count

// StatefulSet count
count = 0
query = fmt.Sprintf("count (kube_statefulset_status_replicas_available{taco_cluster=~'%s'} != 0)", clusterIdStr)
wm, err = thanosClient.GetWorkload(ctx, query)
if err != nil {
return nil, err
}
if len(wm.Data.Result) > 0 && len(wm.Data.Result[0].Value) > 1 {
count, _ = strconv.Atoi(wm.Data.Result[0].Value[1].(string))
}
dwr.StatefulSetCount = count
dwr.Data = append(dwr.Data, domain.WorkloadData{Name: "Deployments", Value: count})

// StatefulSet pod count
count = 0
Expand All @@ -918,19 +895,7 @@ func (u *DashboardUsecase) GetWorkload(ctx context.Context, organizationId strin
if len(wm.Data.Result) > 0 && len(wm.Data.Result[0].Value) > 1 {
count, _ = strconv.Atoi(wm.Data.Result[0].Value[1].(string))
}
dwr.StatefulSetPodCount = count

// DaemonSet count
count = 0
query = fmt.Sprintf("count (kube_daemonset_status_number_available{taco_cluster=~'%s'} != 0)", clusterIdStr)
wm, err = thanosClient.GetWorkload(ctx, query)
if err != nil {
return nil, err
}
if len(wm.Data.Result) > 0 && len(wm.Data.Result[0].Value) > 1 {
count, _ = strconv.Atoi(wm.Data.Result[0].Value[1].(string))
}
dwr.DaemonSetCount = count
dwr.Data = append(dwr.Data, domain.WorkloadData{Name: "StatefulSets", Value: count})

// DaemonSet pod count
count = 0
Expand All @@ -942,19 +907,7 @@ func (u *DashboardUsecase) GetWorkload(ctx context.Context, organizationId strin
if len(wm.Data.Result) > 0 && len(wm.Data.Result[0].Value) > 1 {
count, _ = strconv.Atoi(wm.Data.Result[0].Value[1].(string))
}
dwr.DaemonSetPodCount = count

// CronJob count
count = 0
query = fmt.Sprintf("count (kube_cronjob_status_active{taco_cluster=~'%s'} != 0)", clusterIdStr)
wm, err = thanosClient.GetWorkload(ctx, query)
if err != nil {
return nil, err
}
if len(wm.Data.Result) > 0 && len(wm.Data.Result[0].Value) > 1 {
count, _ = strconv.Atoi(wm.Data.Result[0].Value[1].(string))
}
dwr.CronJobCount = count
dwr.Data = append(dwr.Data, domain.WorkloadData{Name: "DaemonSets", Value: count})

// CronJob pod count
count = 0
Expand All @@ -966,19 +919,7 @@ func (u *DashboardUsecase) GetWorkload(ctx context.Context, organizationId strin
if len(wm.Data.Result) > 0 && len(wm.Data.Result[0].Value) > 1 {
count, _ = strconv.Atoi(wm.Data.Result[0].Value[1].(string))
}
dwr.CronJobPodCount = count

// Job count
count = 0
query = fmt.Sprintf("count (kube_job_status_active{taco_cluster=~'%s'} != 0)", clusterIdStr)
wm, err = thanosClient.GetWorkload(ctx, query)
if err != nil {
return nil, err
}
if len(wm.Data.Result) > 0 && len(wm.Data.Result[0].Value) > 1 {
count, _ = strconv.Atoi(wm.Data.Result[0].Value[1].(string))
}
dwr.JobCount = count
dwr.Data = append(dwr.Data, domain.WorkloadData{Name: "CronJobs", Value: count})

// Job pod count
count = 0
Expand All @@ -990,7 +931,7 @@ func (u *DashboardUsecase) GetWorkload(ctx context.Context, organizationId strin
if len(wm.Data.Result) > 0 && len(wm.Data.Result[0].Value) > 1 {
count, _ = strconv.Atoi(wm.Data.Result[0].Value[1].(string))
}
dwr.JobPodCount = count
dwr.Data = append(dwr.Data, domain.WorkloadData{Name: "Jobs", Value: count})

return dwr, nil
}
Expand Down
16 changes: 6 additions & 10 deletions pkg/domain/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,17 +223,13 @@ type GetDashboardPolicyStatisticsResponse struct {
PolicyStatisticsResponse
}

type WorkloadData struct {
Name string `json:"name"`
Value int `json:"value"`
}
type GetDashboardWorkloadResponse struct {
DeploymentCount int `json:"deploymentCount"`
DeploymentPodCount int `json:"deploymentPodCount"`
StatefulSetCount int `json:"statefulSetCount"`
StatefulSetPodCount int `json:"statefulSetPodCount"`
DaemonSetCount int `json:"daemonSetCount"`
DaemonSetPodCount int `json:"daemonSetPodCount"`
CronJobCount int `json:"cronJobCount"`
CronJobPodCount int `json:"cronJobPodCount"`
JobCount int `json:"jobCount"`
JobPodCount int `json:"jobPodCount"`
Title string `json:"title"`
Data []WorkloadData `json:"data"`
}

type GetDashboardPolicyViolationTop5Response struct {
Expand Down

0 comments on commit 5c16eea

Please sign in to comment.