fix(monitor): detach alert (#20375)

This commit is contained in:
Zexi Li
2024-05-28 10:00:03 +08:00
committed by GitHub
parent 903e5f5203
commit eb102ad7e4
2 changed files with 25 additions and 1 deletions
+14 -1
View File
@@ -416,7 +416,20 @@ func (manager *SMonitorResourceManager) UpdateMonitorResourceAttachJoint(ctx con
}
deleteJointIds := make([]int64, 0)
for _, joint := range resourceAlerts {
if utils.IsInStringArray(joint.MonitorResourceId, matchResourceIds) {
evalData, err := joint.GetData()
if err != nil {
log.Warningf("get data of monitor_resource_alert %s: %s", jsonutils.Marshal(joint), err)
continue
}
metricName := evalData.Metric
isMetricFound := false
for _, match := range matches {
if match.Metric == metricName {
isMetricFound = true
break
}
}
if utils.IsInStringArray(joint.MonitorResourceId, matchResourceIds) && isMetricFound {
continue
}
deleteJointIds = append(deleteJointIds, joint.RowId)
@@ -152,6 +152,17 @@ func (obj *SMonitorResourceAlert) UpdateAlertRecordData(record *SAlertRecord, ma
return nil
}
func (obj *SMonitorResourceAlert) GetData() (*monitor.EvalMatch, error) {
if obj.Data == nil {
return nil, errors.Errorf("data is nil")
}
match := new(monitor.EvalMatch)
if err := obj.Data.Unmarshal(match); err != nil {
return nil, errors.Wrap(err, "unmarshal to monitor.EvalMatch")
}
return match, nil
}
func (m *SMonitorResourceAlertManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential, input *monitor.MonitorResourceJointListInput) (*sqlchemy.SQuery, error) {
var err error
q, err = m.SJointResourceBaseManager.ListItemFilter(ctx, q, userCred, input.JointResourceBaseListInput)