Merge branch 'feature/liujian-1.8' into 'main'

update service overview

See merge request apipark/APIPark!343
This commit is contained in:
刘健
2025-04-29 10:20:17 +08:00
8 changed files with 191 additions and 29 deletions
+97 -19
View File
@@ -70,24 +70,54 @@ var (
)
type imlServiceController struct {
module service.IServiceModule `autowired:""`
docModule service.IServiceDocModule `autowired:""`
subscribeModule subscribe.ISubscribeModule `autowired:""`
aiAPIModule ai_api.IAPIModule `autowired:""`
routerModule router.IRouterModule `autowired:""`
apiDocModule api_doc.IAPIDocModule `autowired:""`
providerModule ai.IProviderModule `autowired:""`
aiLocalModel ai_local.ILocalModelModule `autowired:""`
appModule service.IAppModule `autowired:""`
upstreamModule upstream.IUpstreamModule `autowired:""`
settingModule system.ISettingModule `autowired:""`
teamModule team.ITeamModule `autowired:""`
catalogueModule catalogue.ICatalogueModule `autowired:""`
monitorModule monitor.IMonitorStatisticModule `autowired:""`
transaction store.ITransaction `autowired:""`
module service.IServiceModule `autowired:""`
docModule service.IServiceDocModule `autowired:""`
subscribeModule subscribe.ISubscribeModule `autowired:""`
aiAPIModule ai_api.IAPIModule `autowired:""`
routerModule router.IRouterModule `autowired:""`
apiDocModule api_doc.IAPIDocModule `autowired:""`
providerModule ai.IProviderModule `autowired:""`
aiLocalModel ai_local.ILocalModelModule `autowired:""`
appModule service.IAppModule `autowired:""`
upstreamModule upstream.IUpstreamModule `autowired:""`
settingModule system.ISettingModule `autowired:""`
teamModule team.ITeamModule `autowired:""`
catalogueModule catalogue.ICatalogueModule `autowired:""`
monitorModule monitor.IMonitorStatisticModule `autowired:""`
monitorConfigModule monitor.IMonitorConfigModule `autowired:""`
transaction store.ITransaction `autowired:""`
}
func (i *imlServiceController) AIChartOverview(ctx *gin.Context, serviceId string, start string, end string) (*monitor_dto.ChartAIOverview, error) {
func (i *imlServiceController) ServiceOverview(ctx *gin.Context, serviceId string) (*service_dto.Overview, error) {
o, err := i.module.ServiceOverview(ctx, serviceId)
if err != nil {
return nil, err
}
cfg, err := i.monitorConfigModule.GetMonitorConfig(ctx)
if err != nil {
return nil, err
}
if len(cfg.Config) < 1 {
return o, nil
}
statistics, err := i.monitorModule.ProviderStatistics(ctx, &monitor_dto.StatisticInput{
Services: []string{serviceId},
CommonInput: &monitor_dto.CommonInput{
Start: time.Now().Add(-24 * 30 * time.Hour).Unix(),
End: time.Now().Unix(),
},
})
if err != nil {
return nil, err
}
if len(statistics) < 1 {
return o, nil
}
o.InvokeNum = statistics[0].RequestTotal
return o, nil
}
func (i *imlServiceController) AIChartOverview(ctx *gin.Context, serviceId string, start string, end string) (*monitor_dto.ServiceChartAIOverview, error) {
s, e, err := formatTime(start, end)
if err != nil {
return nil, err
@@ -95,10 +125,35 @@ func (i *imlServiceController) AIChartOverview(ctx *gin.Context, serviceId strin
if serviceId == "" {
return nil, fmt.Errorf("service is required")
}
return i.monitorModule.AIChartOverview(ctx, serviceId, s, e)
so, err := i.module.ServiceOverview(ctx, serviceId)
if err != nil {
return nil, err
}
result := &monitor_dto.ServiceChartAIOverview{
EnableMCP: so.EnableMCP,
SubscriberNum: so.SubscriberNum,
APINum: so.APINum,
ServiceKind: so.ServiceKind,
}
cfg, err := i.monitorConfigModule.GetMonitorConfig(ctx)
if err != nil {
return nil, err
}
if len(cfg.Config) < 1 {
return result, nil
}
o, err := i.monitorModule.AIChartOverview(ctx, serviceId, s, e)
if err != nil {
return nil, err
}
result.AvailableMonitor = true
result.ChartAIOverview = o
return result, nil
}
func (i *imlServiceController) RestChartOverview(ctx *gin.Context, serviceId string, start string, end string) (*monitor_dto.ChartRestOverview, error) {
func (i *imlServiceController) RestChartOverview(ctx *gin.Context, serviceId string, start string, end string) (*monitor_dto.ServiceChartRestOverview, error) {
s, e, err := formatTime(start, end)
if err != nil {
return nil, err
@@ -106,7 +161,30 @@ func (i *imlServiceController) RestChartOverview(ctx *gin.Context, serviceId str
if serviceId == "" {
return nil, fmt.Errorf("service is required")
}
return i.monitorModule.RestChartOverview(ctx, serviceId, s, e)
so, err := i.module.ServiceOverview(ctx, serviceId)
if err != nil {
return nil, err
}
result := &monitor_dto.ServiceChartRestOverview{
EnableMCP: so.EnableMCP,
SubscriberNum: so.SubscriberNum,
APINum: so.APINum,
ServiceKind: so.ServiceKind,
}
cfg, err := i.monitorConfigModule.GetMonitorConfig(ctx)
if err != nil {
return nil, err
}
if len(cfg.Config) < 1 {
return result, nil
}
o, err := i.monitorModule.RestChartOverview(ctx, serviceId, s, e)
if err != nil {
return nil, err
}
result.AvailableMonitor = true
result.ChartRestOverview = o
return result, nil
}
func formatTime(start string, end string) (int64, int64, error) {
+4 -2
View File
@@ -37,8 +37,10 @@ type IServiceController interface {
Top10(ctx *gin.Context, serviceId string, start string, end string) ([]*monitor_dto.TopN, []*monitor_dto.TopN, error)
AIChartOverview(ctx *gin.Context, serviceId string, start string, end string) (*monitor_dto.ChartAIOverview, error)
RestChartOverview(ctx *gin.Context, serviceId string, start string, end string) (*monitor_dto.ChartRestOverview, error)
AIChartOverview(ctx *gin.Context, serviceId string, start string, end string) (*monitor_dto.ServiceChartAIOverview, error)
RestChartOverview(ctx *gin.Context, serviceId string, start string, end string) (*monitor_dto.ServiceChartRestOverview, error)
ServiceOverview(ctx *gin.Context, serviceId string) (*service_dto.Overview, error)
}
type IAppController interface {
+10 -3
View File
@@ -442,9 +442,16 @@ func (e *executor) aggregateSummary(ctx context.Context, start time.Time, end ti
result := make(map[string]*monitor.Aggregate)
for _, field := range fields {
a := new(monitor.Aggregate)
a.Avg = int64(avgRes[field+"_avg"].(float64))
a.Min = minRes[field+"_min"].(int64)
a.Max = maxRes[field+"_max"].(int64)
if v, ok := avgRes[field+"_avg"]; ok {
a.Avg = int64(v.(float64))
}
if v, ok := maxRes[field+"_max"]; ok {
a.Min = v.(int64)
}
if v, ok := minRes[field+"_min"]; ok {
a.Min = v.(int64)
}
result[field] = a
}
+18
View File
@@ -186,6 +186,24 @@ type ChartRestOverview struct {
Date []string `json:"date"`
}
type ServiceChartRestOverview struct {
EnableMCP bool `json:"enable_mcp"`
SubscriberNum int64 `json:"subscriber_num"`
APINum int64 `json:"api_num"`
ServiceKind string `json:"service_kind"`
AvailableMonitor bool `json:"available_monitor"`
*ChartRestOverview
}
type ServiceChartAIOverview struct {
EnableMCP bool `json:"enable_mcp"`
SubscriberNum int64 `json:"subscriber_num"`
APINum int64 `json:"api_num"`
ServiceKind string `json:"service_kind"`
AvailableMonitor bool `json:"available_monitor"`
*ChartAIOverview
}
type TopN struct {
Id string `json:"id"`
Name string `json:"name"`
+15
View File
@@ -221,3 +221,18 @@ type ExportApp struct {
Description string `json:"description"`
Team string `json:"team"`
}
type Overview struct {
Id string `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
EnableMCP bool `json:"enable_mcp"`
ServiceKind string `json:"service_kind"`
SubscriberNum int64 `json:"subscriber_num"`
InvokeNum int64 `json:"invoke_num"`
Logo string `json:"logo"`
AvailableMonitor bool `json:"available_monitor"`
IsReleased bool `json:"is_released"`
Catalogue auto.Label `json:"catalogue" aolabel:"catalogue"`
APINum int64 `json:"api_num"`
}
+44 -5
View File
@@ -79,14 +79,53 @@ type imlServiceModule struct {
tagService tag.ITagService `autowired:""`
localModelService ai_local.ILocalModelService `autowired:""`
serviceTagService service_tag.ITagService `autowired:""`
apiService api.IAPIService `autowired:""`
apiDocService api_doc.IAPIDocService `autowired:""`
clusterService cluster.IClusterService `autowired:""`
transaction store.ITransaction `autowired:""`
serviceTagService service_tag.ITagService `autowired:""`
apiService api.IAPIService `autowired:""`
apiDocService api_doc.IAPIDocService `autowired:""`
clusterService cluster.IClusterService `autowired:""`
subscribeServer subscribe.ISubscribeService `autowired:""`
releaseService release.IReleaseService `autowired:""`
serviceModelMappingService service_model_mapping.IServiceModelMappingService `autowired:""`
transaction store.ITransaction `autowired:""`
}
func (i *imlServiceModule) ServiceOverview(ctx context.Context, id string) (*service_dto.Overview, error) {
info, err := i.serviceService.Get(ctx, id)
if err != nil {
return nil, err
}
apiCountMap, err := i.apiDocService.APICountByServices(ctx, id)
if err != nil {
return nil, err
}
subscribeMap, err := i.subscribeServer.CountMapByService(ctx, subscribe.ApplyStatusSubscribe, id)
if err != nil {
return nil, err
}
result := &service_dto.Overview{
Id: info.Id,
Name: info.Name,
Description: info.Description,
EnableMCP: info.EnableMCP,
ServiceKind: info.Kind.String(),
SubscriberNum: subscribeMap[id],
Logo: info.Logo,
Catalogue: auto.UUID(info.Catalogue),
APINum: apiCountMap[id],
}
_, err = i.releaseService.GetRunning(ctx, id)
if err != nil {
if !errors.Is(err, gorm.ErrRecordNotFound) {
return nil, err
}
} else {
result.IsReleased = true
}
return result, nil
}
func (i *imlServiceModule) OnInit() {
+2
View File
@@ -34,6 +34,8 @@ type IServiceModule interface {
//MySimple 获取我的简易项目列表
MySimple(ctx context.Context) ([]*service_dto.SimpleServiceItem, error)
ServiceOverview(ctx context.Context, id string) (*service_dto.Overview, error)
}
type IServiceDocModule interface {
+1
View File
@@ -43,5 +43,6 @@ func (p *plugin) ServiceApis() []pm3.Api {
pm3.CreateApiWidthDoc(http.MethodGet, "/api/v1/service/monitor/top10", []string{"context", "query:service", "query:start", "query:end"}, []string{"apis", "consumers"}, p.serviceController.Top10, access.SystemWorkspaceServiceViewAll, access.TeamTeamServiceView),
pm3.CreateApiWidthDoc(http.MethodGet, "/api/v1/service/overview/monitor/ai", []string{"context", "query:service", "query:start", "query:end"}, []string{"overview"}, p.serviceController.AIChartOverview, access.SystemWorkspaceServiceViewAll, access.TeamTeamServiceView),
pm3.CreateApiWidthDoc(http.MethodGet, "/api/v1/service/overview/monitor/rest", []string{"context", "query:service", "query:start", "query:end"}, []string{"overview"}, p.serviceController.RestChartOverview, access.SystemWorkspaceServiceViewAll, access.TeamTeamServiceView),
pm3.CreateApiWidthDoc(http.MethodGet, "/api/v1/service/overview/basic", []string{"context", "query:service"}, []string{"overview"}, p.serviceController.ServiceOverview, access.SystemWorkspaceServiceViewAll, access.TeamTeamServiceView),
}
}