Merge pull request 'alert' (#124) from zhangweiii/pcm-coordinator:master into master
Former-commit-id: 15540513ed115027887c5804a21a05b30b11dcc0
This commit is contained in:
commit
4453d4ae55
|
@ -14,6 +14,8 @@ type CreateAlertRuleReq {
|
|||
type (
|
||||
AlertRulesReq {
|
||||
AlertType string `form:"alertType"`
|
||||
AdapterId string `form:"adapterId,optional"`
|
||||
ClusterId string `form:"clusterId,optional"`
|
||||
}
|
||||
AlertRulesResp {
|
||||
alertRules []AlertRule `json:"alertRules"`
|
||||
|
@ -56,4 +58,26 @@ type (
|
|||
|
||||
type SyncClusterAlertReq {
|
||||
AlertRecordsMap map[string]interface{} `json:"alertRecordsMap"`
|
||||
}
|
||||
}
|
||||
|
||||
type (
|
||||
taskNumReq {
|
||||
clusterId string `form:"clusterId"`
|
||||
}
|
||||
taskNumResp {
|
||||
current int `json:"current"`
|
||||
today int `json:"today"`
|
||||
history int `json:"history"`
|
||||
failed int `json:"failed"`
|
||||
}
|
||||
)
|
||||
|
||||
type (
|
||||
adapterInfoReq{
|
||||
clusterId string `form:"clusterId"`
|
||||
}
|
||||
adapterInfoResp{
|
||||
name string `json:"name"`
|
||||
version string `json:"version"`
|
||||
}
|
||||
)
|
|
@ -132,11 +132,11 @@ service pcm {
|
|||
|
||||
@doc "paging queries the task list"
|
||||
@handler pageListTaskHandler
|
||||
get /core/task/list (pageTaskReq) returns(PageResult)
|
||||
get /core/task/list (pageTaskReq) returns (PageResult)
|
||||
|
||||
@doc "Statistical task status"
|
||||
@handler countTaskStatus
|
||||
get /core/task/countTaskStatus () returns(TaskStatusResp)
|
||||
get /core/task/countTaskStatus () returns (TaskStatusResp)
|
||||
}
|
||||
|
||||
//hpc二级接口
|
||||
|
@ -210,7 +210,7 @@ service pcm {
|
|||
|
||||
@doc "Create cloud computing common tasks"
|
||||
@handler commitGeneralTask
|
||||
post /cloud/task/create (GeneralTaskReq) returns()
|
||||
post /cloud/task/create (GeneralTaskReq) returns ()
|
||||
}
|
||||
|
||||
//智算二级接口
|
||||
|
@ -978,7 +978,7 @@ service pcm {
|
|||
|
||||
@doc "alert rules"
|
||||
@handler alertRulesHandler
|
||||
get /monitoring/alert/rule (AlertRulesReq)returns (AlertRulesResp)
|
||||
get /monitoring/alert/rule (AlertRulesReq) returns (AlertRulesResp)
|
||||
|
||||
@doc "cluster resource load"
|
||||
@handler clustersLoadHandler
|
||||
|
@ -994,5 +994,11 @@ service pcm {
|
|||
|
||||
@doc "Synchronize Cluster alert Information"
|
||||
@handler syncClusterAlertHandler
|
||||
post /core/syncClusterAlert (SyncClusterAlertReq)
|
||||
post /monitoring/syncClusterAlert (SyncClusterAlertReq)
|
||||
|
||||
@handler taskNumHandler
|
||||
get /monitoring/task/num (taskNumReq) returns (taskNumResp)
|
||||
|
||||
@handler adapterInfoHandler
|
||||
get /monitoring/adapter/info (adapterInfoReq) returns (adapterInfoResp)
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package monitoring
|
||||
|
||||
import (
|
||||
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result"
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/logic/monitoring"
|
||||
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
|
||||
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types"
|
||||
)
|
||||
|
||||
func AdapterInfoHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.AdapterInfoReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := monitoring.NewAdapterInfoLogic(r.Context(), svcCtx)
|
||||
resp, err := l.AdapterInfo(&req)
|
||||
result.HttpResult(r, w, resp, err)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package monitoring
|
||||
|
||||
import (
|
||||
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result"
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/logic/monitoring"
|
||||
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
|
||||
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types"
|
||||
)
|
||||
|
||||
func TaskNumHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.TaskNumReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := monitoring.NewTaskNumLogic(r.Context(), svcCtx)
|
||||
resp, err := l.TaskNum(&req)
|
||||
result.HttpResult(r, w, resp, err)
|
||||
}
|
||||
}
|
|
@ -1249,9 +1249,19 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
|||
},
|
||||
{
|
||||
Method: http.MethodPost,
|
||||
Path: "/core/syncClusterAlert",
|
||||
Path: "/monitoring/syncClusterAlert",
|
||||
Handler: monitoring.SyncClusterAlertHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodGet,
|
||||
Path: "/monitoring/task/num",
|
||||
Handler: monitoring.TaskNumHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodGet,
|
||||
Path: "/monitoring/adapter/info",
|
||||
Handler: monitoring.AdapterInfoHandler(serverCtx),
|
||||
},
|
||||
},
|
||||
rest.WithPrefix("/pcm/v1"),
|
||||
)
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
package monitoring
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
|
||||
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type AdapterInfoLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewAdapterInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AdapterInfoLogic {
|
||||
return &AdapterInfoLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *AdapterInfoLogic) AdapterInfo(req *types.AdapterInfoReq) (resp *types.AdapterInfoResp, err error) {
|
||||
// todo: add your logic here and delete this line
|
||||
resp = &types.AdapterInfoResp{}
|
||||
l.svcCtx.DbEngin.Raw("select ta.name , ta.version from t_adapter ta,t_cluster tc where tc.id = ? and tc.adapter_id = ta.id", req.ClusterId).Scan(resp)
|
||||
return resp, nil
|
||||
}
|
|
@ -2,6 +2,7 @@ package monitoring
|
|||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
|
||||
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types"
|
||||
|
@ -26,7 +27,14 @@ func NewAlertRulesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AlertR
|
|||
func (l *AlertRulesLogic) AlertRules(req *types.AlertRulesReq) (resp *types.AlertRulesResp, err error) {
|
||||
resp = &types.AlertRulesResp{}
|
||||
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.alert_type = ? AND ar.deleted_at IS NULL AND tc.deleted_at IS NULL GROUP BY ar.id", req.AlertType).Scan(&alertRules)
|
||||
sql := fmt.Sprintf("SELECT 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.alert_type = %s AND ar.deleted_at IS NULL AND tc.deleted_at IS NULL GROUP BY ar.id", req.AlertType)
|
||||
if req.AdapterId != "" {
|
||||
sql = fmt.Sprintf("SELECT 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 JOIN t_adapter ta ON ta.id = tc.adapter_id WHERE ar.alert_type = %s AND ta.id = %s AND ar.deleted_at IS NULL AND tc.deleted_at IS NULL GROUP BY ar.id", req.AlertType, req.AdapterId)
|
||||
}
|
||||
if req.ClusterId != "" {
|
||||
sql = fmt.Sprintf("SELECT 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.alert_type = %s AND ar.cluster_id = %s AND ar.deleted_at IS NULL AND tc.deleted_at IS NULL GROUP BY ar.id", req.AlertType, req.ClusterId)
|
||||
}
|
||||
l.svcCtx.DbEngin.Raw(sql).Scan(&alertRules)
|
||||
resp.AlertRules = alertRules
|
||||
return resp, nil
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ import (
|
|||
v12 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/util/intstr"
|
||||
"k8s.io/apimachinery/pkg/util/json"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type CreateAlertRuleLogic struct {
|
||||
|
@ -38,6 +39,7 @@ func (l *CreateAlertRuleLogic) CreateAlertRule(req *types.CreateAlertRuleReq) er
|
|||
// save to db
|
||||
var alertRule models.AlertRule
|
||||
tool.Convert(req, &alertRule)
|
||||
alertRule.ClusterId, _ = strconv.ParseInt(req.CLusterId, 10, 64)
|
||||
alertRule.Id = tool.GenSnowflakeID()
|
||||
tx := l.svcCtx.DbEngin.Save(&alertRule)
|
||||
if tx.Error != nil {
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
package monitoring
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
|
||||
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type TaskNumLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewTaskNumLogic(ctx context.Context, svcCtx *svc.ServiceContext) *TaskNumLogic {
|
||||
return &TaskNumLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *TaskNumLogic) TaskNum(req *types.TaskNumReq) (resp *types.TaskNumResp, err error) {
|
||||
resp = &types.TaskNumResp{}
|
||||
l.svcCtx.DbEngin.Raw("SELECT COUNT(id) from task_cloud where cluster_id = ? and status = 'running'", req.ClusterId).Scan(resp.Current)
|
||||
l.svcCtx.DbEngin.Raw("SELECT COUNT(id) from task_cloud where cluster_id = '' and DATE(start_time) = CURDATE()", req.ClusterId).Scan(resp.Today)
|
||||
l.svcCtx.DbEngin.Raw("SELECT COUNT(id) from task_cloud where cluster_id = ?", req.ClusterId).Scan(resp.History)
|
||||
l.svcCtx.DbEngin.Raw("SELECT COUNT(id) from task_cloud where cluster_id = ? and status = 'failed'", req.ClusterId).Scan(resp.Failed)
|
||||
return resp, nil
|
||||
}
|
|
@ -5559,6 +5559,8 @@ type CreateAlertRuleReq struct {
|
|||
|
||||
type AlertRulesReq struct {
|
||||
AlertType string `form:"alertType"`
|
||||
AdapterId string `form:"adapterId,optional"`
|
||||
ClusterId string `form:"clusterId,optional"`
|
||||
}
|
||||
|
||||
type AlertRulesResp struct {
|
||||
|
@ -5600,3 +5602,23 @@ type AlertListResp struct {
|
|||
type SyncClusterAlertReq struct {
|
||||
AlertRecordsMap map[string]interface{} `json:"alertRecordsMap"`
|
||||
}
|
||||
|
||||
type TaskNumReq struct {
|
||||
ClusterId string `form:"clusterId"`
|
||||
}
|
||||
|
||||
type TaskNumResp struct {
|
||||
Current int `json:"current"`
|
||||
Today int `json:"today"`
|
||||
History int `json:"history"`
|
||||
Failed int `json:"failed"`
|
||||
}
|
||||
|
||||
type AdapterInfoReq struct {
|
||||
ClusterId string `form:"clusterId"`
|
||||
}
|
||||
|
||||
type AdapterInfoResp struct {
|
||||
Name string `json:"name"`
|
||||
Version string `json:"version"`
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue