Skip to content

SigNoz is an open-source, OpenTelemetry-native observability platform for your team and their AI agents. Get logs, metrics, and traces in one tool with features like APM, distributed tracing, log management, infra monitoring, etc. Combined with SigNoz MCP and a native AI teammate (in SigNoz Cloud) it helps you build more resilient apps.

chore: enable sorting for hosts list (#6502)

Srikanth Chekuried6abe5a95be
diff --git a/ee/query-service/app/server.go b/ee/query-service/app/server.go
index b58a90b9c4..a970a34b0e 100644
--- a/ee/query-service/app/server.go
+++ b/ee/query-service/app/server.go
@@ -317,10 +317,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)
@@ -360,10 +360,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)
diff --git a/frontend/src/container/InfraMonitoringHosts/utils.tsx b/frontend/src/container/InfraMonitoringHosts/utils.tsx
index 13a8b6fd5a..e25b4d4185 100644
--- a/frontend/src/container/InfraMonitoringHosts/utils.tsx
+++ b/frontend/src/container/InfraMonitoringHosts/utils.tsx
@@ -55,6 +55,7 @@ export const getHostsListColumns = (): ColumnType<HostRowData>[] => [
dataIndex: 'cpu',
key: 'cpu',
width: 100,
+ sorter: true,
align: 'right',
},
{
@@ -62,6 +63,7 @@ export const getHostsListColumns = (): ColumnType<HostRowData>[] => [
dataIndex: 'memory',
key: 'memory',
width: 100,
+ sorter: true,
align: 'right',
},
{
@@ -69,6 +71,7 @@ export const getHostsListColumns = (): ColumnType<HostRowData>[] => [
dataIndex: 'wait',
key: 'wait',
width: 100,
+ sorter: true,
align: 'right',
},
{
@@ -76,6 +79,7 @@ export const getHostsListColumns = (): ColumnType<HostRowData>[] => [
dataIndex: 'load15',
key: 'load15',
width: 100,
+ sorter: true,
align: 'right',
},
];
diff --git a/pkg/query-service/app/inframetrics/hosts.go b/pkg/query-service/app/inframetrics/hosts.go
index 8aae039d3e..8153c382c9 100644
--- a/pkg/query-service/app/inframetrics/hosts.go
+++ b/pkg/query-service/app/inframetrics/hosts.go
@@ -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
}
diff --git a/pkg/query-service/app/server.go b/pkg/query-service/app/server.go
index 76637ad328..20d183876c 100644
--- a/pkg/query-service/app/server.go
+++ b/pkg/query-service/app/server.go
@@ -286,10 +286,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) {
@@ -387,10 +387,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())
kvs := map[string]string{
"path": path,
diff --git a/pkg/query-service/model/infra.go b/pkg/query-service/model/infra.go
index 0c23a0642b..3c7dbc39e0 100644
--- a/pkg/query-service/model/infra.go
+++ b/pkg/query-service/model/infra.go
@@ -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
@@ -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
+ })
+ }
+ // 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