Skip to content
This repository was archived by the owner on Mar 10, 2026. It is now read-only.

Commit 87d879c

Browse files
authored
Merge pull request #11 from c9274326/feature/web-ui-pod-pid-mapping
Feature/web UI pod pid mapping
2 parents 00dea73 + 777fe1d commit 87d879c

8 files changed

Lines changed: 3337 additions & 845 deletions

File tree

decisionmaker/rest/handler.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,8 @@ func (h *Handler) SetupRoutes(engine *echo.Echo) error {
165165
apiV1.DELETE("/intents", h.echoHandler(h.DeleteIntent), echo.WrapMiddleware(authMiddleware))
166166
apiV1.GET("/scheduling/strategies", h.echoHandler(h.ListIntents), echo.WrapMiddleware(authMiddleware))
167167
apiV1.POST("/metrics", h.echoHandler(h.UpdateMetrics), echo.WrapMiddleware(authMiddleware))
168+
// pod routes
169+
apiV1.GET("/pods/pids", h.echoHandler(h.GetPodsPIDs), echo.WrapMiddleware(authMiddleware))
168170
// token routes
169171
apiV1.POST("/auth/token", h.echoHandler(h.GenTokenHandler))
170172
}

decisionmaker/rest/pod_handler.go

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
package rest
2+
3+
import (
4+
"net/http"
5+
"os"
6+
"time"
7+
8+
"github.com/Gthulhu/api/decisionmaker/domain"
9+
)
10+
11+
// PodProcess represents a process information within a pod (for API response)
12+
type PodProcess struct {
13+
PID int `json:"pid"`
14+
Command string `json:"command"`
15+
PPID int `json:"ppid,omitempty"`
16+
ContainerID string `json:"container_id,omitempty"`
17+
}
18+
19+
// PodInfo represents pod information with associated processes (for API response)
20+
type PodInfo struct {
21+
PodUID string `json:"pod_uid"`
22+
PodID string `json:"pod_id,omitempty"`
23+
Processes []PodProcess `json:"processes"`
24+
}
25+
26+
// GetPodsPIDsResponse is the response structure for the GET /api/v1/pods/pids endpoint
27+
type GetPodsPIDsResponse struct {
28+
Pods []PodInfo `json:"pods"`
29+
Timestamp string `json:"timestamp"`
30+
NodeName string `json:"node_name"`
31+
NodeID string `json:"node_id,omitempty"`
32+
}
33+
34+
// GetPodsPIDs godoc
35+
// @Summary Get Pod to PID mappings
36+
// @Description Returns all pods running on this node with their associated process IDs
37+
// @Tags Pods
38+
// @Produce json
39+
// @Security BearerAuth
40+
// @Success 200 {object} SuccessResponse[GetPodsPIDsResponse]
41+
// @Failure 401 {object} ErrorResponse
42+
// @Failure 500 {object} ErrorResponse
43+
// @Router /api/v1/pods/pids [get]
44+
func (h *Handler) GetPodsPIDs(w http.ResponseWriter, r *http.Request) {
45+
ctx := r.Context()
46+
47+
// Get all pod information from /proc filesystem
48+
podInfoMap, err := h.Service.GetAllPodInfos(ctx)
49+
if err != nil {
50+
h.ErrorResponse(ctx, w, http.StatusInternalServerError, "Failed to retrieve pod information", err)
51+
return
52+
}
53+
54+
// Convert map to slice for response
55+
pods := make([]PodInfo, 0, len(podInfoMap))
56+
for _, podInfo := range podInfoMap {
57+
processes := make([]PodProcess, 0, len(podInfo.Processes))
58+
for _, proc := range podInfo.Processes {
59+
processes = append(processes, PodProcess{
60+
PID: proc.PID,
61+
Command: proc.Command,
62+
PPID: proc.PPID,
63+
ContainerID: proc.ContainerID,
64+
})
65+
}
66+
pods = append(pods, PodInfo{
67+
PodUID: podInfo.PodUID,
68+
PodID: podInfo.PodID,
69+
Processes: processes,
70+
})
71+
}
72+
73+
// Get node name from hostname or environment variable
74+
nodeName, _ := os.Hostname()
75+
if envNodeName := os.Getenv("NODE_NAME"); envNodeName != "" {
76+
nodeName = envNodeName
77+
}
78+
79+
response := GetPodsPIDsResponse{
80+
Pods: pods,
81+
Timestamp: time.Now().UTC().Format(time.RFC3339),
82+
NodeName: nodeName,
83+
}
84+
85+
h.JSONResponse(ctx, w, http.StatusOK, NewSuccessResponse(&response))
86+
}
87+
88+
// convertDomainPodProcess converts domain.PodProcess to rest.PodProcess
89+
func convertDomainPodProcess(proc domain.PodProcess) PodProcess {
90+
return PodProcess{
91+
PID: proc.PID,
92+
Command: proc.Command,
93+
PPID: proc.PPID,
94+
ContainerID: proc.ContainerID,
95+
}
96+
}

0 commit comments

Comments
 (0)