Skip to content

Commit

Permalink
Add support for severity options in AlertPolicy (#9544)
Browse files Browse the repository at this point in the history
* Add support for severity options in AlertPolicy

* Update description for severity options

* Add update test for severity options

* Format go changes

---------

Co-authored-by: James Edouard <[email protected]>
  • Loading branch information
jedouard1994 and James Edouard authored Dec 11, 2023
1 parent c2f6cc6 commit 42bac03
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
10 changes: 10 additions & 0 deletions mmv1/products/monitoring/AlertPolicy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -957,6 +957,16 @@ properties:
to 63 Unicode characters or 128 bytes, whichever is smaller. Labels and values
can contain only lowercase letters, numerals, underscores, and dashes. Keys
must begin with a letter.
- !ruby/object:Api::Type::Enum
name: severity
description: |
The severity of an alert policy indicates how important incidents generated
by that policy are. The severity level will be displayed on the Incident
detail page and in notifications.
values:
- :CRITICAL
- :ERROR
- :WARNING
- !ruby/object:Api::Type::NestedObject
name: documentation
description: |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func testAccMonitoringAlertPolicy_basic(t *testing.T) {
CheckDestroy: testAccCheckAlertPolicyDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccMonitoringAlertPolicy_basicCfg(alertName, conditionName, "ALIGN_RATE", filter),
Config: testAccMonitoringAlertPolicy_basicCfg(alertName, conditionName, "ALIGN_RATE", filter, "WARNING"),
},
{
ResourceName: "google_monitoring_alert_policy.basic",
Expand All @@ -65,24 +65,26 @@ func testAccMonitoringAlertPolicy_update(t *testing.T) {
conditionName := fmt.Sprintf("tf-test-%s", acctest.RandString(t, 10))
filter1 := `metric.type=\"compute.googleapis.com/instance/disk/write_bytes_count\" AND resource.type=\"gce_instance\"`
aligner1 := "ALIGN_RATE"
severity1 := "WARNING"
filter2 := `metric.type=\"compute.googleapis.com/instance/cpu/utilization\" AND resource.type=\"gce_instance\"`
aligner2 := "ALIGN_MAX"
severity2 := "ERROR"

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckAlertPolicyDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccMonitoringAlertPolicy_basicCfg(alertName, conditionName, aligner1, filter1),
Config: testAccMonitoringAlertPolicy_basicCfg(alertName, conditionName, aligner1, filter1, severity1),
},
{
ResourceName: "google_monitoring_alert_policy.basic",
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccMonitoringAlertPolicy_basicCfg(alertName, conditionName, aligner2, filter2),
Config: testAccMonitoringAlertPolicy_basicCfg(alertName, conditionName, aligner2, filter2, severity2),
},
{
ResourceName: "google_monitoring_alert_policy.basic",
Expand Down Expand Up @@ -233,7 +235,7 @@ func testAccMonitoringAlertPolicy_promql(t *testing.T) {
})
}

func testAccMonitoringAlertPolicy_basicCfg(alertName, conditionName, aligner, filter string) string {
func testAccMonitoringAlertPolicy_basicCfg(alertName, conditionName, aligner, filter, severity string) string {
return fmt.Sprintf(`
resource "google_monitoring_alert_policy" "basic" {
display_name = "%s"
Expand All @@ -255,8 +257,10 @@ resource "google_monitoring_alert_policy" "basic" {
threshold_value = "0.5"
}
}
severity = "%s"
}
`, alertName, conditionName, aligner, filter)
`, alertName, conditionName, aligner, filter, severity)
}

func testAccMonitoringAlertPolicy_fullCfg(alertName, conditionName1, conditionName2 string) string {
Expand Down Expand Up @@ -319,6 +323,8 @@ resource "google_monitoring_alert_policy" "full" {
}
}
severity = "WARNING"
documentation {
content = "test content"
mime_type = "text/markdown"
Expand Down Expand Up @@ -348,6 +354,8 @@ resource "google_monitoring_alert_policy" "mql" {
}
}
severity = "WARNING"
documentation {
content = "test content"
mime_type = "text/markdown"
Expand Down Expand Up @@ -382,6 +390,8 @@ resource "google_monitoring_alert_policy" "log" {
auto_close = "2000s"
}
severity = "WARNING"
documentation {
content = "test content"
mime_type = "text/markdown"
Expand Down Expand Up @@ -441,6 +451,8 @@ resource "google_monitoring_alert_policy" "promql" {
}
}
severity = "WARNING"
documentation {
content = "test content"
mime_type = "text/markdown"
Expand Down

0 comments on commit 42bac03

Please sign in to comment.