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

chore: enable sorting for hosts list #6502

Merged
merged 2 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions ee/query-service/app/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,10 +313,10 @@ func (s *Server) createPrivateServer(apiHandler *api.APIHandler) (*http.Server,

r := baseapp.NewRouter()

r.Use(baseapp.LogCommentEnricher)
r.Use(setTimeoutMiddleware)
r.Use(s.analyticsMiddleware)
r.Use(loggingMiddlewarePrivate)
r.Use(baseapp.LogCommentEnricher)

apiHandler.RegisterPrivateRoutes(r)

Expand Down Expand Up @@ -356,10 +356,10 @@ func (s *Server) createPublicServer(apiHandler *api.APIHandler) (*http.Server, e
}
am := baseapp.NewAuthMiddleware(getUserFromRequest)

r.Use(baseapp.LogCommentEnricher)
r.Use(setTimeoutMiddleware)
r.Use(s.analyticsMiddleware)
r.Use(loggingMiddleware)
r.Use(baseapp.LogCommentEnricher)

apiHandler.RegisterRoutes(r, am)
apiHandler.RegisterLogsRoutes(r, am)
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/container/InfraMonitoringHosts/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,27 +55,31 @@ export const getHostsListColumns = (): ColumnType<HostRowData>[] => [
dataIndex: 'cpu',
key: 'cpu',
width: 100,
sorter: true,
align: 'right',
},
{
title: <div className="column-header-right">Memory Usage</div>,
dataIndex: 'memory',
key: 'memory',
width: 100,
sorter: true,
align: 'right',
},
{
title: <div className="column-header-right">IOWait</div>,
dataIndex: 'wait',
key: 'wait',
width: 100,
sorter: true,
align: 'right',
},
{
title: <div className="column-header-right">Load Avg</div>,
dataIndex: 'load15',
key: 'load15',
width: 100,
sorter: true,
align: 'right',
},
];
Expand Down
1 change: 1 addition & 0 deletions pkg/query-service/app/inframetrics/hosts.go
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,7 @@ func (h *HostsRepo) GetHostList(ctx context.Context, req model.HostListRequest)
}
resp.Total = len(allHostGroups)
resp.Records = records
resp.SortBy(req.OrderBy)

return resp, nil
}
7 changes: 2 additions & 5 deletions pkg/query-service/app/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,10 +283,10 @@ func (s *Server) createPublicServer(api *APIHandler) (*http.Server, error) {

r := NewRouter()

r.Use(LogCommentEnricher)
r.Use(setTimeoutMiddleware)
r.Use(s.analyticsMiddleware)
r.Use(loggingMiddleware)
r.Use(LogCommentEnricher)

// add auth middleware
getUserFromRequest := func(r *http.Request) (*model.UserPayload, error) {
Expand Down Expand Up @@ -384,10 +384,7 @@ func LogCommentEnricher(next http.Handler) http.Handler {
client = "api"
}

email, err := auth.GetEmailFromJwt(r.Context())
if err != nil {
zap.S().Errorf("error while getting email from jwt: %v", err)
}
email, _ := auth.GetEmailFromJwt(r.Context())
srikanthccv marked this conversation as resolved.
Show resolved Hide resolved

kvs := map[string]string{
"path": path,
Expand Down
34 changes: 33 additions & 1 deletion pkg/query-service/model/infra.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package model

import v3 "go.signoz.io/signoz/pkg/query-service/model/v3"
import (
"sort"

v3 "go.signoz.io/signoz/pkg/query-service/model/v3"
)

type (
ResponseType string
Expand Down Expand Up @@ -38,6 +42,34 @@ type HostListResponse struct {
Total int `json:"total"`
}

func (r *HostListResponse) SortBy(orderBy *v3.OrderBy) {
switch orderBy.ColumnName {
case "cpu":
sort.Slice(r.Records, func(i, j int) bool {
return r.Records[i].CPU > r.Records[j].CPU
})
case "memory":
sort.Slice(r.Records, func(i, j int) bool {
return r.Records[i].Memory > r.Records[j].Memory
})
case "load15":
sort.Slice(r.Records, func(i, j int) bool {
return r.Records[i].Load15 > r.Records[j].Load15
})
case "wait":
sort.Slice(r.Records, func(i, j int) bool {
return r.Records[i].Wait > r.Records[j].Wait
})
}
srikanthccv marked this conversation as resolved.
Show resolved Hide resolved
// 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 ProcessListRequest struct {
Start int64 `json:"start"` // epoch time in ms
End int64 `json:"end"` // epoch time in ms
Expand Down
Loading