Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change transition order #131

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 23 additions & 9 deletions pkg/notify/notify.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,20 @@ func (r *Receiver) Notify(data *alertmanager.Data, hashJiraLabel bool) (bool, er
return false, errors.Wrap(err, "render issue description")
}

// Issue already exists.
if issue != nil {

// Issue is closed and should be reopened
if issue.Fields.Status.StatusCategory.Key == "done" && issue.Fields.Resolution.Name != r.conf.WontFixResolution {
level.Info(r.logger).Log("msg", "issue was recently resolved, reopening", "key", issue.Key, "label", issueGroupLabel)
retry, err := r.reopen(issue.Key)
if err != nil {
return retry, err
}
// Issue is not dynamically updated, so we need to modify the Resolution to avoid creating duplicates on a "won't fix" situation
issue.Fields.Resolution = nil
Comment on lines +97 to +98
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I understand this.

}

// Update summary if needed.
if issue.Fields.Summary != issueSummary {
retry, err := r.updateSummary(issue.Key, issueSummary)
Expand All @@ -93,13 +106,22 @@ func (r *Receiver) Notify(data *alertmanager.Data, hashJiraLabel bool) (bool, er
}
}

// Update description if needed.
if issue.Fields.Description != issueDesc {
retry, err := r.updateDescription(issue.Key, issueDesc)
if err != nil {
return retry, err
}
}

// Issue is set as won't fix. Discard.
if r.conf.WontFixResolution != "" && issue.Fields.Resolution != nil &&
issue.Fields.Resolution.Name == r.conf.WontFixResolution {
level.Info(r.logger).Log("msg", "issue was resolved as won't fix, not reopening", "key", issue.Key, "label", issueGroupLabel, "resolution", issue.Fields.Resolution.Name)
return false, nil
}
Comment on lines +117 to +122
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this go at the very top? I.e. before the summary and/or description are updated?


// Alert has been resolved. Close issue.
if len(data.Alerts.Firing()) == 0 {
if r.conf.AutoResolve != nil {
level.Debug(r.logger).Log("msg", "no firing alert; resolving issue", "key", issue.Key, "label", issueGroupLabel)
Expand All @@ -115,19 +137,11 @@ func (r *Receiver) Notify(data *alertmanager.Data, hashJiraLabel bool) (bool, er
}

// The set of JIRA status categories is fixed, this is a safe check to make.
if issue.Fields.Status.StatusCategory.Key != "done" {
if issue.Fields.Resolution == nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand this either.

Since the issue is about Jira not allowing editing issues in certain states (which presumably covers the summary and description), shouldn't the fix be to just move updating of the summary and description after the r.reopen()?

As is, the code first tries to reopen the issue (and edit it). Then it checks whether it should be reopened. Then resolves it, if no alerts are firing. Finally, if it has just reopened the issue, it logs "issue is unresolved" and exits. Seems kind of random.

level.Debug(r.logger).Log("msg", "issue is unresolved, all is done", "key", issue.Key, "label", issueGroupLabel)
return false, nil
}

if r.conf.WontFixResolution != "" && issue.Fields.Resolution != nil &&
issue.Fields.Resolution.Name == r.conf.WontFixResolution {
level.Info(r.logger).Log("msg", "issue was resolved as won't fix, not reopening", "key", issue.Key, "label", issueGroupLabel, "resolution", issue.Fields.Resolution.Name)
return false, nil
}

level.Info(r.logger).Log("msg", "issue was recently resolved, reopening", "key", issue.Key, "label", issueGroupLabel)
return r.reopen(issue.Key)
}

if len(data.Alerts.Firing()) == 0 {
Expand Down