Skip to content

Commit 9adece0

Browse files
feat(service): add service detail and interfaces endpoints with request/response models
1 parent c9e76b5 commit 9adece0

7 files changed

Lines changed: 285 additions & 125 deletions

File tree

pkg/console/handler/service.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,3 +248,41 @@ func GetServiceGraph(ctx consolectx.Context) gin.HandlerFunc {
248248
c.JSON(http.StatusOK, model.NewSuccessResp(resp))
249249
}
250250
}
251+
252+
// GetServiceDetail returns service detail information
253+
func GetServiceDetail(ctx consolectx.Context) gin.HandlerFunc {
254+
return func(c *gin.Context) {
255+
req := &model.ServiceDetailReq{}
256+
if err := c.ShouldBindQuery(req); err != nil {
257+
c.JSON(http.StatusBadRequest, model.NewErrorResp(err.Error()))
258+
return
259+
}
260+
261+
resp, err := service.GetServiceDetail(ctx, req)
262+
if err != nil {
263+
util.HandleServiceError(c, err)
264+
return
265+
}
266+
267+
c.JSON(http.StatusOK, model.NewSuccessResp(resp))
268+
}
269+
}
270+
271+
// GetServiceInterfaces returns service interfaces information
272+
func GetServiceInterfaces(ctx consolectx.Context) gin.HandlerFunc {
273+
return func(c *gin.Context) {
274+
req := &model.ServiceInterfacesReq{}
275+
if err := c.ShouldBindQuery(req); err != nil {
276+
c.JSON(http.StatusBadRequest, model.NewErrorResp(err.Error()))
277+
return
278+
}
279+
280+
resp, err := service.GetServiceInterfaces(ctx, req)
281+
if err != nil {
282+
util.HandleServiceError(c, err)
283+
return
284+
}
285+
286+
c.JSON(http.StatusOK, model.NewSuccessResp(resp))
287+
}
288+
}

pkg/console/model/graph.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,17 @@ package model
1919

2020
import (
2121
meshresource "github.com/apache/dubbo-admin/pkg/core/resource/apis/mesh/v1alpha1"
22+
23+
"github.com/apache/dubbo-admin/pkg/common/constants"
2224
)
2325

2426
// GraphNode represents a node in the graph for AntV G6
2527
type GraphNode struct {
2628
ID string `json:"id"`
2729
Label string `json:"label"`
28-
Data interface{} `json:"data,omitempty"` // Additional data for the node
30+
Type string `json:"type"` // "application" or "service"
31+
Rule string `json:"rule"` // "provider", "consumer", or ""
32+
Data interface{} `json:"data,omitempty"`
2933
}
3034

3135
// GraphEdge represents an edge in the graph for AntV G6
@@ -57,6 +61,13 @@ type CrossLinkedListGraph struct {
5761

5862
// ServiceGraphReq represents the request parameters for fetching the service graph
5963
type ServiceGraphReq struct {
60-
ServiceName string `json:"serviceName" form:"serviceName"`
6164
Mesh string `json:"mesh" form:"mesh" binding:"required"`
65+
ServiceName string `json:"serviceName" form:"serviceName" binding:"required"`
66+
Version string `json:"version" form:"version"`
67+
Group string `json:"group" form:"group"`
68+
}
69+
70+
// ServiceKey returns the unique service identifier
71+
func (s *ServiceGraphReq) ServiceKey() string {
72+
return s.ServiceName + constants.ColonSeparator + s.Version + constants.ColonSeparator + s.Group
6273
}

pkg/console/model/service.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,3 +120,36 @@ func (s *BaseServiceReq) Query(c *gin.Context) error {
120120
func (s *BaseServiceReq) ServiceKey() string {
121121
return s.ServiceName + constants.ColonSeparator + s.Version + constants.ColonSeparator + s.Group
122122
}
123+
124+
type ServiceDetailReq struct {
125+
ServiceName string `form:"serviceName" json:"serviceName" binding:"required"`
126+
Version string `form:"version" json:"version"`
127+
Group string `form:"group" json:"group"`
128+
Mesh string `form:"mesh" json:"mesh" binding:"required"`
129+
}
130+
131+
type VersionGroup struct {
132+
Version string `json:"version"`
133+
Group string `json:"group"`
134+
}
135+
136+
type ServiceDetailResp struct {
137+
VersionGroups []*VersionGroup `json:"versionGroups"`
138+
AvgRT string `json:"avgRT"`
139+
AvgQPS string `json:"avgQPS"`
140+
RequestTotal string `json:"requestTotal"`
141+
}
142+
143+
type ServiceInterfacesReq struct {
144+
ServiceName string `form:"serviceName" json:"serviceName" binding:"required"`
145+
Mesh string `form:"mesh" json:"mesh" binding:"required"`
146+
}
147+
148+
type ServiceInterface struct {
149+
InterfaceName string `json:"interfaceName"`
150+
MethodCount int `json:"methodCount"`
151+
}
152+
153+
type ServiceInterfacesResp struct {
154+
Interfaces []*ServiceInterface `json:"interfaces"`
155+
}

pkg/console/router/router.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ func InitRouter(r *gin.Engine, ctx consolectx.Context) {
100100
service.GET("/distribution", handler.GetServiceTabDistribution(ctx))
101101
service.GET("/search", handler.SearchServices(ctx))
102102
service.GET("/graph", handler.GetServiceGraph(ctx))
103-
//service.GET("/detail", handler.GetServiceDetail(ctx))
104-
//service.GET("/interfaces", handler.GetServiceInterfaces(ctx))
103+
service.GET("/detail", handler.GetServiceDetail(ctx))
104+
service.GET("/interfaces", handler.GetServiceInterfaces(ctx))
105105
}
106106

107107
{

0 commit comments

Comments
 (0)