From 2929b6e0f36d6a9deda202291659bc1593514f3d Mon Sep 17 00:00:00 2001 From: zhangwei <894646498@qq.com> Date: Mon, 8 Apr 2024 09:16:52 +0800 Subject: [PATCH] alert Former-commit-id: b59e446af73f3fdbdfc9bcff0f7a6beaf6bac935 --- api/desc/monitoring/pcm-monitoring.api | 2 ++ api/internal/handler/monitoring/nodesloadtophandler.go | 7 ++----- api/internal/logic/monitoring/alertruleslogic.go | 4 +++- api/internal/logic/monitoring/nodesloadtoplogic.go | 2 +- api/internal/types/types.go | 2 ++ 5 files changed, 10 insertions(+), 7 deletions(-) diff --git a/api/desc/monitoring/pcm-monitoring.api b/api/desc/monitoring/pcm-monitoring.api index 9a09aed1..c5ff3f5a 100644 --- a/api/desc/monitoring/pcm-monitoring.api +++ b/api/desc/monitoring/pcm-monitoring.api @@ -33,6 +33,8 @@ type ( Metrics string `form:"metrics"` } nodesLoadTopResp { + code int `json:"code"` data interface{} `json:"data"` + msg string `json:"msg"` } ) \ No newline at end of file diff --git a/api/internal/handler/monitoring/nodesloadtophandler.go b/api/internal/handler/monitoring/nodesloadtophandler.go index 4c0e5925..81630285 100644 --- a/api/internal/handler/monitoring/nodesloadtophandler.go +++ b/api/internal/handler/monitoring/nodesloadtophandler.go @@ -1,6 +1,7 @@ package monitoring import ( + "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result" "net/http" "github.com/zeromicro/go-zero/rest/httpx" @@ -19,10 +20,6 @@ func NodesLoadTopHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { l := monitoring.NewNodesLoadTopLogic(r.Context(), svcCtx) resp, err := l.NodesLoadTop(&req) - if err != nil { - httpx.ErrorCtx(r.Context(), w, err) - } else { - httpx.OkJsonCtx(r.Context(), w, resp) - } + result.HttpResult(r, w, resp, err) } } diff --git a/api/internal/logic/monitoring/alertruleslogic.go b/api/internal/logic/monitoring/alertruleslogic.go index 93d5500c..ee9eb1dc 100644 --- a/api/internal/logic/monitoring/alertruleslogic.go +++ b/api/internal/logic/monitoring/alertruleslogic.go @@ -25,6 +25,8 @@ func NewAlertRulesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AlertR func (l *AlertRulesLogic) AlertRules() (resp *types.AlertRulesResp, err error) { resp = &types.AlertRulesResp{} - l.svcCtx.DbEngin.Raw("SELECT ar.id,ar.*,GROUP_CONCAT(tc.`name` ORDER BY tc.`name` ASC SEPARATOR ',') as cluster_name FROM alert_rule ar JOIN t_cluster tc ON ar.cluster_id = tc.id WHERE ar.deleted_at IS NULL AND tc.deleted_at IS NULL GROUP BY ar.id;").Scan(&resp) + var alertRules []types.AlertRule + l.svcCtx.DbEngin.Raw("SELECT ar.id,ar.*,GROUP_CONCAT(tc.`name` ORDER BY tc.`name` ASC SEPARATOR ',') as cluster_name FROM alert_rule ar JOIN t_cluster tc ON ar.cluster_id = tc.id WHERE ar.deleted_at IS NULL AND tc.deleted_at IS NULL GROUP BY ar.id").Scan(&alertRules) + resp.AlertRules = alertRules return resp, nil } diff --git a/api/internal/logic/monitoring/nodesloadtoplogic.go b/api/internal/logic/monitoring/nodesloadtoplogic.go index 7efb6cd4..5a1fd7e2 100644 --- a/api/internal/logic/monitoring/nodesloadtoplogic.go +++ b/api/internal/logic/monitoring/nodesloadtoplogic.go @@ -38,7 +38,7 @@ func (l *NodesLoadTopLogic) NodesLoadTop(req *types.NodesLoadTopReq) (resp *type ForceContentType("application/json"). Get(server + "/api/v1/monitoring/node") if err != nil || response.IsError() { - + return nil, err } return resp, nil } diff --git a/api/internal/types/types.go b/api/internal/types/types.go index ddea5775..274ccf66 100644 --- a/api/internal/types/types.go +++ b/api/internal/types/types.go @@ -5464,5 +5464,7 @@ type NodesLoadTopReq struct { } type NodesLoadTopResp struct { + Code int `json:"code"` Data interface{} `json:"data"` + Msg string `json:"msg"` }