Skip to content
Merged
Show file tree
Hide file tree
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
13 changes: 7 additions & 6 deletions notify/jira/jira.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,16 +201,17 @@ func (n *Notifier) searchExistingIssue(ctx context.Context, logger *slog.Logger,
jql.WriteString(fmt.Sprintf(`resolution != %q and `, n.conf.WontFixResolution))
}

// If the group is firing, do not search for closed issues unless a reopen transition is defined.
// If the group is firing, search for open issues. If a reopen transition is
// defined, also search for issues that were closed within the reopen duration.
if firing {
if n.conf.ReopenTransition == "" {
jql.WriteString(`statusCategory != Done and `)
}
} else {
reopenDuration := int64(time.Duration(n.conf.ReopenDuration).Minutes())
if reopenDuration != 0 {
if n.conf.ReopenTransition != "" && reopenDuration > 0 {
jql.WriteString(fmt.Sprintf(`(resolutiondate is EMPTY OR resolutiondate >= -%dm) and `, reopenDuration))
} else {
jql.WriteString(`statusCategory != Done and `)
}
} else {
jql.WriteString(`statusCategory != Done and `)
}

alertLabel := fmt.Sprintf("ALERT{%s}", groupID)
Expand Down
30 changes: 28 additions & 2 deletions notify/jira/jira_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,19 +100,45 @@ func TestSearchExistingIssue(t *testing.T) {
title string
cfg *config.JiraConfig
groupKey string
firing bool
expectedJQL string
expectedIssue *issue
expectedErr bool
expectedRetry bool
}{
{
title: "search existing issue with project template",
title: "search existing issue with project template for firing alert",
cfg: &config.JiraConfig{
Summary: `{{ template "jira.default.summary" . }}`,
Description: `{{ template "jira.default.description" . }}`,
Project: `{{ .CommonLabels.project }}`,
},
groupKey: "1",
firing: true,
expectedJQL: `statusCategory != Done and project="PROJ" and labels="ALERT{1}" order by status ASC,resolutiondate DESC`,
},
{
title: "search existing issue with reopen duration for firing alert",
cfg: &config.JiraConfig{
Summary: `{{ template "jira.default.summary" . }}`,
Description: `{{ template "jira.default.description" . }}`,
Project: `{{ .CommonLabels.project }}`,
ReopenDuration: model.Duration(60 * time.Minute),
ReopenTransition: "REOPEN",
},
groupKey: "1",
firing: true,
expectedJQL: `(resolutiondate is EMPTY OR resolutiondate >= -60m) and project="PROJ" and labels="ALERT{1}" order by status ASC,resolutiondate DESC`,
},
{
title: "search existing issue for resolved alert",
cfg: &config.JiraConfig{
Summary: `{{ template "jira.default.summary" . }}`,
Description: `{{ template "jira.default.description" . }}`,
Project: `{{ .CommonLabels.project }}`,
},
groupKey: "1",
firing: false,
expectedJQL: `statusCategory != Done and project="PROJ" and labels="ALERT{1}" order by status ASC,resolutiondate DESC`,
},
} {
Expand Down Expand Up @@ -147,7 +173,7 @@ func TestSearchExistingIssue(t *testing.T) {
return tmplText(tmpl), tmplTextErr
}

issue, retry, err := pd.searchExistingIssue(ctx, logger, tc.groupKey, true, tmplTextFunc)
issue, retry, err := pd.searchExistingIssue(ctx, logger, tc.groupKey, tc.firing, tmplTextFunc)
if tc.expectedErr {
require.Error(t, err)
} else {
Expand Down
Loading