Skip to content

Commit

Permalink
fix(monitor): detach alert (#20373)
Browse files Browse the repository at this point in the history
  • Loading branch information
zexi committed May 28, 2024
1 parent 6294744 commit 8a0c2d3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
15 changes: 14 additions & 1 deletion pkg/monitor/models/monitor_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 11 additions & 0 deletions pkg/monitor/models/monitor_resource_alert.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 8a0c2d3

Please sign in to comment.