Skip to content

Commit dacf3dd

Browse files
author
Gabe Fuentes
committed
feat: Add disable_health_status_reporting field
1 parent 1a2be29 commit dacf3dd

5 files changed

+157
-78
lines changed

newrelic/resource_newrelic_nrql_alert_condition.go

+6
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,12 @@ func termSchema() *schema.Resource {
9898
},
9999
},
100100
},
101+
"disable_health_status_reporting": {
102+
Type: schema.TypeBool,
103+
Optional: true,
104+
Default: false,
105+
Description: "Violations will not change system health status for this term.",
106+
},
101107
},
102108
}
103109
}

newrelic/resource_newrelic_nrql_alert_condition_test.go

+55
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,28 @@ func TestAccNewRelicNrqlAlertCondition_StaticConditionPrediction(t *testing.T) {
612612
})
613613
}
614614

615+
func TestAccNewRelicNrqlAlertCondition_StaticConditionDisableHealthStatusReporting(t *testing.T) {
616+
resourceName := "newrelic_nrql_alert_condition.foo"
617+
rName := acctest.RandString(5)
618+
619+
resource.ParallelTest(t, resource.TestCase{
620+
PreCheck: func() { testAccPreCheckEnvVars(t) },
621+
Providers: testAccProviders,
622+
CheckDestroy: testAccCheckNewRelicNrqlAlertConditionDestroy,
623+
Steps: []resource.TestStep{
624+
// Test: Create
625+
{
626+
Config: testAccNewRelicNrqlAlertConditionStaticWithDisableHealthStatusReporting(
627+
rName,
628+
),
629+
Check: resource.ComposeTestCheckFunc(
630+
testAccCheckNewRelicNrqlAlertConditionExists(resourceName),
631+
),
632+
},
633+
},
634+
})
635+
}
636+
615637
func TestAccNewRelicNrqlAlertCondition_StaticConditionExpectedTermination(t *testing.T) {
616638
resourceName := "newrelic_nrql_alert_condition.foo"
617639
rName := acctest.RandString(5)
@@ -1423,3 +1445,36 @@ resource "newrelic_nrql_alert_condition" "foo" {
14231445
}
14241446
`, name, predictBy)
14251447
}
1448+
1449+
func testAccNewRelicNrqlAlertConditionStaticWithDisableHealthStatusReporting(
1450+
name string,
1451+
) string {
1452+
return fmt.Sprintf(`
1453+
resource "newrelic_alert_policy" "foo" {
1454+
name = "tf-test-%[1]s"
1455+
}
1456+
1457+
resource "newrelic_nrql_alert_condition" "foo" {
1458+
policy_id = newrelic_alert_policy.foo.id
1459+
1460+
name = "tf-test-%[1]s"
1461+
type = "static"
1462+
enabled = false
1463+
violation_time_limit_seconds = 3600
1464+
aggregation_delay = 120
1465+
aggregation_method = "event_flow"
1466+
1467+
nrql {
1468+
query = "SELECT uniqueCount(hostname) FROM ComputeSample"
1469+
}
1470+
1471+
critical {
1472+
operator = "below"
1473+
threshold = 0
1474+
threshold_duration = 120
1475+
threshold_occurrences = "ALL"
1476+
disable_health_status_reporting = true
1477+
}
1478+
}
1479+
`, name)
1480+
}

newrelic/structures_newrelic_nrql_alert_condition.go

+16-2
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,11 @@ func expandNrqlConditionTerm(term map[string]interface{}, conditionType, priorit
286286
ThresholdOccurrences: *thresholdOccurrences,
287287
}
288288

289+
if term["disable_health_status_reporting"] != nil {
290+
disableHealthStatusReporting := term["disable_health_status_reporting"].(bool)
291+
expandedTerm.DisableHealthStatusReporting = &disableHealthStatusReporting
292+
}
293+
289294
if conditionType == "baseline" {
290295
return &expandedTerm, nil
291296
}
@@ -781,6 +786,10 @@ func flattenNrqlTerms(terms []alerts.NrqlConditionTerm, configTerms []interface{
781786
dst["threshold_occurrences"] = strings.ToLower(string(term.ThresholdOccurrences))
782787
}
783788

789+
if term.DisableHealthStatusReporting != nil {
790+
dst["disable_health_status_reporting"] = term.DisableHealthStatusReporting
791+
}
792+
784793
out = append(out, dst)
785794
}
786795

@@ -808,6 +817,10 @@ func handleImportFlattenNrqlTerms(terms []alerts.NrqlConditionTerm) []map[string
808817
dst["prediction"] = []interface{}{predictionBlockContents}
809818
}
810819

820+
if term.DisableHealthStatusReporting != nil {
821+
dst["disable_health_status_reporting"] = term.DisableHealthStatusReporting
822+
}
823+
811824
out = append(out, dst)
812825
}
813826

@@ -828,8 +841,9 @@ func getConfiguredTerms(configTerms []interface{}) []map[string]interface{} {
828841
"time_function": t["time_function"],
829842

830843
// NerdGraph fields
831-
"threshold_duration": t["threshold_duration"],
832-
"threshold_occurrences": t["threshold_occurrences"],
844+
"threshold_duration": t["threshold_duration"],
845+
"threshold_occurrences": t["threshold_occurrences"],
846+
"disable_health_status_reporting": t["disable_health_status_reporting"],
833847
}
834848

835849
if t["prediction"] != nil {

newrelic/structures_newrelic_nrql_alert_condition_test.go

+14-11
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ import (
1717
)
1818

1919
var (
20-
testThresholdLow = 1.0
21-
testThresholdHigh = 10.9
20+
testThresholdLow = 1.0
21+
testThresholdHigh = 10.9
22+
testDisableHealthStatusReporting = true
2223
)
2324

2425
func TestExpandNrqlAlertConditionInput(t *testing.T) {
@@ -714,17 +715,19 @@ func TestExpandNrqlConditionTerm(t *testing.T) {
714715
Priority: "critical",
715716
ConditionType: "static",
716717
Term: map[string]interface{}{
717-
"threshold": 10.9,
718-
"threshold_duration": 5,
719-
"threshold_occurrences": "ALL",
720-
"operator": "equals",
718+
"threshold": 10.9,
719+
"threshold_duration": 5,
720+
"threshold_occurrences": "ALL",
721+
"operator": "equals",
722+
"disable_health_status_reporting": true,
721723
},
722724
Expected: &alerts.NrqlConditionTerm{
723-
Operator: alerts.AlertsNRQLConditionTermsOperator("EQUALS"),
724-
Priority: alerts.NrqlConditionPriority("CRITICAL"),
725-
Threshold: &testThresholdHigh,
726-
ThresholdDuration: 5,
727-
ThresholdOccurrences: "ALL",
725+
Operator: alerts.AlertsNRQLConditionTermsOperator("EQUALS"),
726+
Priority: alerts.NrqlConditionPriority("CRITICAL"),
727+
Threshold: &testThresholdHigh,
728+
ThresholdDuration: 5,
729+
ThresholdOccurrences: "ALL",
730+
DisableHealthStatusReporting: &testDisableHealthStatusReporting,
728731
},
729732
},
730733
"critical explicit priority": {

website/docs/r/alert_condition.html.markdown

+66-65
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ description: |-
66
Create and manage alert conditions for APM, Browser, and Mobile in New Relic.
77
---
88

9-
# Resource: newrelic\_alert\_condition
9+
# Resource: newrelic_alert_condition
1010

1111
Use this resource to create and manage alert conditions for APM, Browser, and Mobile in New Relic.
1212

@@ -49,63 +49,63 @@ resource "newrelic_alert_condition" "foo" {
4949

5050
The following arguments are supported:
5151

52-
* `policy_id` - (Required) The ID of the policy where this condition should be used.
53-
* `name` - (Required) The title of the condition. Must be between 1 and 64 characters, inclusive.
54-
* `type` - (Required) The type of condition. One of: `apm_app_metric`, `apm_jvm_metric`, `apm_kt_metric`, `browser_metric`, `mobile_metric`
55-
* `entities` - (Required) The instance IDs associated with this condition.
56-
* `metric` - (Required) The metric field accepts parameters based on the `type` set. One of these metrics based on `type`:
57-
* `apm_app_metric`
58-
* `apdex`
59-
* `error_percentage`
60-
* `response_time_background`
61-
* `response_time_web`
62-
* `throughput_background`
63-
* `throughput_web`
64-
* `user_defined`
65-
* `apm_jvm_metric`
66-
* `cpu_utilization_time`
67-
* `deadlocked_threads`
68-
* `gc_cpu_time`
69-
* `heap_memory_usage`
70-
* `apm_kt_metric`
71-
* `apdex`
72-
* `error_count`
73-
* `error_percentage`
74-
* `response_time`
75-
* `throughput`
76-
* `browser_metric`
77-
* `ajax_response_time`
78-
* `ajax_throughput`
79-
* `dom_processing`
80-
* `end_user_apdex`
81-
* `network`
82-
* `page_rendering`
83-
* `page_view_throughput`
84-
* `page_views_with_js_errors`
85-
* `request_queuing`
86-
* `total_page_load`
87-
* `user_defined`
88-
* `web_application`
89-
* `mobile_metric`
90-
* `database`
91-
* `images`
92-
* `json`
93-
* `mobile_crash_rate`
94-
* `network_error_percentage`
95-
* `network`
96-
* `status_error_percentage`
97-
* `user_defined`
98-
* `view_loading`
99-
* `condition_scope` - (Required for some types) `application` or `instance`. Choose `application` for most scenarios. If you are using the JVM plugin in New Relic, the `instance` setting allows your condition to trigger [for specific app instances](https://docs.newrelic.com/docs/alerts/new-relic-alerts/defining-conditions/scope-alert-thresholds-specific-instances).
100-
* `enabled` - (Optional) Whether the condition is enabled or not. Defaults to true.
101-
* `gc_metric` - (Optional) A valid Garbage Collection metric e.g. `GC/G1 Young Generation`.
102-
* `violation_close_timer` - (Optional) Automatically close instance-based incidents, including JVM health metric incidents, after the number of hours specified. Must be between 1 and 720 hours. Must be specified in the following two cases, to prevent drift:
103-
* when `type` = `apm_app_metric` and `condition_scope` = `instance`
104-
* when `type` = `apm_jvm_metric`
105-
* `runbook_url` - (Optional) Runbook URL to display in notifications.
106-
* `term` - (Required) A list of terms for this condition. See [Terms](#terms) below for details.
107-
* `user_defined_metric` - (Optional) A custom metric to be evaluated.
108-
* `user_defined_value_function` - (Optional) One of: `average`, `min`, `max`, `total`, `sample_size`, `rate` or `percent`.
52+
- `policy_id` - (Required) The ID of the policy where this condition should be used.
53+
- `name` - (Required) The title of the condition. Must be between 1 and 64 characters, inclusive.
54+
- `type` - (Required) The type of condition. One of: `apm_app_metric`, `apm_jvm_metric`, `apm_kt_metric`, `browser_metric`, `mobile_metric`
55+
- `entities` - (Required) The instance IDs associated with this condition.
56+
- `metric` - (Required) The metric field accepts parameters based on the `type` set. One of these metrics based on `type`:
57+
- `apm_app_metric`
58+
- `apdex`
59+
- `error_percentage`
60+
- `response_time_background`
61+
- `response_time_web`
62+
- `throughput_background`
63+
- `throughput_web`
64+
- `user_defined`
65+
- `apm_jvm_metric`
66+
- `cpu_utilization_time`
67+
- `deadlocked_threads`
68+
- `gc_cpu_time`
69+
- `heap_memory_usage`
70+
- `apm_kt_metric`
71+
- `apdex`
72+
- `error_count`
73+
- `error_percentage`
74+
- `response_time`
75+
- `throughput`
76+
- `browser_metric`
77+
- `ajax_response_time`
78+
- `ajax_throughput`
79+
- `dom_processing`
80+
- `end_user_apdex`
81+
- `network`
82+
- `page_rendering`
83+
- `page_view_throughput`
84+
- `page_views_with_js_errors`
85+
- `request_queuing`
86+
- `total_page_load`
87+
- `user_defined`
88+
- `web_application`
89+
- `mobile_metric`
90+
- `database`
91+
- `images`
92+
- `json`
93+
- `mobile_crash_rate`
94+
- `network_error_percentage`
95+
- `network`
96+
- `status_error_percentage`
97+
- `user_defined`
98+
- `view_loading`
99+
- `condition_scope` - (Required for some types) `application` or `instance`. Choose `application` for most scenarios. If you are using the JVM plugin in New Relic, the `instance` setting allows your condition to trigger [for specific app instances](https://docs.newrelic.com/docs/alerts/new-relic-alerts/defining-conditions/scope-alert-thresholds-specific-instances).
100+
- `enabled` - (Optional) Whether the condition is enabled or not. Defaults to true.
101+
- `gc_metric` - (Optional) A valid Garbage Collection metric e.g. `GC/G1 Young Generation`.
102+
- `violation_close_timer` - (Optional) Automatically close instance-based incidents, including JVM health metric incidents, after the number of hours specified. Must be between 1 and 720 hours. Must be specified in the following two cases, to prevent drift:
103+
- when `type` = `apm_app_metric` and `condition_scope` = `instance`
104+
- when `type` = `apm_jvm_metric`
105+
- `runbook_url` - (Optional) Runbook URL to display in notifications.
106+
- `term` - (Required) A list of terms for this condition. See [Terms](#terms) below for details.
107+
- `user_defined_metric` - (Optional) A custom metric to be evaluated.
108+
- `user_defined_value_function` - (Optional) One of: `average`, `min`, `max`, `total`, `sample_size`, `rate` or `percent`.
109109

110110
-> **NOTE:** The `user_defined_value_function` can have `rate` or `percent` only when the `type` is `mobile_metric`.
111111

@@ -117,18 +117,19 @@ Warning: This resource will use the account ID linked to your API key. At the mo
117117

118118
The `term` mapping supports the following arguments:
119119

120-
* `duration` - (Required) In minutes, must be in the range of `5` to `120`, inclusive.
121-
* `operator` - (Optional) `above`, `below`, or `equal`. Defaults to `equal`.
122-
* `priority` - (Optional) `critical` or `warning`. Defaults to `critical`. Terms must include at least one `critical` priority term
123-
* `threshold` - (Required) Must be 0 or greater.
124-
* `time_function` - (Required) `all` or `any`.
120+
- `duration` - (Required) In minutes, must be in the range of `5` to `120`, inclusive.
121+
- `operator` - (Optional) `above`, `below`, or `equal`. Defaults to `equal`.
122+
- `priority` - (Optional) `critical` or `warning`. Defaults to `critical`. Terms must include at least one `critical` priority term
123+
- `threshold` - (Required) Must be 0 or greater.
124+
- `time_function` - (Required) `all` or `any`.
125+
- `disable_health_status_reporting` - (Optional) `true` or `false`. Defaults to `false` when field not included in TF config. Violations will not change system health status for this term.
125126

126127
## Attributes Reference
127128

128129
In addition to all arguments above, the following attributes are exported:
129130

130-
* `id` - The ID of the alert condition.
131-
* `entity_guid` - The unique entity identifier of the condition in New Relic.
131+
- `id` - The ID of the alert condition.
132+
- `entity_guid` - The unique entity identifier of the condition in New Relic.
132133

133134
## Import
134135

0 commit comments

Comments
 (0)