From 6a8325e2186083066a89b6b1b8a115209a826417 Mon Sep 17 00:00:00 2001 From: MytkoEnko Date: Sun, 30 Apr 2023 15:54:13 +0200 Subject: [PATCH 01/10] Allowing selected (custom/standard) fields to be updated Signed-off-by: MytkoEnko --- examples/jiralert.yml | 5 +++ pkg/config/config.go | 16 +++++---- pkg/config/config_test.go | 15 +++++--- pkg/notify/notify.go | 47 ++++++++++++++++++++++++- pkg/notify/notify_test.go | 72 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 143 insertions(+), 12 deletions(-) diff --git a/examples/jiralert.yml b/examples/jiralert.yml index 46263c3..1a8029b 100644 --- a/examples/jiralert.yml +++ b/examples/jiralert.yml @@ -64,6 +64,11 @@ receivers: # MultiSelect customfield_10003: [{"value": "red"}, {"value": "blue"}, {"value": "green"}] # + # List of standard or custom field names which values will be updated. Optional. + update_always_fields: + - customfield_10001 + - customfield_10003 + # # Automatically resolve jira issues when alert is resolved. Optional. If declared, ensure state is not an empty string. auto_resolve: state: 'Done' diff --git a/pkg/config/config.go b/pkg/config/config.go index 7fc63c4..c239bd1 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -140,12 +140,13 @@ type ReceiverConfig struct { ReopenDuration *Duration `yaml:"reopen_duration" json:"reopen_duration"` // Optional issue fields - Priority string `yaml:"priority" json:"priority"` - Description string `yaml:"description" json:"description"` - WontFixResolution string `yaml:"wont_fix_resolution" json:"wont_fix_resolution"` - Fields map[string]interface{} `yaml:"fields" json:"fields"` - Components []string `yaml:"components" json:"components"` - StaticLabels []string `yaml:"static_labels" json:"static_labels"` + Priority string `yaml:"priority" json:"priority"` + Description string `yaml:"description" json:"description"` + WontFixResolution string `yaml:"wont_fix_resolution" json:"wont_fix_resolution"` + Fields map[string]interface{} `yaml:"fields" json:"fields"` + Components []string `yaml:"components" json:"components"` + StaticLabels []string `yaml:"static_labels" json:"static_labels"` + CustomFieldsToUpdate []string `yaml:"update_always_fields" json:"update_always_fields"` // Label copy settings AddGroupLabels *bool `yaml:"add_group_labels" json:"add_group_labels"` @@ -312,6 +313,9 @@ func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error { } } } + if len(c.Defaults.CustomFieldsToUpdate) > 0 { + rc.CustomFieldsToUpdate = c.Defaults.CustomFieldsToUpdate + } if len(c.Defaults.StaticLabels) > 0 { rc.StaticLabels = append(rc.StaticLabels, c.Defaults.StaticLabels...) } diff --git a/pkg/config/config_test.go b/pkg/config/config_test.go index e0bd0c9..3ca2dcb 100644 --- a/pkg/config/config_test.go +++ b/pkg/config/config_test.go @@ -76,6 +76,10 @@ receivers: customfield_10002: { "value": "red" } # MultiSelect customfield_10003: [{"value": "red" }, {"value": "blue" }, {"value": "green" }] + # List of standard or custom field names which values will be updated. Optional. + update_always_fields: + - customfield_10001 + - customfield_10003 # File containing template definitions. Required. template: jiralert.tmpl @@ -126,12 +130,13 @@ type receiverTestConfig struct { ReopenState string `yaml:"reopen_state,omitempty"` ReopenDuration string `yaml:"reopen_duration,omitempty"` - Priority string `yaml:"priority,omitempty"` - Description string `yaml:"description,omitempty"` - WontFixResolution string `yaml:"wont_fix_resolution,omitempty"` - AddGroupLabels *bool `yaml:"add_group_labels,omitempty"` + Priority string `yaml:"priority,omitempty"` + Description string `yaml:"description,omitempty"` + WontFixResolution string `yaml:"wont_fix_resolution,omitempty"` + AddGroupLabels *bool `yaml:"add_group_labels,omitempty"` UpdateInComment *bool `yaml:"update_in_comment,omitempty"` - StaticLabels []string `yaml:"static_labels" json:"static_labels"` + StaticLabels []string `yaml:"static_labels" json:"static_labels"` + CustomFieldsToUpdate []string `yaml:"update_always_fields,omitempty"` AutoResolve *AutoResolve `yaml:"auto_resolve" json:"auto_resolve"` diff --git a/pkg/notify/notify.go b/pkg/notify/notify.go index e4b96a2..b7bcea6 100644 --- a/pkg/notify/notify.go +++ b/pkg/notify/notify.go @@ -91,6 +91,18 @@ func (r *Receiver) Notify(data *alertmanager.Data, hashJiraLabel bool, updateSum issueDesc = issueDesc[:maxDescriptionLength] } + issueCustomFields := tcontainer.NewMarshalMap() + + for _, field := range r.conf.CustomFieldsToUpdate { + _, ok := r.conf.Fields[field] + if ok { + issueCustomFields[field], err = deepCopyWithTemplate(r.conf.Fields[field], r.tmpl, data) + if err != nil { + return false, errors.Wrap(err, "render issue fields") + } + } + } + if issue != nil { // Update summary if needed. @@ -135,6 +147,23 @@ func (r *Receiver) Notify(data *alertmanager.Data, hashJiraLabel bool, updateSum } } + + for CustomField := range issueCustomFields { + if _, ok := issue.Fields.Unknowns[CustomField]; ok { + if issue.Fields.Unknowns[CustomField] != issueCustomFields[CustomField] { + retry, err = r.updateUnknownFields(issue.Key, tcontainer.MarshalMap(map[string]interface{}{ + CustomField: issueCustomFields[CustomField], + })) + if err != nil { + return retry, err + } + } + if err != nil { + return false, err + } + } + } + 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) @@ -316,7 +345,7 @@ func (r *Receiver) search(projects []string, issueLabel string) (*jira.Issue, bo projectList := "'" + strings.Join(projects, "', '") + "'" query := fmt.Sprintf("project in(%s) and labels=%q order by resolutiondate desc", projectList, issueLabel) options := &jira.SearchOptions{ - Fields: []string{"summary", "status", "resolution", "resolutiondate", "description", "comment"}, + Fields: append([]string{"summary", "status", "resolution", "resolutiondate", "description", "comment"}, r.conf.CustomFieldsToUpdate...), MaxResults: 2, } @@ -418,6 +447,22 @@ func (r *Receiver) addComment(issueKey string, content string) (bool, error) { return false, nil } +func (r *Receiver) updateUnknownFields(issueKey string, unknowns tcontainer.MarshalMap) (bool, error) { + level.Debug(r.logger).Log("msg", "updating issue with unknown fields", "key", issueKey, "unknowns", unknowns) + + issueUpdate := &jira.Issue{ + Key: issueKey, + Fields: &jira.IssueFields{ + Unknowns: unknowns, + }, + } + _, resp, err := r.client.UpdateWithOptions(issueUpdate, nil) + if err != nil { + return handleJiraErrResponse("Issue.UpdateWithOptions", resp, err, r.logger) + } + return false, nil +} + func (r *Receiver) reopen(issueKey string) (bool, error) { return r.doTransition(issueKey, r.conf.ReopenState) } diff --git a/pkg/notify/notify_test.go b/pkg/notify/notify_test.go index 49d686f..3b64b3a 100644 --- a/pkg/notify/notify_test.go +++ b/pkg/notify/notify_test.go @@ -56,6 +56,7 @@ func (f *fakeJira) Search(jql string, options *jira.SearchOptions) ([]jira.Issue var issues []jira.Issue for _, key := range f.keysByQuery[jql] { issue := jira.Issue{Key: key, Fields: &jira.IssueFields{}} + issue.Fields.Unknowns = f.issuesByKey[key].Fields.Unknowns for _, field := range options.Fields { switch field { case "summary": @@ -132,6 +133,10 @@ func (f *fakeJira) UpdateWithOptions(old *jira.Issue, _ *jira.UpdateQueryOptions issue.Fields.Description = old.Fields.Description } + if old.Fields.Unknowns != nil { + issue.Fields.Unknowns = old.Fields.Unknowns + } + f.issuesByKey[issue.Key] = issue return issue, nil, nil } @@ -222,6 +227,21 @@ func testReceiverConfigWithStaticLabels() *config.ReceiverConfig { } } +func testReceiverConfigWithCustomFields() *config.ReceiverConfig { + reopen := config.Duration(1 * time.Hour) + return &config.ReceiverConfig{ + Project: "abc", + Summary: `[{{ .Status | toUpper }}{{ if eq .Status "firing" }}:{{ .Alerts.Firing | len }}{{ end }}] {{ .GroupLabels.SortedPairs.Values | join " " }} {{ if gt (len .CommonLabels) (len .GroupLabels) }}({{ with .CommonLabels.Remove .GroupLabels.Names }}{{ .Values | join " " }}{{ end }}){{ end }}`, + ReopenDuration: &reopen, + ReopenState: "reopened", + Description: `{{ .Alerts.Firing | len }}`, + Fields: tcontainer.MarshalMap(map[string]interface{}{ + "customfield_12345": `{{ (index .Alerts 0).Annotations.AlertValue }}`, + }), + CustomFieldsToUpdate: []string{"customfield_12345","non_existant_field"}, + } +} + func TestNotify_JIRAInteraction(t *testing.T) { testNowTime := time.Now() @@ -347,6 +367,58 @@ func TestNotify_JIRAInteraction(t *testing.T) { }, }, }, + { + name: "opened ticket, update specified custom field value", + inputConfig: testReceiverConfigWithCustomFields(), + initJira: func(t *testing.T) *fakeJira { + f := newTestFakeJira() + _, _, err := f.Create(&jira.Issue{ + ID: "1", + Key: "1", + Fields: &jira.IssueFields{ + Project: jira.Project{Key: testReceiverConfigWithCustomFields().Project}, + Labels: []string{"JIRALERT{819ba5ecba4ea5946a8d17d285cb23f3bb6862e08bb602ab08fd231cd8e1a83a1d095b0208a661787e9035f0541817634df5a994d1b5d4200d6c68a7663c97f5}"}, + Unknowns: tcontainer.MarshalMap(map[string]interface{}{ + "customfield_12345": "90", + }), + Summary: "[FIRING:1] b d ", + Description: "1", + }, + }) + require.NoError(t, err) + return f + }, + inputAlert: &alertmanager.Data{ + Alerts: alertmanager.Alerts{ + {Status: alertmanager.AlertFiring, + Annotations: alertmanager.KV{ + "AlertValue": "95", + }, + }, + //{Status: "not firing"}, + }, + Status: alertmanager.AlertFiring, + GroupLabels: alertmanager.KV{"a": "b", "c": "d"}, + }, + expectedJiraIssues: map[string]*jira.Issue{ + "1": { + ID: "1", + Key: "1", + Fields: &jira.IssueFields{ + Project: jira.Project{Key: testReceiverConfigWithCustomFields().Project}, + Labels: []string{"JIRALERT{819ba5ecba4ea5946a8d17d285cb23f3bb6862e08bb602ab08fd231cd8e1a83a1d095b0208a661787e9035f0541817634df5a994d1b5d4200d6c68a7663c97f5}"}, + Status: &jira.Status{ + StatusCategory: jira.StatusCategory{Key: "NotDone"}, + }, + Unknowns: tcontainer.MarshalMap{ + "customfield_12345": "95", + }, + Summary: "[FIRING:1] b d ", + Description: "1", + }, + }, + }, + }, { name: "closed ticket, reopen and update summary", inputConfig: testReceiverConfig1(), From 4821a5a2534d33550819ed096140ef8883e7bab9 Mon Sep 17 00:00:00 2001 From: MytkoEnko Date: Sun, 30 Apr 2023 16:55:58 +0200 Subject: [PATCH 02/10] correct code style Signed-off-by: MytkoEnko --- pkg/notify/notify.go | 3 +-- pkg/notify/notify_test.go | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/pkg/notify/notify.go b/pkg/notify/notify.go index b7bcea6..374a2c9 100644 --- a/pkg/notify/notify.go +++ b/pkg/notify/notify.go @@ -147,7 +147,6 @@ func (r *Receiver) Notify(data *alertmanager.Data, hashJiraLabel bool, updateSum } } - for CustomField := range issueCustomFields { if _, ok := issue.Fields.Unknowns[CustomField]; ok { if issue.Fields.Unknowns[CustomField] != issueCustomFields[CustomField] { @@ -345,7 +344,7 @@ func (r *Receiver) search(projects []string, issueLabel string) (*jira.Issue, bo projectList := "'" + strings.Join(projects, "', '") + "'" query := fmt.Sprintf("project in(%s) and labels=%q order by resolutiondate desc", projectList, issueLabel) options := &jira.SearchOptions{ - Fields: append([]string{"summary", "status", "resolution", "resolutiondate", "description", "comment"}, r.conf.CustomFieldsToUpdate...), + Fields: append([]string{"summary", "status", "resolution", "resolutiondate", "description", "comment"}, r.conf.CustomFieldsToUpdate...), MaxResults: 2, } diff --git a/pkg/notify/notify_test.go b/pkg/notify/notify_test.go index 3b64b3a..8410710 100644 --- a/pkg/notify/notify_test.go +++ b/pkg/notify/notify_test.go @@ -238,7 +238,7 @@ func testReceiverConfigWithCustomFields() *config.ReceiverConfig { Fields: tcontainer.MarshalMap(map[string]interface{}{ "customfield_12345": `{{ (index .Alerts 0).Annotations.AlertValue }}`, }), - CustomFieldsToUpdate: []string{"customfield_12345","non_existant_field"}, + CustomFieldsToUpdate: []string{"customfield_12345", "non_existant_field"}, } } From bad9755baf2f62c29d13bd67c5ab1c13cb108561 Mon Sep 17 00:00:00 2001 From: MytkoEnko Date: Mon, 1 May 2023 19:47:02 +0200 Subject: [PATCH 03/10] Remove unnecessary code and comments Signed-off-by: MytkoEnko --- pkg/notify/notify.go | 3 --- pkg/notify/notify_test.go | 3 +-- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/pkg/notify/notify.go b/pkg/notify/notify.go index 374a2c9..ae6e98f 100644 --- a/pkg/notify/notify.go +++ b/pkg/notify/notify.go @@ -157,9 +157,6 @@ func (r *Receiver) Notify(data *alertmanager.Data, hashJiraLabel bool, updateSum return retry, err } } - if err != nil { - return false, err - } } } diff --git a/pkg/notify/notify_test.go b/pkg/notify/notify_test.go index 8410710..ecb3016 100644 --- a/pkg/notify/notify_test.go +++ b/pkg/notify/notify_test.go @@ -394,8 +394,7 @@ func TestNotify_JIRAInteraction(t *testing.T) { Annotations: alertmanager.KV{ "AlertValue": "95", }, - }, - //{Status: "not firing"}, + }, // New value for the field }, Status: alertmanager.AlertFiring, GroupLabels: alertmanager.KV{"a": "b", "c": "d"}, From 612c7dfb486e7d3d0190d75d20be286da3a7a8a6 Mon Sep 17 00:00:00 2001 From: Dmytro Aleksieiev Date: Mon, 5 Feb 2024 22:04:58 +0100 Subject: [PATCH 04/10] Update pkg/notify/notify.go Co-authored-by: Bartlomiej Plotka Signed-off-by: Dmytro Aleksieiev --- pkg/notify/notify.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pkg/notify/notify.go b/pkg/notify/notify.go index ae6e98f..4be42c3 100644 --- a/pkg/notify/notify.go +++ b/pkg/notify/notify.go @@ -94,8 +94,7 @@ func (r *Receiver) Notify(data *alertmanager.Data, hashJiraLabel bool, updateSum issueCustomFields := tcontainer.NewMarshalMap() for _, field := range r.conf.CustomFieldsToUpdate { - _, ok := r.conf.Fields[field] - if ok { + if _, ok := r.conf.Fields[field]; ok { issueCustomFields[field], err = deepCopyWithTemplate(r.conf.Fields[field], r.tmpl, data) if err != nil { return false, errors.Wrap(err, "render issue fields") From d4956132936cf4947488d4a0ba38a77af92a04f9 Mon Sep 17 00:00:00 2001 From: Dmytro Aleksieiev Date: Mon, 5 Feb 2024 22:05:24 +0100 Subject: [PATCH 05/10] Update pkg/notify/notify.go Co-authored-by: Bartlomiej Plotka Signed-off-by: Dmytro Aleksieiev --- pkg/notify/notify.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/notify/notify.go b/pkg/notify/notify.go index 4be42c3..d0b2f25 100644 --- a/pkg/notify/notify.go +++ b/pkg/notify/notify.go @@ -146,7 +146,7 @@ func (r *Receiver) Notify(data *alertmanager.Data, hashJiraLabel bool, updateSum } } - for CustomField := range issueCustomFields { + for field := range issueCustomFields { if _, ok := issue.Fields.Unknowns[CustomField]; ok { if issue.Fields.Unknowns[CustomField] != issueCustomFields[CustomField] { retry, err = r.updateUnknownFields(issue.Key, tcontainer.MarshalMap(map[string]interface{}{ From b7f238acde5ef9826496b3d6041976d4d283483d Mon Sep 17 00:00:00 2001 From: Dmytro Aleksieiev Date: Mon, 5 Feb 2024 22:05:33 +0100 Subject: [PATCH 06/10] Update pkg/notify/notify.go Co-authored-by: Bartlomiej Plotka Signed-off-by: Dmytro Aleksieiev --- pkg/notify/notify.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pkg/notify/notify.go b/pkg/notify/notify.go index d0b2f25..11134dd 100644 --- a/pkg/notify/notify.go +++ b/pkg/notify/notify.go @@ -451,9 +451,8 @@ func (r *Receiver) updateUnknownFields(issueKey string, unknowns tcontainer.Mars Unknowns: unknowns, }, } - _, resp, err := r.client.UpdateWithOptions(issueUpdate, nil) - if err != nil { - return handleJiraErrResponse("Issue.UpdateWithOptions", resp, err, r.logger) + if _, resp, err := r.client.UpdateWithOptions(issueUpdate, nil); err != nil { + return handleJiraErrResponse("Issue.UpdateUnknownFields", resp, err, r.logger) } return false, nil } From aa7bd7a7f5257d0c42e431a25a81298de40ed48d Mon Sep 17 00:00:00 2001 From: Dmytro Aleksieiev Date: Mon, 5 Feb 2024 22:05:59 +0100 Subject: [PATCH 07/10] Update pkg/config/config.go Co-authored-by: Bartlomiej Plotka Signed-off-by: Dmytro Aleksieiev --- pkg/config/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/config/config.go b/pkg/config/config.go index c239bd1..0558857 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -146,7 +146,7 @@ type ReceiverConfig struct { Fields map[string]interface{} `yaml:"fields" json:"fields"` Components []string `yaml:"components" json:"components"` StaticLabels []string `yaml:"static_labels" json:"static_labels"` - CustomFieldsToUpdate []string `yaml:"update_always_fields" json:"update_always_fields"` + FieldsToUpdate []string `yaml:"update_always_fields" json:"update_always_fields"` // Label copy settings AddGroupLabels *bool `yaml:"add_group_labels" json:"add_group_labels"` From eab76486f1f5f9261c96918135e95456bfac030c Mon Sep 17 00:00:00 2001 From: Dmytro Aleksieiev Date: Tue, 6 Feb 2024 20:23:09 +0100 Subject: [PATCH 08/10] Fmt and rename FieldsToUpdate Signed-off-by: Dmytro Aleksieiev --- pkg/config/config.go | 18 +++++++++--------- pkg/config/config_test.go | 2 +- pkg/notify/notify.go | 10 +++++----- pkg/notify/notify_test.go | 2 +- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/pkg/config/config.go b/pkg/config/config.go index 0558857..3c8dc9f 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -140,13 +140,13 @@ type ReceiverConfig struct { ReopenDuration *Duration `yaml:"reopen_duration" json:"reopen_duration"` // Optional issue fields - Priority string `yaml:"priority" json:"priority"` - Description string `yaml:"description" json:"description"` - WontFixResolution string `yaml:"wont_fix_resolution" json:"wont_fix_resolution"` - Fields map[string]interface{} `yaml:"fields" json:"fields"` - Components []string `yaml:"components" json:"components"` - StaticLabels []string `yaml:"static_labels" json:"static_labels"` - FieldsToUpdate []string `yaml:"update_always_fields" json:"update_always_fields"` + Priority string `yaml:"priority" json:"priority"` + Description string `yaml:"description" json:"description"` + WontFixResolution string `yaml:"wont_fix_resolution" json:"wont_fix_resolution"` + Fields map[string]interface{} `yaml:"fields" json:"fields"` + Components []string `yaml:"components" json:"components"` + StaticLabels []string `yaml:"static_labels" json:"static_labels"` + FieldsToUpdate []string `yaml:"update_always_fields" json:"update_always_fields"` // Label copy settings AddGroupLabels *bool `yaml:"add_group_labels" json:"add_group_labels"` @@ -313,8 +313,8 @@ func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error { } } } - if len(c.Defaults.CustomFieldsToUpdate) > 0 { - rc.CustomFieldsToUpdate = c.Defaults.CustomFieldsToUpdate + if len(c.Defaults.FieldsToUpdate) > 0 { + rc.FieldsToUpdate = c.Defaults.FieldsToUpdate } if len(c.Defaults.StaticLabels) > 0 { rc.StaticLabels = append(rc.StaticLabels, c.Defaults.StaticLabels...) diff --git a/pkg/config/config_test.go b/pkg/config/config_test.go index 3ca2dcb..5e6ee99 100644 --- a/pkg/config/config_test.go +++ b/pkg/config/config_test.go @@ -134,7 +134,7 @@ type receiverTestConfig struct { Description string `yaml:"description,omitempty"` WontFixResolution string `yaml:"wont_fix_resolution,omitempty"` AddGroupLabels *bool `yaml:"add_group_labels,omitempty"` - UpdateInComment *bool `yaml:"update_in_comment,omitempty"` + UpdateInComment *bool `yaml:"update_in_comment,omitempty"` StaticLabels []string `yaml:"static_labels" json:"static_labels"` CustomFieldsToUpdate []string `yaml:"update_always_fields,omitempty"` diff --git a/pkg/notify/notify.go b/pkg/notify/notify.go index 11134dd..5af8eac 100644 --- a/pkg/notify/notify.go +++ b/pkg/notify/notify.go @@ -93,7 +93,7 @@ func (r *Receiver) Notify(data *alertmanager.Data, hashJiraLabel bool, updateSum issueCustomFields := tcontainer.NewMarshalMap() - for _, field := range r.conf.CustomFieldsToUpdate { + for _, field := range r.conf.FieldsToUpdate { if _, ok := r.conf.Fields[field]; ok { issueCustomFields[field], err = deepCopyWithTemplate(r.conf.Fields[field], r.tmpl, data) if err != nil { @@ -147,10 +147,10 @@ func (r *Receiver) Notify(data *alertmanager.Data, hashJiraLabel bool, updateSum } for field := range issueCustomFields { - if _, ok := issue.Fields.Unknowns[CustomField]; ok { - if issue.Fields.Unknowns[CustomField] != issueCustomFields[CustomField] { + if _, ok := issue.Fields.Unknowns[field]; ok { + if issue.Fields.Unknowns[field] != issueCustomFields[field] { retry, err = r.updateUnknownFields(issue.Key, tcontainer.MarshalMap(map[string]interface{}{ - CustomField: issueCustomFields[CustomField], + field: issueCustomFields[field], })) if err != nil { return retry, err @@ -340,7 +340,7 @@ func (r *Receiver) search(projects []string, issueLabel string) (*jira.Issue, bo projectList := "'" + strings.Join(projects, "', '") + "'" query := fmt.Sprintf("project in(%s) and labels=%q order by resolutiondate desc", projectList, issueLabel) options := &jira.SearchOptions{ - Fields: append([]string{"summary", "status", "resolution", "resolutiondate", "description", "comment"}, r.conf.CustomFieldsToUpdate...), + Fields: append([]string{"summary", "status", "resolution", "resolutiondate", "description", "comment"}, r.conf.FieldsToUpdate...), MaxResults: 2, } diff --git a/pkg/notify/notify_test.go b/pkg/notify/notify_test.go index ecb3016..c306a5f 100644 --- a/pkg/notify/notify_test.go +++ b/pkg/notify/notify_test.go @@ -238,7 +238,7 @@ func testReceiverConfigWithCustomFields() *config.ReceiverConfig { Fields: tcontainer.MarshalMap(map[string]interface{}{ "customfield_12345": `{{ (index .Alerts 0).Annotations.AlertValue }}`, }), - CustomFieldsToUpdate: []string{"customfield_12345", "non_existant_field"}, + FieldsToUpdate: []string{"customfield_12345", "non_existant_field"}, } } From 9be41f880d7415185fb8f8c35768bebce98e1324 Mon Sep 17 00:00:00 2001 From: Dmytro Aleksieiev Date: Wed, 7 Feb 2024 11:46:19 +0100 Subject: [PATCH 09/10] Update pkg/config/config_test.go Co-authored-by: Bartlomiej Plotka Signed-off-by: Dmytro Aleksieiev --- pkg/config/config_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/config/config_test.go b/pkg/config/config_test.go index 5e6ee99..ddafa92 100644 --- a/pkg/config/config_test.go +++ b/pkg/config/config_test.go @@ -136,7 +136,7 @@ type receiverTestConfig struct { AddGroupLabels *bool `yaml:"add_group_labels,omitempty"` UpdateInComment *bool `yaml:"update_in_comment,omitempty"` StaticLabels []string `yaml:"static_labels" json:"static_labels"` - CustomFieldsToUpdate []string `yaml:"update_always_fields,omitempty"` + FieldsToUpdate []string `yaml:"update_always_fields,omitempty"` AutoResolve *AutoResolve `yaml:"auto_resolve" json:"auto_resolve"` From 76831574058e97f40f7c9610d4c85311cf9e0d61 Mon Sep 17 00:00:00 2001 From: Dmytro Aleksieiev Date: Wed, 7 Feb 2024 11:57:23 +0100 Subject: [PATCH 10/10] Fmt config_test.go Signed-off-by: Dmytro Aleksieiev --- pkg/config/config_test.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/pkg/config/config_test.go b/pkg/config/config_test.go index ddafa92..ac49db8 100644 --- a/pkg/config/config_test.go +++ b/pkg/config/config_test.go @@ -130,13 +130,13 @@ type receiverTestConfig struct { ReopenState string `yaml:"reopen_state,omitempty"` ReopenDuration string `yaml:"reopen_duration,omitempty"` - Priority string `yaml:"priority,omitempty"` - Description string `yaml:"description,omitempty"` - WontFixResolution string `yaml:"wont_fix_resolution,omitempty"` - AddGroupLabels *bool `yaml:"add_group_labels,omitempty"` - UpdateInComment *bool `yaml:"update_in_comment,omitempty"` - StaticLabels []string `yaml:"static_labels" json:"static_labels"` - FieldsToUpdate []string `yaml:"update_always_fields,omitempty"` + Priority string `yaml:"priority,omitempty"` + Description string `yaml:"description,omitempty"` + WontFixResolution string `yaml:"wont_fix_resolution,omitempty"` + AddGroupLabels *bool `yaml:"add_group_labels,omitempty"` + UpdateInComment *bool `yaml:"update_in_comment,omitempty"` + StaticLabels []string `yaml:"static_labels" json:"static_labels"` + FieldsToUpdate []string `yaml:"update_always_fields,omitempty"` AutoResolve *AutoResolve `yaml:"auto_resolve" json:"auto_resolve"`