mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-06-20 10:22:22 +08:00
feat(monitor): update monitor resource overview
1.调整监控总览-报警资源逻辑 启用禁用策略时对报警资源进行对应的挂载和解绑
This commit is contained in:
@@ -7,8 +7,9 @@ import (
|
||||
)
|
||||
|
||||
type MonitorResourceJointListInput struct {
|
||||
MonitorResourceId string `json:"monitor_resource_id"`
|
||||
AlertId string `json:"alert_id"`
|
||||
MonitorResourceId string `json:"monitor_resource_id"`
|
||||
AlertId string `json:"alert_id"`
|
||||
JointId []int64 `json:"joint_id"`
|
||||
}
|
||||
|
||||
type MonitorResourceJointCreateInput struct {
|
||||
|
||||
@@ -516,6 +516,7 @@ func (c *QueryCondition) setResType() {
|
||||
metricMeasurement, _ := models.MetricMeasurementManager.GetCache().Get(c.Query.Model.Measurement)
|
||||
if metricMeasurement != nil {
|
||||
resType = metricMeasurement.ResType
|
||||
c.ResType = resType
|
||||
}
|
||||
if len(resType) != 0 && c.Query.Model.GroupBy[0].Params[0] != monitor.
|
||||
MEASUREMENT_TAG_ID[resType] {
|
||||
|
||||
@@ -1193,6 +1193,19 @@ func PerformConfigLog(model db.IModel, userCred mcclient.TokenCredential) {
|
||||
logclient.AddSimpleActionLog(model, logclient.ACT_UPDATE_RULE, nil, userCred, true)
|
||||
}
|
||||
|
||||
func (alert *SCommonAlert) AllowPerformEnable(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input apis.PerformEnableInput) bool {
|
||||
return db.IsProjectAllowPerform(userCred, alert, "enable")
|
||||
}
|
||||
|
||||
func (alert *SCommonAlert) PerformEnable(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input apis.PerformEnableInput) (jsonutils.JSONObject, error) {
|
||||
err := db.EnabledPerformEnable(alert, ctx, userCred, true)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "EnabledPerformEnable")
|
||||
}
|
||||
alert.StartUpdateMonitorAlertJointTask(ctx, userCred)
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (alert *SCommonAlert) AllowPerformDisable(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input apis.PerformDisableInput) bool {
|
||||
return db.IsProjectAllowPerform(userCred, alert, "disable")
|
||||
}
|
||||
@@ -1282,6 +1295,7 @@ func (alert *SCommonAlert) UpdateMonitorResourceJoint(ctx context.Context, userC
|
||||
}
|
||||
resourceIds = append(resourceIds, resourceId)
|
||||
}
|
||||
deleteJointIds := make([]int64, 0)
|
||||
joints, _ := MonitorResourceAlertManager.GetJoinsByListInput(monitor.MonitorResourceJointListInput{AlertId: alert.GetId()})
|
||||
jointLoop:
|
||||
for _, joint := range joints {
|
||||
@@ -1291,11 +1305,17 @@ jointLoop:
|
||||
continue jointLoop
|
||||
}
|
||||
}
|
||||
joint.Detach(ctx, userCred)
|
||||
deleteJointIds = append(deleteJointIds, joint.RowId)
|
||||
}
|
||||
if len(resourceIds) == 0 {
|
||||
return nil
|
||||
}
|
||||
if len(deleteJointIds) != 0 {
|
||||
err := MonitorResourceAlertManager.DetachJoint(ctx, userCred, monitor.MonitorResourceJointListInput{JointId: deleteJointIds})
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "DetachJoint By alertName:%s err", alert.GetName())
|
||||
}
|
||||
}
|
||||
monitorResources, _ := MonitorResourceManager.GetMonitorResources(monitor.MonitorResourceListInput{ResId: resourceIds})
|
||||
errs := make([]error, 0)
|
||||
for _, monRes := range monitorResources {
|
||||
|
||||
@@ -304,11 +304,13 @@ func (manager *SMonitorResourceManager) UpdateMonitorResourceAttachJoint(ctx con
|
||||
}
|
||||
matches, _ := alertRecord.GetEvalData()
|
||||
errs := make([]error, 0)
|
||||
matchResourceIds := make([]string, 0)
|
||||
for _, matche := range matches {
|
||||
resId := matche.Tags[monitor.MEASUREMENT_TAG_ID[alertRecord.ResType]]
|
||||
if len(resId) == 0 {
|
||||
continue
|
||||
}
|
||||
matchResourceIds = append(matchResourceIds, resId)
|
||||
monitorResources, err := manager.GetMonitorResources(monitor.MonitorResourceListInput{ResType: resType, ResId: []string{resId}})
|
||||
if err != nil {
|
||||
errs = append(errs, errors.Wrapf(err, "SMonitorResourceManager GetMonitorResources by resId:%s err", resId))
|
||||
@@ -321,6 +323,23 @@ func (manager *SMonitorResourceManager) UpdateMonitorResourceAttachJoint(ctx con
|
||||
}
|
||||
}
|
||||
}
|
||||
resourceAlerts, err := MonitorResourceAlertManager.GetJoinsByListInput(monitor.MonitorResourceJointListInput{AlertId: alertRecord.AlertId})
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "get monitor_resource_joint by alertId:%s err", alertRecord.AlertId)
|
||||
}
|
||||
deleteJointIds := make([]int64, 0)
|
||||
for _, joint := range resourceAlerts {
|
||||
if utils.IsInStringArray(joint.MonitorResourceId, matchResourceIds) {
|
||||
continue
|
||||
}
|
||||
deleteJointIds = append(deleteJointIds, joint.RowId)
|
||||
}
|
||||
if len(deleteJointIds) != 0 {
|
||||
err = MonitorResourceAlertManager.DetachJoint(ctx, userCred, monitor.MonitorResourceJointListInput{JointId: deleteJointIds})
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "DetachJoint by alertId:%s err", alertRecord.AlertId)
|
||||
}
|
||||
}
|
||||
return errors.NewAggregate(errs)
|
||||
}
|
||||
|
||||
|
||||
@@ -59,7 +59,7 @@ func (manager *SMonitorResourceAlertManager) DetachJoint(ctx context.Context, us
|
||||
}
|
||||
errs := make([]error, 0)
|
||||
for _, joint := range joints {
|
||||
err := joint.Delete(ctx, userCred)
|
||||
err := joint.Delete(ctx, nil)
|
||||
if err != nil {
|
||||
errs = append(errs, errors.Wrapf(err, "joint %s:%s ,%s:%s", manager.GetMasterFieldName(),
|
||||
joint.MonitorResourceId, manager.GetSlaveFieldName(), joint.AlertId))
|
||||
@@ -102,9 +102,12 @@ func (manager *SMonitorResourceAlertManager) GetJoinsByListInput(input monitor.M
|
||||
if len(input.AlertId) != 0 {
|
||||
query.Equals(manager.GetSlaveFieldName(), input.AlertId)
|
||||
}
|
||||
if len(input.JointId) != 0 {
|
||||
query.In("row_id", input.JointId)
|
||||
}
|
||||
err := db.FetchModelObjects(manager, query, &joints)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "FetchModelObjects by GetJoinsByMasterId:%s err", input)
|
||||
return nil, errors.Wrapf(err, "FetchModelObjects by GetJoinsByMasterId:%s err", input.MonitorResourceId)
|
||||
}
|
||||
return joints, nil
|
||||
}
|
||||
|
||||
@@ -132,6 +132,7 @@ monLoop:
|
||||
errs = append(errs, errors.Wrapf(err, "monitorResource:%s Update err", resource.Name))
|
||||
continue monLoop
|
||||
}
|
||||
resource.UpdateAlertState()
|
||||
if index == len(resources)-1 {
|
||||
resources = resources[0:index]
|
||||
} else {
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/errors"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/apis/monitor"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||
"yunion.io/x/onecloud/pkg/monitor/models"
|
||||
@@ -34,6 +35,12 @@ func (self *DetachAlertResourceTask) OnInit(ctx context.Context, obj db.IStandal
|
||||
if err != nil {
|
||||
log.Errorf("DetachAlertResourceTask NotifyAlertResourceCount error:%v", err)
|
||||
}
|
||||
// detach MonitorResourceJoint when alert disabel
|
||||
err = models.MonitorResourceAlertManager.DetachJoint(ctx, self.GetUserCred(),
|
||||
monitor.MonitorResourceJointListInput{AlertId: alert.GetId()})
|
||||
if err != nil {
|
||||
log.Errorf("DetachJoint when alert:%s disable err:%v", alert.GetName(), err)
|
||||
}
|
||||
logclient.AddActionLogWithStartable(self, alert, logclient.ACT_DETACH_ALERTRESOURCE, nil, self.UserCred, true)
|
||||
self.SetStageComplete(ctx, nil)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user