diff --git a/config/notifiers.go b/config/notifiers.go index 87f806aa27..b02261cbe4 100644 --- a/config/notifiers.go +++ b/config/notifiers.go @@ -905,10 +905,11 @@ type JiraConfig struct { Priority string `yaml:"priority,omitempty" json:"priority,omitempty"` IssueType string `yaml:"issue_type,omitempty" json:"issue_type,omitempty"` - ReopenTransition string `yaml:"reopen_transition,omitempty" json:"reopen_transition,omitempty"` - ResolveTransition string `yaml:"resolve_transition,omitempty" json:"resolve_transition,omitempty"` - WontFixResolution string `yaml:"wont_fix_resolution,omitempty" json:"wont_fix_resolution,omitempty"` - ReopenDuration model.Duration `yaml:"reopen_duration,omitempty" json:"reopen_duration,omitempty"` + DisableFieldUpdates bool `yaml:"disable_field_updates,omitempty" json:"disable_field_updates,omitempty"` + ReopenTransition string `yaml:"reopen_transition,omitempty" json:"reopen_transition,omitempty"` + ResolveTransition string `yaml:"resolve_transition,omitempty" json:"resolve_transition,omitempty"` + WontFixResolution string `yaml:"wont_fix_resolution,omitempty" json:"wont_fix_resolution,omitempty"` + ReopenDuration model.Duration `yaml:"reopen_duration,omitempty" json:"reopen_duration,omitempty"` Fields map[string]any `yaml:"fields,omitempty" json:"custom_fields,omitempty"` } diff --git a/docs/configuration.md b/docs/configuration.md index 6a7c6b9c7d..67157ffdf3 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -1035,6 +1035,10 @@ labels: # Type of the issue (e.g. Bug). [ issue_type: ] +# Disable updates to fields once an issue is created. If false, the alertmanager will overwrite changes after every notification. +# NOTE: Disabling field updates does not disable transitions. +[ disable_field_updates: | default = false ] + # Name of the workflow transition to resolve an issue. The target status must have the category "done". # NOTE: The name of the transition can be localized and depends on the language setting of the service account. [ resolve_transition: ] diff --git a/notify/jira/jira.go b/notify/jira/jira.go index 259a5e62aa..846d54a581 100644 --- a/notify/jira/jira.go +++ b/notify/jira/jira.go @@ -100,6 +100,9 @@ func (n *Notifier) Notify(ctx context.Context, as ...*types.Alert) (bool, error) logger.Debug("create new issue") } else { + if n.conf.DisableFieldUpdates { + return n.transitionIssue(ctx, logger, existingIssue, alerts.HasFiring()) + } path = "issue/" + existingIssue.Key method = http.MethodPut diff --git a/notify/jira/jira_test.go b/notify/jira/jira_test.go index 9b5868aa59..891d5b33f6 100644 --- a/notify/jira/jira_test.go +++ b/notify/jira/jira_test.go @@ -596,6 +596,55 @@ func TestJiraNotify(t *testing.T) { customFieldAssetFn: func(t *testing.T, issue map[string]any) {}, errMsg: "can't find transition REOPEN for issue OPS-3", }, + { + title: "skip update request when DisableFieldUpdates is true", + cfg: &config.JiraConfig{ + Summary: `{{ template "jira.default.summary" . }}`, + Description: `{{ template "jira.default.description" . }}`, + IssueType: "{{ .CommonLabels.issue_type }}", + Project: "{{ .CommonLabels.project }}", + Priority: `{{ template "jira.default.priority" . }}`, + Labels: []string{"alertmanager", "{{ .GroupLabels.alertname }}"}, + DisableFieldUpdates: true, + }, + alert: &types.Alert{ + Alert: model.Alert{ + Labels: model.LabelSet{ + "alertname": "DisableFieldUpdates", + "project": "OPS", + "issue_type": "Bug", + }, + StartsAt: time.Now(), + EndsAt: time.Now().Add(time.Hour), + }, + }, + searchResponse: issueSearchResult{ + Total: 1, + Issues: []issue{ + { + Key: "OPS-3", + Fields: &issueFields{ + Status: &issueStatus{ + Name: "Open", + StatusCategory: struct { + Key string `json:"key"` + }{ + Key: "open", + }, + }, + }, + }, + }, + }, + issue: issue{ + Key: "", + Fields: &issueFields{ + Summary: "These issue fields don't match the issue in the search response above", + Description: "If the test checks these values, then it tried to update the fields and it should fail", + }, + }, + customFieldAssetFn: func(t *testing.T, issue map[string]any) {}, + }, } { tc := tc