Skip to content

Commit

Permalink
Alerts/edit rule issue 676 (SigNoz#1505)
Browse files Browse the repository at this point in the history
* fix: resolved issue with editing of rules

(cherry picked from commit a3015d1)
  • Loading branch information
mindhash authored and prashant-shahi committed Aug 11, 2022
1 parent 998e723 commit 54cc363
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions pkg/query-service/rules/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,8 @@ func (m *Manager) EditRule(ruleStr string, id string) error {
func (m *Manager) editTask(rule *PostableRule, taskName string) error {
m.mtx.Lock()
defer m.mtx.Unlock()

zap.S().Debugf("msg:", "editing a rule task", "\t task name:", taskName)

newTask, err := m.prepareTask(false, rule, taskName)

Expand Down Expand Up @@ -298,12 +300,14 @@ func (m *Manager) DeleteRule(id string) error {
func (m *Manager) deleteTask(taskName string) {
m.mtx.Lock()
defer m.mtx.Unlock()
zap.S().Debugf("msg:", "deleting a rule task", "\t task name:", taskName)

oldg, ok := m.tasks[taskName]
if ok {
oldg.Stop()
delete(m.tasks, taskName)
delete(m.rules, ruleIdFromTaskName(taskName))
zap.S().Debugf("msg:", "rule task deleted", "\t task name:", taskName)
} else {
zap.S().Info("msg: ", "rule not found for deletion", "\t name:", taskName)
}
Expand Down Expand Up @@ -337,6 +341,7 @@ func (m *Manager) addTask(rule *PostableRule, taskName string) error {
m.mtx.Lock()
defer m.mtx.Unlock()

zap.S().Debugf("msg:", "adding a new rule task", "\t task name:", taskName)
newTask, err := m.prepareTask(false, rule, taskName)

if err != nil {
Expand Down Expand Up @@ -605,6 +610,10 @@ func (m *Manager) syncRuleStateWithTask(taskName string, rule *PostableRule) err
if err := m.addTask(rule, taskName); err != nil {
return err
}
} else {
if err := m.editTask(rule, taskName); err != nil {
return err
}
}
}
return nil
Expand Down

0 comments on commit 54cc363

Please sign in to comment.