upd graph
ci-agent / build (push) Has started running

This commit is contained in:
d3m0k1d
2026-04-05 08:34:04 +03:00
parent 413e31c711
commit e9fdaf8711
5 changed files with 55 additions and 25 deletions
+1 -1
View File
@@ -226,7 +226,7 @@ func main() {
graphView := graphGroup.Group("") graphView := graphGroup.Group("")
graphView.Use(handlers.RequireView()) graphView.Use(handlers.RequireView())
{ {
graphView.GET("", graphHandlers.GetYAML) graphView.GET("", graphHandlers.GetGraph)
graphView.GET("/order", graphHandlers.StartupOrder) graphView.GET("/order", graphHandlers.StartupOrder)
graphView.GET("/cycle", graphHandlers.CycleCheck) graphView.GET("/cycle", graphHandlers.CycleCheck)
graphView.GET("/failure", graphHandlers.GetFailureRootCause) graphView.GET("/failure", graphHandlers.GetFailureRootCause)
+6 -5
View File
@@ -1001,19 +1001,20 @@ const docTemplate = `{
"Bearer": [] "Bearer": []
} }
], ],
"description": "Returns the service dependency graph as raw YAML text", "description": "Returns the service dependency graph as JSON",
"produces": [ "produces": [
"text/plain" "application/json"
], ],
"tags": [ "tags": [
"graph" "graph"
], ],
"summary": "Get dependency graph YAML", "summary": "Get dependency graph",
"responses": { "responses": {
"200": { "200": {
"description": "YAML content", "description": "Dependency graph",
"schema": { "schema": {
"type": "string" "type": "object",
"additionalProperties": true
} }
} }
} }
+6 -5
View File
@@ -990,19 +990,20 @@
"Bearer": [] "Bearer": []
} }
], ],
"description": "Returns the service dependency graph as raw YAML text", "description": "Returns the service dependency graph as JSON",
"produces": [ "produces": [
"text/plain" "application/json"
], ],
"tags": [ "tags": [
"graph" "graph"
], ],
"summary": "Get dependency graph YAML", "summary": "Get dependency graph",
"responses": { "responses": {
"200": { "200": {
"description": "YAML content", "description": "Dependency graph",
"schema": { "schema": {
"type": "string" "type": "object",
"additionalProperties": true
} }
} }
} }
+6 -5
View File
@@ -1181,17 +1181,18 @@ paths:
- auth - auth
/graph: /graph:
get: get:
description: Returns the service dependency graph as raw YAML text description: Returns the service dependency graph as JSON
produces: produces:
- text/plain - application/json
responses: responses:
"200": "200":
description: YAML content description: Dependency graph
schema: schema:
type: string additionalProperties: true
type: object
security: security:
- Bearer: [] - Bearer: []
summary: Get dependency graph YAML summary: Get dependency graph
tags: tags:
- graph - graph
put: put:
+36 -9
View File
@@ -53,25 +53,52 @@ func (h *GraphHandlers) reload() error {
return nil return nil
} }
// GetGraph returns the current parsed graph. // LoadedGraph returns the current parsed graph.
func (h *GraphHandlers) GetGraph() *graph.Graph { func (h *GraphHandlers) LoadedGraph() *graph.Graph {
h.mu.RLock() h.mu.RLock()
defer h.mu.RUnlock() defer h.mu.RUnlock()
return h.loaded return h.loaded
} }
// GetYAML returns the raw YAML content. // GetGraph returns the current dependency graph as JSON.
// @Summary Get dependency graph YAML // @Summary Get dependency graph
// @Description Returns the service dependency graph as raw YAML text // @Description Returns the service dependency graph as JSON
// @Tags graph // @Tags graph
// @Produce plain // @Produce json
// @Success 200 {string} string "YAML content" // @Success 200 {object} map[string]interface{} "Dependency graph"
// @Security Bearer // @Security Bearer
// @Router /graph [get] // @Router /graph [get]
func (h *GraphHandlers) GetYAML(c *gin.Context) { func (h *GraphHandlers) GetGraph(c *gin.Context) {
h.mu.RLock() h.mu.RLock()
defer h.mu.RUnlock() defer h.mu.RUnlock()
c.Data(http.StatusOK, "text/yaml", h.yamlData)
g := h.loaded
if g == nil {
c.JSON(http.StatusOK, gin.H{"nodes": map[string]interface{}{}})
return
}
nodes := make(map[string]interface{})
for _, node := range g.Nodes() {
services := make(map[string]interface{})
for _, svc := range node.Services {
deps := make([]map[string]interface{}, 0)
for _, dep := range svc.Dependencies {
deps = append(deps, map[string]interface{}{
"target": dep.Target,
"condition": dep.Condition,
})
}
services[svc.Name] = map[string]interface{}{
"dependencies": deps,
}
}
nodes[node.ID] = map[string]interface{}{
"services": services,
}
}
c.JSON(http.StatusOK, gin.H{"nodes": nodes})
} }
// UpdateYAML updates the graph from new YAML text. // UpdateYAML updates the graph from new YAML text.