mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-08-16 15:45:56 +08:00
chore: correct order within page result (#6847)
This commit is contained in:
parent
610f4d43e7
commit
89541862cc
@ -338,5 +338,7 @@ func (p *ClustersRepo) GetClusterList(ctx context.Context, req model.ClusterList
|
||||
resp.Total = len(allClusterGroups)
|
||||
resp.Records = records
|
||||
|
||||
resp.SortBy(req.OrderBy)
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
|
@ -440,5 +440,7 @@ func (d *DaemonSetsRepo) GetDaemonSetList(ctx context.Context, req model.DaemonS
|
||||
resp.Total = len(allDaemonSetGroups)
|
||||
resp.Records = records
|
||||
|
||||
resp.SortBy(req.OrderBy)
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
|
@ -440,5 +440,7 @@ func (d *DeploymentsRepo) GetDeploymentList(ctx context.Context, req model.Deplo
|
||||
resp.Total = len(allDeploymentGroups)
|
||||
resp.Records = records
|
||||
|
||||
resp.SortBy(req.OrderBy)
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
|
@ -494,5 +494,7 @@ func (d *JobsRepo) GetJobList(ctx context.Context, req model.JobListRequest) (mo
|
||||
resp.Total = len(allJobGroups)
|
||||
resp.Records = records
|
||||
|
||||
resp.SortBy(req.OrderBy)
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
|
@ -341,5 +341,7 @@ func (p *NamespacesRepo) GetNamespaceList(ctx context.Context, req model.Namespa
|
||||
resp.Total = len(allNamespaceGroups)
|
||||
resp.Records = records
|
||||
|
||||
resp.SortBy(req.OrderBy)
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ var (
|
||||
|
||||
nodeAttrsToEnrich = []string{"k8s_node_name", "k8s_node_uid", "k8s_cluster_name"}
|
||||
|
||||
k8sNodeUIDAttrKey = "k8s_node_uid"
|
||||
k8sNodeGroupAttrKey = "k8s_node_name"
|
||||
|
||||
queryNamesForNodes = map[string][]string{
|
||||
"cpu": {"A"},
|
||||
@ -125,7 +125,7 @@ func (p *NodesRepo) getMetadataAttributes(ctx context.Context, req model.NodeLis
|
||||
}
|
||||
}
|
||||
|
||||
nodeUID := stringData[k8sNodeUIDAttrKey]
|
||||
nodeUID := stringData[k8sNodeGroupAttrKey]
|
||||
if _, ok := nodeAttrs[nodeUID]; !ok {
|
||||
nodeAttrs[nodeUID] = map[string]string{}
|
||||
}
|
||||
@ -220,7 +220,7 @@ func (p *NodesRepo) GetNodeList(ctx context.Context, req model.NodeListRequest)
|
||||
}
|
||||
|
||||
if req.GroupBy == nil {
|
||||
req.GroupBy = []v3.AttributeKey{{Key: k8sNodeUIDAttrKey}}
|
||||
req.GroupBy = []v3.AttributeKey{{Key: k8sNodeGroupAttrKey}}
|
||||
resp.Type = model.ResponseTypeList
|
||||
} else {
|
||||
resp.Type = model.ResponseTypeGroupedList
|
||||
@ -306,7 +306,7 @@ func (p *NodesRepo) GetNodeList(ctx context.Context, req model.NodeListRequest)
|
||||
NodeMemoryAllocatable: -1,
|
||||
}
|
||||
|
||||
if nodeUID, ok := row.Data[k8sNodeUIDAttrKey].(string); ok {
|
||||
if nodeUID, ok := row.Data[k8sNodeGroupAttrKey].(string); ok {
|
||||
record.NodeUID = nodeUID
|
||||
}
|
||||
|
||||
@ -354,5 +354,6 @@ func (p *NodesRepo) GetNodeList(ctx context.Context, req model.NodeListRequest)
|
||||
resp.Total = len(allNodeGroups)
|
||||
resp.Records = records
|
||||
|
||||
resp.SortBy(req.OrderBy)
|
||||
return resp, nil
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ var NodesTableListQuery = v3.QueryRangeParamsV3{
|
||||
},
|
||||
GroupBy: []v3.AttributeKey{
|
||||
{
|
||||
Key: k8sNodeUIDAttrKey,
|
||||
Key: k8sNodeGroupAttrKey,
|
||||
DataType: v3.AttributeKeyDataTypeString,
|
||||
Type: v3.AttributeKeyTypeResource,
|
||||
},
|
||||
@ -46,7 +46,7 @@ var NodesTableListQuery = v3.QueryRangeParamsV3{
|
||||
},
|
||||
GroupBy: []v3.AttributeKey{
|
||||
{
|
||||
Key: k8sNodeUIDAttrKey,
|
||||
Key: k8sNodeGroupAttrKey,
|
||||
DataType: v3.AttributeKeyDataTypeString,
|
||||
Type: v3.AttributeKeyTypeResource,
|
||||
},
|
||||
@ -72,7 +72,7 @@ var NodesTableListQuery = v3.QueryRangeParamsV3{
|
||||
},
|
||||
GroupBy: []v3.AttributeKey{
|
||||
{
|
||||
Key: k8sNodeUIDAttrKey,
|
||||
Key: k8sNodeGroupAttrKey,
|
||||
DataType: v3.AttributeKeyDataTypeString,
|
||||
Type: v3.AttributeKeyTypeResource,
|
||||
},
|
||||
@ -98,7 +98,7 @@ var NodesTableListQuery = v3.QueryRangeParamsV3{
|
||||
},
|
||||
GroupBy: []v3.AttributeKey{
|
||||
{
|
||||
Key: k8sNodeUIDAttrKey,
|
||||
Key: k8sNodeGroupAttrKey,
|
||||
DataType: v3.AttributeKeyDataTypeString,
|
||||
Type: v3.AttributeKeyTypeResource,
|
||||
},
|
||||
@ -132,7 +132,7 @@ var NodesTableListQuery = v3.QueryRangeParamsV3{
|
||||
},
|
||||
GroupBy: []v3.AttributeKey{
|
||||
{
|
||||
Key: k8sNodeUIDAttrKey,
|
||||
Key: k8sNodeGroupAttrKey,
|
||||
DataType: v3.AttributeKeyDataTypeString,
|
||||
Type: v3.AttributeKeyTypeResource,
|
||||
},
|
||||
@ -166,7 +166,7 @@ var NodesTableListQuery = v3.QueryRangeParamsV3{
|
||||
},
|
||||
GroupBy: []v3.AttributeKey{
|
||||
{
|
||||
Key: k8sNodeUIDAttrKey,
|
||||
Key: k8sNodeGroupAttrKey,
|
||||
DataType: v3.AttributeKeyDataTypeString,
|
||||
Type: v3.AttributeKeyTypeResource,
|
||||
},
|
||||
|
@ -404,5 +404,7 @@ func (p *PodsRepo) GetPodList(ctx context.Context, req model.PodListRequest) (mo
|
||||
resp.Total = len(allPodGroups)
|
||||
resp.Records = records
|
||||
|
||||
resp.SortBy(req.OrderBy)
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
|
@ -374,5 +374,7 @@ func (p *PvcsRepo) GetPvcList(ctx context.Context, req model.VolumeListRequest)
|
||||
resp.Total = len(allVolumeGroups)
|
||||
resp.Records = records
|
||||
|
||||
resp.SortBy(req.OrderBy)
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
|
@ -440,5 +440,7 @@ func (d *StatefulSetsRepo) GetStatefulSetList(ctx context.Context, req model.Sta
|
||||
resp.Total = len(allStatefulSetGroups)
|
||||
resp.Records = records
|
||||
|
||||
resp.SortBy(req.OrderBy)
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
|
@ -114,6 +114,47 @@ type PodListResponse struct {
|
||||
Total int `json:"total"`
|
||||
}
|
||||
|
||||
func (r *PodListResponse) SortBy(orderBy *v3.OrderBy) {
|
||||
switch orderBy.ColumnName {
|
||||
case "cpu":
|
||||
sort.Slice(r.Records, func(i, j int) bool {
|
||||
return r.Records[i].PodCPU > r.Records[j].PodCPU
|
||||
})
|
||||
case "cpu_request":
|
||||
sort.Slice(r.Records, func(i, j int) bool {
|
||||
return r.Records[i].PodCPURequest > r.Records[j].PodCPURequest
|
||||
})
|
||||
case "cpu_limit":
|
||||
sort.Slice(r.Records, func(i, j int) bool {
|
||||
return r.Records[i].PodCPULimit > r.Records[j].PodCPULimit
|
||||
})
|
||||
case "memory":
|
||||
sort.Slice(r.Records, func(i, j int) bool {
|
||||
return r.Records[i].PodMemory > r.Records[j].PodMemory
|
||||
})
|
||||
case "memory_request":
|
||||
sort.Slice(r.Records, func(i, j int) bool {
|
||||
return r.Records[i].PodMemoryRequest > r.Records[j].PodMemoryRequest
|
||||
})
|
||||
case "memory_limit":
|
||||
sort.Slice(r.Records, func(i, j int) bool {
|
||||
return r.Records[i].PodMemoryLimit > r.Records[j].PodMemoryLimit
|
||||
})
|
||||
case "restarts":
|
||||
sort.Slice(r.Records, func(i, j int) bool {
|
||||
return r.Records[i].RestartCount > r.Records[j].RestartCount
|
||||
})
|
||||
}
|
||||
|
||||
// the default is descending
|
||||
if orderBy.Order == v3.DirectionAsc {
|
||||
// reverse the list
|
||||
for i, j := 0, len(r.Records)-1; i < j; i, j = i+1, j-1 {
|
||||
r.Records[i], r.Records[j] = r.Records[j], r.Records[i]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
type PodListRecord struct {
|
||||
PodUID string `json:"podUID,omitempty"`
|
||||
PodCPU float64 `json:"podCPU"`
|
||||
@ -151,6 +192,35 @@ type NodeListResponse struct {
|
||||
Total int `json:"total"`
|
||||
}
|
||||
|
||||
func (r *NodeListResponse) SortBy(orderBy *v3.OrderBy) {
|
||||
switch orderBy.ColumnName {
|
||||
case "cpu":
|
||||
sort.Slice(r.Records, func(i, j int) bool {
|
||||
return r.Records[i].NodeCPUUsage > r.Records[j].NodeCPUUsage
|
||||
})
|
||||
case "cpu_allocatable":
|
||||
sort.Slice(r.Records, func(i, j int) bool {
|
||||
return r.Records[i].NodeCPUAllocatable > r.Records[j].NodeCPUAllocatable
|
||||
})
|
||||
case "memory":
|
||||
sort.Slice(r.Records, func(i, j int) bool {
|
||||
return r.Records[i].NodeMemoryUsage > r.Records[j].NodeMemoryUsage
|
||||
})
|
||||
case "memory_allocatable":
|
||||
sort.Slice(r.Records, func(i, j int) bool {
|
||||
return r.Records[i].NodeMemoryAllocatable > r.Records[j].NodeMemoryAllocatable
|
||||
})
|
||||
}
|
||||
|
||||
// the default is descending
|
||||
if orderBy.Order == v3.DirectionAsc {
|
||||
// reverse the list
|
||||
for i, j := 0, len(r.Records)-1; i < j; i, j = i+1, j-1 {
|
||||
r.Records[i], r.Records[j] = r.Records[j], r.Records[i]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
type NodeCountByCondition struct {
|
||||
Ready int `json:"ready"`
|
||||
NotReady int `json:"notReady"`
|
||||
@ -183,6 +253,31 @@ type NamespaceListResponse struct {
|
||||
Total int `json:"total"`
|
||||
}
|
||||
|
||||
func (r *NamespaceListResponse) SortBy(orderBy *v3.OrderBy) {
|
||||
switch orderBy.ColumnName {
|
||||
case "cpu":
|
||||
sort.Slice(r.Records, func(i, j int) bool {
|
||||
return r.Records[i].CPUUsage > r.Records[j].CPUUsage
|
||||
})
|
||||
case "memory":
|
||||
sort.Slice(r.Records, func(i, j int) bool {
|
||||
return r.Records[i].MemoryUsage > r.Records[j].MemoryUsage
|
||||
})
|
||||
case "pod_phase":
|
||||
sort.Slice(r.Records, func(i, j int) bool {
|
||||
return r.Records[i].CountByPhase.Pending > r.Records[j].CountByPhase.Pending
|
||||
})
|
||||
}
|
||||
|
||||
// the default is descending
|
||||
if orderBy.Order == v3.DirectionAsc {
|
||||
// reverse the list
|
||||
for i, j := 0, len(r.Records)-1; i < j; i, j = i+1, j-1 {
|
||||
r.Records[i], r.Records[j] = r.Records[j], r.Records[i]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
type NamespaceListRecord struct {
|
||||
NamespaceName string `json:"namespaceName"`
|
||||
CPUUsage float64 `json:"cpuUsage"`
|
||||
@ -207,6 +302,35 @@ type ClusterListResponse struct {
|
||||
Total int `json:"total"`
|
||||
}
|
||||
|
||||
func (r *ClusterListResponse) SortBy(orderBy *v3.OrderBy) {
|
||||
switch orderBy.ColumnName {
|
||||
case "cpu":
|
||||
sort.Slice(r.Records, func(i, j int) bool {
|
||||
return r.Records[i].CPUUsage > r.Records[j].CPUUsage
|
||||
})
|
||||
case "cpu_allocatable":
|
||||
sort.Slice(r.Records, func(i, j int) bool {
|
||||
return r.Records[i].CPUAllocatable > r.Records[j].CPUAllocatable
|
||||
})
|
||||
case "memory":
|
||||
sort.Slice(r.Records, func(i, j int) bool {
|
||||
return r.Records[i].MemoryUsage > r.Records[j].MemoryUsage
|
||||
})
|
||||
case "memory_allocatable":
|
||||
sort.Slice(r.Records, func(i, j int) bool {
|
||||
return r.Records[i].MemoryAllocatable > r.Records[j].MemoryAllocatable
|
||||
})
|
||||
}
|
||||
|
||||
// the default is descending
|
||||
if orderBy.Order == v3.DirectionAsc {
|
||||
// reverse the list
|
||||
for i, j := 0, len(r.Records)-1; i < j; i, j = i+1, j-1 {
|
||||
r.Records[i], r.Records[j] = r.Records[j], r.Records[i]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
type ClusterListRecord struct {
|
||||
ClusterUID string `json:"clusterUID"`
|
||||
CPUUsage float64 `json:"cpuUsage"`
|
||||
@ -232,6 +356,55 @@ type DeploymentListResponse struct {
|
||||
Total int `json:"total"`
|
||||
}
|
||||
|
||||
func (r *DeploymentListResponse) SortBy(orderBy *v3.OrderBy) {
|
||||
switch orderBy.ColumnName {
|
||||
case "cpu":
|
||||
sort.Slice(r.Records, func(i, j int) bool {
|
||||
return r.Records[i].CPUUsage > r.Records[j].CPUUsage
|
||||
})
|
||||
case "cpu_request":
|
||||
sort.Slice(r.Records, func(i, j int) bool {
|
||||
return r.Records[i].CPURequest > r.Records[j].CPURequest
|
||||
})
|
||||
case "cpu_limit":
|
||||
sort.Slice(r.Records, func(i, j int) bool {
|
||||
return r.Records[i].CPULimit > r.Records[j].CPULimit
|
||||
})
|
||||
case "memory":
|
||||
sort.Slice(r.Records, func(i, j int) bool {
|
||||
return r.Records[i].MemoryUsage > r.Records[j].MemoryUsage
|
||||
})
|
||||
case "memory_request":
|
||||
sort.Slice(r.Records, func(i, j int) bool {
|
||||
return r.Records[i].MemoryRequest > r.Records[j].MemoryRequest
|
||||
})
|
||||
case "memory_limit":
|
||||
sort.Slice(r.Records, func(i, j int) bool {
|
||||
return r.Records[i].MemoryLimit > r.Records[j].MemoryLimit
|
||||
})
|
||||
case "desired_pods":
|
||||
sort.Slice(r.Records, func(i, j int) bool {
|
||||
return r.Records[i].DesiredPods > r.Records[j].DesiredPods
|
||||
})
|
||||
case "available_pods":
|
||||
sort.Slice(r.Records, func(i, j int) bool {
|
||||
return r.Records[i].AvailablePods > r.Records[j].AvailablePods
|
||||
})
|
||||
case "restarts":
|
||||
sort.Slice(r.Records, func(i, j int) bool {
|
||||
return r.Records[i].Restarts > r.Records[j].Restarts
|
||||
})
|
||||
}
|
||||
|
||||
// the default is descending
|
||||
if orderBy.Order == v3.DirectionAsc {
|
||||
// reverse the list
|
||||
for i, j := 0, len(r.Records)-1; i < j; i, j = i+1, j-1 {
|
||||
r.Records[i], r.Records[j] = r.Records[j], r.Records[i]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
type DeploymentListRecord struct {
|
||||
DeploymentName string `json:"deploymentName"`
|
||||
CPUUsage float64 `json:"cpuUsage"`
|
||||
@ -262,6 +435,55 @@ type DaemonSetListResponse struct {
|
||||
Total int `json:"total"`
|
||||
}
|
||||
|
||||
func (r *DaemonSetListResponse) SortBy(orderBy *v3.OrderBy) {
|
||||
switch orderBy.ColumnName {
|
||||
case "cpu":
|
||||
sort.Slice(r.Records, func(i, j int) bool {
|
||||
return r.Records[i].CPUUsage > r.Records[j].CPUUsage
|
||||
})
|
||||
case "cpu_request":
|
||||
sort.Slice(r.Records, func(i, j int) bool {
|
||||
return r.Records[i].CPURequest > r.Records[j].CPURequest
|
||||
})
|
||||
case "cpu_limit":
|
||||
sort.Slice(r.Records, func(i, j int) bool {
|
||||
return r.Records[i].CPULimit > r.Records[j].CPULimit
|
||||
})
|
||||
case "memory":
|
||||
sort.Slice(r.Records, func(i, j int) bool {
|
||||
return r.Records[i].MemoryUsage > r.Records[j].MemoryUsage
|
||||
})
|
||||
case "memory_request":
|
||||
sort.Slice(r.Records, func(i, j int) bool {
|
||||
return r.Records[i].MemoryRequest > r.Records[j].MemoryRequest
|
||||
})
|
||||
case "memory_limit":
|
||||
sort.Slice(r.Records, func(i, j int) bool {
|
||||
return r.Records[i].MemoryLimit > r.Records[j].MemoryLimit
|
||||
})
|
||||
case "restarts":
|
||||
sort.Slice(r.Records, func(i, j int) bool {
|
||||
return r.Records[i].Restarts > r.Records[j].Restarts
|
||||
})
|
||||
case "desired_nodes":
|
||||
sort.Slice(r.Records, func(i, j int) bool {
|
||||
return r.Records[i].DesiredNodes > r.Records[j].DesiredNodes
|
||||
})
|
||||
case "available_nodes":
|
||||
sort.Slice(r.Records, func(i, j int) bool {
|
||||
return r.Records[i].AvailableNodes > r.Records[j].AvailableNodes
|
||||
})
|
||||
}
|
||||
|
||||
// the default is descending
|
||||
if orderBy.Order == v3.DirectionAsc {
|
||||
// reverse the list
|
||||
for i, j := 0, len(r.Records)-1; i < j; i, j = i+1, j-1 {
|
||||
r.Records[i], r.Records[j] = r.Records[j], r.Records[i]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
type DaemonSetListRecord struct {
|
||||
DaemonSetName string `json:"daemonSetName"`
|
||||
CPUUsage float64 `json:"cpuUsage"`
|
||||
@ -292,6 +514,55 @@ type StatefulSetListResponse struct {
|
||||
Total int `json:"total"`
|
||||
}
|
||||
|
||||
func (r *StatefulSetListResponse) SortBy(orderBy *v3.OrderBy) {
|
||||
switch orderBy.ColumnName {
|
||||
case "cpu":
|
||||
sort.Slice(r.Records, func(i, j int) bool {
|
||||
return r.Records[i].CPUUsage > r.Records[j].CPUUsage
|
||||
})
|
||||
case "cpu_request":
|
||||
sort.Slice(r.Records, func(i, j int) bool {
|
||||
return r.Records[i].CPURequest > r.Records[j].CPURequest
|
||||
})
|
||||
case "cpu_limit":
|
||||
sort.Slice(r.Records, func(i, j int) bool {
|
||||
return r.Records[i].CPULimit > r.Records[j].CPULimit
|
||||
})
|
||||
case "memory":
|
||||
sort.Slice(r.Records, func(i, j int) bool {
|
||||
return r.Records[i].MemoryUsage > r.Records[j].MemoryUsage
|
||||
})
|
||||
case "memory_request":
|
||||
sort.Slice(r.Records, func(i, j int) bool {
|
||||
return r.Records[i].MemoryRequest > r.Records[j].MemoryRequest
|
||||
})
|
||||
case "memory_limit":
|
||||
sort.Slice(r.Records, func(i, j int) bool {
|
||||
return r.Records[i].MemoryLimit > r.Records[j].MemoryLimit
|
||||
})
|
||||
case "restarts":
|
||||
sort.Slice(r.Records, func(i, j int) bool {
|
||||
return r.Records[i].Restarts > r.Records[j].Restarts
|
||||
})
|
||||
case "desired_pods":
|
||||
sort.Slice(r.Records, func(i, j int) bool {
|
||||
return r.Records[i].DesiredPods > r.Records[j].DesiredPods
|
||||
})
|
||||
case "available_pods":
|
||||
sort.Slice(r.Records, func(i, j int) bool {
|
||||
return r.Records[i].AvailablePods > r.Records[j].AvailablePods
|
||||
})
|
||||
}
|
||||
|
||||
// the default is descending
|
||||
if orderBy.Order == v3.DirectionAsc {
|
||||
// reverse the list
|
||||
for i, j := 0, len(r.Records)-1; i < j; i, j = i+1, j-1 {
|
||||
r.Records[i], r.Records[j] = r.Records[j], r.Records[i]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
type StatefulSetListRecord struct {
|
||||
StatefulSetName string `json:"statefulSetName"`
|
||||
CPUUsage float64 `json:"cpuUsage"`
|
||||
@ -322,6 +593,63 @@ type JobListResponse struct {
|
||||
Total int `json:"total"`
|
||||
}
|
||||
|
||||
func (r *JobListResponse) SortBy(orderBy *v3.OrderBy) {
|
||||
switch orderBy.ColumnName {
|
||||
case "cpu":
|
||||
sort.Slice(r.Records, func(i, j int) bool {
|
||||
return r.Records[i].CPUUsage > r.Records[j].CPUUsage
|
||||
})
|
||||
case "cpu_request":
|
||||
sort.Slice(r.Records, func(i, j int) bool {
|
||||
return r.Records[i].CPURequest > r.Records[j].CPURequest
|
||||
})
|
||||
case "cpu_limit":
|
||||
sort.Slice(r.Records, func(i, j int) bool {
|
||||
return r.Records[i].CPULimit > r.Records[j].CPULimit
|
||||
})
|
||||
case "memory":
|
||||
sort.Slice(r.Records, func(i, j int) bool {
|
||||
return r.Records[i].MemoryUsage > r.Records[j].MemoryUsage
|
||||
})
|
||||
case "memory_request":
|
||||
sort.Slice(r.Records, func(i, j int) bool {
|
||||
return r.Records[i].MemoryRequest > r.Records[j].MemoryRequest
|
||||
})
|
||||
case "memory_limit":
|
||||
sort.Slice(r.Records, func(i, j int) bool {
|
||||
return r.Records[i].MemoryLimit > r.Records[j].MemoryLimit
|
||||
})
|
||||
case "restarts":
|
||||
sort.Slice(r.Records, func(i, j int) bool {
|
||||
return r.Records[i].Restarts > r.Records[j].Restarts
|
||||
})
|
||||
case "desired_pods":
|
||||
sort.Slice(r.Records, func(i, j int) bool {
|
||||
return r.Records[i].DesiredSuccessfulPods > r.Records[j].DesiredSuccessfulPods
|
||||
})
|
||||
case "active_pods":
|
||||
sort.Slice(r.Records, func(i, j int) bool {
|
||||
return r.Records[i].ActivePods > r.Records[j].ActivePods
|
||||
})
|
||||
case "failed_pods":
|
||||
sort.Slice(r.Records, func(i, j int) bool {
|
||||
return r.Records[i].FailedPods > r.Records[j].FailedPods
|
||||
})
|
||||
case "successful_pods":
|
||||
sort.Slice(r.Records, func(i, j int) bool {
|
||||
return r.Records[i].SuccessfulPods > r.Records[j].SuccessfulPods
|
||||
})
|
||||
}
|
||||
|
||||
// the default is descending
|
||||
if orderBy.Order == v3.DirectionAsc {
|
||||
// reverse the list
|
||||
for i, j := 0, len(r.Records)-1; i < j; i, j = i+1, j-1 {
|
||||
r.Records[i], r.Records[j] = r.Records[j], r.Records[i]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
type JobListRecord struct {
|
||||
JobName string `json:"jobName"`
|
||||
CPUUsage float64 `json:"cpuUsage"`
|
||||
@ -354,6 +682,43 @@ type VolumeListResponse struct {
|
||||
Total int `json:"total"`
|
||||
}
|
||||
|
||||
func (r *VolumeListResponse) SortBy(orderBy *v3.OrderBy) {
|
||||
switch orderBy.ColumnName {
|
||||
case "available":
|
||||
sort.Slice(r.Records, func(i, j int) bool {
|
||||
return r.Records[i].VolumeAvailable > r.Records[j].VolumeAvailable
|
||||
})
|
||||
case "capacity":
|
||||
sort.Slice(r.Records, func(i, j int) bool {
|
||||
return r.Records[i].VolumeCapacity > r.Records[j].VolumeCapacity
|
||||
})
|
||||
case "usage":
|
||||
sort.Slice(r.Records, func(i, j int) bool {
|
||||
return r.Records[i].VolumeUsage > r.Records[j].VolumeUsage
|
||||
})
|
||||
case "inodes":
|
||||
sort.Slice(r.Records, func(i, j int) bool {
|
||||
return r.Records[i].VolumeInodes > r.Records[j].VolumeInodes
|
||||
})
|
||||
case "inodes_free":
|
||||
sort.Slice(r.Records, func(i, j int) bool {
|
||||
return r.Records[i].VolumeInodesFree > r.Records[j].VolumeInodesFree
|
||||
})
|
||||
case "inodes_used":
|
||||
sort.Slice(r.Records, func(i, j int) bool {
|
||||
return r.Records[i].VolumeInodesUsed > r.Records[j].VolumeInodesUsed
|
||||
})
|
||||
}
|
||||
|
||||
// the default is descending
|
||||
if orderBy.Order == v3.DirectionAsc {
|
||||
// reverse the list
|
||||
for i, j := 0, len(r.Records)-1; i < j; i, j = i+1, j-1 {
|
||||
r.Records[i], r.Records[j] = r.Records[j], r.Records[i]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
type VolumeListRecord struct {
|
||||
PersistentVolumeClaimName string `json:"persistentVolumeClaimName"`
|
||||
VolumeAvailable float64 `json:"volumeAvailable"`
|
||||
|
Loading…
x
Reference in New Issue
Block a user