From b4896b8b3880abf500f7ba3035de1d37a2f9812f Mon Sep 17 00:00:00 2001 From: zhangwei <894646498@qq.com> Date: Wed, 6 Nov 2024 20:54:22 +0800 Subject: [PATCH] bug fix --- internal/logic/core/centerresourceslogic.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/internal/logic/core/centerresourceslogic.go b/internal/logic/core/centerresourceslogic.go index 29471a08..e7cdbc18 100644 --- a/internal/logic/core/centerresourceslogic.go +++ b/internal/logic/core/centerresourceslogic.go @@ -26,8 +26,8 @@ func NewCenterResourcesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *C } } -func (l *CenterResourcesLogic) CenterResources() (resp *types.CenterResourcesResp, err error) { - resp = &types.CenterResourcesResp{} +func (l *CenterResourcesLogic) CenterResources() (*types.CenterResourcesResp, error) { + resp := &types.CenterResourcesResp{} rawData, err := l.svcCtx.PromClient.GetRawData("center_top3", tracker.AdapterOption{}) if err != nil { return nil, err @@ -45,9 +45,15 @@ func (l *CenterResourcesLogic) CenterResources() (resp *types.CenterResourcesRes } for _, centerIndex := range centersIndex { // Query the types of resource centers - l.svcCtx.DbEngin.Raw("select name,type as CenterType from t_adapter where id = ?", centerIndex.Id).Scan(¢erIndex) + tx := l.svcCtx.DbEngin.Raw("select name,type as CenterType from t_adapter where id = ?", centerIndex.Id).Scan(¢erIndex) + if tx.Error != nil { + return nil, tx.Error + } var clustersName string - l.svcCtx.DbEngin.Raw("SELECT GROUP_CONCAT(name SEPARATOR '|' ) as clustersName from t_cluster where adapter_id = ?", centerIndex.Id).Scan(&clustersName) + tx = l.svcCtx.DbEngin.Raw("SELECT GROUP_CONCAT(name SEPARATOR '|' ) as clustersName from t_cluster where adapter_id = ?", centerIndex.Id).Scan(&clustersName) + if tx.Error != nil { + return nil, tx.Error + } cpuRawData, err := l.svcCtx.PromClient.GetRawData("center_cpu_utilisation", tracker.AdapterOption{AdapterId: centerIndex.Id, ClustersName: clustersName}) cpuData := cpuRawData.(model.Vector) if err != nil {