mirror of
https://github.com/coreos/prometheus-operator.git
synced 2026-02-05 15:46:31 +01:00
Feat: Support api_type for Jira receiver in Alertmanager config secret (#8218)
* alertmanager: add support for the api type field * alertmanager: add test case for jira api_type not supported version to cover more test case * alertmanager: update test case to fix mandatory field issue * alertmanager: update unit test golden file to match the test case * amcfg: add value check to sanitize to prevent unexpected value in api_type * amcfg: update sanitize method to fix the validation issue * amcfg: add new api type test case to cover wrong api type detection
This commit is contained in:
@@ -2772,6 +2772,19 @@ func (jc *jiraConfig) sanitize(amVersion semver.Version, logger *slog.Logger) er
|
||||
return errors.New("missing issue_type in jira_config")
|
||||
}
|
||||
|
||||
apiTypeAllowed := amVersion.GTE(semver.MustParse("0.29.0"))
|
||||
if jc.APIType != "" {
|
||||
if !apiTypeAllowed {
|
||||
msg := "'api_type' supported in Alertmanager >= 0.29.0 only - dropping field from provided config"
|
||||
logger.Warn(msg, "current_version", amVersion.String())
|
||||
jc.APIType = ""
|
||||
} else {
|
||||
if jc.APIType != "auto" && jc.APIType != "cloud" && jc.APIType != "datacenter" {
|
||||
return fmt.Errorf("invalid 'api_type': a value must be 'auto', 'cloud' or 'datacenter'")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return jc.HTTPConfig.sanitize(amVersion, logger)
|
||||
}
|
||||
|
||||
|
||||
@@ -5846,6 +5846,9 @@ func TestSanitizeJiraConfig(t *testing.T) {
|
||||
logger := newNopLogger(t)
|
||||
versionJiraAllowed := semver.Version{Major: 0, Minor: 28}
|
||||
versionJiraNotAllowed := semver.Version{Major: 0, Minor: 27}
|
||||
|
||||
versionAPITypeAllowed := semver.Version{Major: 0, Minor: 29}
|
||||
versionAPITypeNotAllowed := semver.Version{Major: 0, Minor: 28}
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
againstVersion semver.Version
|
||||
@@ -5922,6 +5925,63 @@ func TestSanitizeJiraConfig(t *testing.T) {
|
||||
},
|
||||
golden: "jira_configs_with_send_resolved.golden",
|
||||
},
|
||||
{
|
||||
name: "jira_configs with api_type",
|
||||
againstVersion: versionAPITypeAllowed,
|
||||
in: &alertmanagerConfig{
|
||||
Receivers: []*receiver{
|
||||
{
|
||||
JiraConfigs: []*jiraConfig{
|
||||
{
|
||||
APIURL: "http://issues.example.com",
|
||||
Project: "Monitoring",
|
||||
APIType: "datacenter",
|
||||
IssueType: "Bug",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
golden: "jira_config_with_api_type.golden",
|
||||
},
|
||||
{
|
||||
name: "jira_configs with api_type version not supported",
|
||||
againstVersion: versionAPITypeNotAllowed,
|
||||
in: &alertmanagerConfig{
|
||||
Receivers: []*receiver{
|
||||
{
|
||||
JiraConfigs: []*jiraConfig{
|
||||
{
|
||||
APIURL: "http://issues.example.com",
|
||||
Project: "Monitoring",
|
||||
APIType: "datacenter",
|
||||
IssueType: "Bug",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
golden: "jira_config_with_api_type_version_not_supported.golden",
|
||||
},
|
||||
{
|
||||
name: "jira_configs with invalid api_type",
|
||||
againstVersion: versionAPITypeAllowed,
|
||||
in: &alertmanagerConfig{
|
||||
Receivers: []*receiver{
|
||||
{
|
||||
JiraConfigs: []*jiraConfig{
|
||||
{
|
||||
APIURL: "http://issues.example.com",
|
||||
Project: "Monitoring",
|
||||
APIType: "onpremise",
|
||||
IssueType: "Bug",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
expectErr: true,
|
||||
},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
err := tc.in.sanitize(tc.againstVersion, logger)
|
||||
|
||||
8
pkg/alertmanager/testdata/jira_config_with_api_type.golden
generated
vendored
Normal file
8
pkg/alertmanager/testdata/jira_config_with_api_type.golden
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
receivers:
|
||||
- name: ""
|
||||
jira_configs:
|
||||
- api_url: http://issues.example.com
|
||||
project: Monitoring
|
||||
issue_type: Bug
|
||||
api_type: datacenter
|
||||
templates: []
|
||||
7
pkg/alertmanager/testdata/jira_config_with_api_type_version_not_supported.golden
generated
vendored
Normal file
7
pkg/alertmanager/testdata/jira_config_with_api_type_version_not_supported.golden
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
receivers:
|
||||
- name: ""
|
||||
jira_configs:
|
||||
- api_url: http://issues.example.com
|
||||
project: Monitoring
|
||||
issue_type: Bug
|
||||
templates: []
|
||||
@@ -448,6 +448,7 @@ type jiraConfig struct {
|
||||
WontFixResolution string `yaml:"wont_fix_resolution,omitempty"`
|
||||
ReopenDuration model.Duration `yaml:"reopen_duration,omitempty"`
|
||||
Fields map[string]any `yaml:"fields,omitempty"`
|
||||
APIType string `yaml:"api_type,omitempty"`
|
||||
}
|
||||
|
||||
type rocketchatAttachmentField struct {
|
||||
|
||||
Reference in New Issue
Block a user