Skip to content

feat(alerts): Add silent alerts field to condition terms #2850

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions newrelic/data_source_newrelic_key_transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,11 @@ func dataSourceNewRelicKeyTransaction() *schema.Resource {
},
"domain": {
Type: schema.TypeString,
Required: false,
Computed: true,
Description: "The Domain of the key transaction in New Relic.",
},
"type": {
Type: schema.TypeString,
Required: false,
Computed: true,
Description: "The Entity type of the key transaction in New Relic.",
},
Expand Down
1 change: 0 additions & 1 deletion newrelic/resource_newrelic_group_management.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ func resourceNewRelicGroup() *schema.Resource {
Type: schema.TypeSet,
Description: "IDs of users to be added to the group.",
Optional: true,
Default: nil,
Elem: &schema.Schema{Type: schema.TypeString},
},
},
Expand Down
2 changes: 0 additions & 2 deletions newrelic/resource_newrelic_key_transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,11 @@ func resourceNewRelicKeyTransaction() *schema.Resource {
"domain": {
Type: schema.TypeString,
Description: "Domain of the entity.",
Required: false,
Computed: true,
},
"type": {
Type: schema.TypeString,
Description: "Type of the entity.",
Required: false,
Computed: true,
},
},
Expand Down
6 changes: 6 additions & 0 deletions newrelic/resource_newrelic_nrql_alert_condition.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ func termSchema() *schema.Resource {
},
},
},
"disable_health_status_reporting": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "Violations will not change system health status for this term.",
},
},
}
}
Expand Down
55 changes: 55 additions & 0 deletions newrelic/resource_newrelic_nrql_alert_condition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,28 @@ func TestAccNewRelicNrqlAlertCondition_StaticConditionPrediction(t *testing.T) {
})
}

func TestAccNewRelicNrqlAlertCondition_StaticConditionDisableHealthStatusReporting(t *testing.T) {
resourceName := "newrelic_nrql_alert_condition.foo"
rName := acctest.RandString(5)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheckEnvVars(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckNewRelicNrqlAlertConditionDestroy,
Steps: []resource.TestStep{
// Test: Create
{
Config: testAccNewRelicNrqlAlertConditionStaticWithDisableHealthStatusReporting(
rName,
),
Check: resource.ComposeTestCheckFunc(
testAccCheckNewRelicNrqlAlertConditionExists(resourceName),
),
},
},
})
}

func TestAccNewRelicNrqlAlertCondition_StaticConditionExpectedTermination(t *testing.T) {
resourceName := "newrelic_nrql_alert_condition.foo"
rName := acctest.RandString(5)
Expand Down Expand Up @@ -1423,3 +1445,36 @@ resource "newrelic_nrql_alert_condition" "foo" {
}
`, name, predictBy)
}

func testAccNewRelicNrqlAlertConditionStaticWithDisableHealthStatusReporting(
name string,
) string {
return fmt.Sprintf(`
resource "newrelic_alert_policy" "foo" {
name = "tf-test-%[1]s"
}

resource "newrelic_nrql_alert_condition" "foo" {
policy_id = newrelic_alert_policy.foo.id

name = "tf-test-%[1]s"
type = "static"
enabled = false
violation_time_limit_seconds = 3600
aggregation_delay = 120
aggregation_method = "event_flow"

nrql {
query = "SELECT uniqueCount(hostname) FROM ComputeSample"
}

critical {
operator = "below"
threshold = 0
threshold_duration = 120
threshold_occurrences = "ALL"
disable_health_status_reporting = true
}
}
`, name)
}
18 changes: 16 additions & 2 deletions newrelic/structures_newrelic_nrql_alert_condition.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,11 @@ func expandNrqlConditionTerm(term map[string]interface{}, conditionType, priorit
ThresholdOccurrences: *thresholdOccurrences,
}

if term["disable_health_status_reporting"] != nil {
disableHealthStatusReporting := term["disable_health_status_reporting"].(bool)
expandedTerm.DisableHealthStatusReporting = &disableHealthStatusReporting
}

if conditionType == "baseline" {
return &expandedTerm, nil
}
Expand Down Expand Up @@ -781,6 +786,10 @@ func flattenNrqlTerms(terms []alerts.NrqlConditionTerm, configTerms []interface{
dst["threshold_occurrences"] = strings.ToLower(string(term.ThresholdOccurrences))
}

if term.DisableHealthStatusReporting != nil {
dst["disable_health_status_reporting"] = term.DisableHealthStatusReporting
}

out = append(out, dst)
}

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

if term.DisableHealthStatusReporting != nil {
dst["disable_health_status_reporting"] = term.DisableHealthStatusReporting
}

out = append(out, dst)
}

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

// NerdGraph fields
"threshold_duration": t["threshold_duration"],
"threshold_occurrences": t["threshold_occurrences"],
"threshold_duration": t["threshold_duration"],
"threshold_occurrences": t["threshold_occurrences"],
"disable_health_status_reporting": t["disable_health_status_reporting"],
}

predictionSet := t["prediction"].(*schema.Set)
Expand Down
25 changes: 14 additions & 11 deletions newrelic/structures_newrelic_nrql_alert_condition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ import (
)

var (
testThresholdLow = 1.0
testThresholdHigh = 10.9
testThresholdLow = 1.0
testThresholdHigh = 10.9
testDisableHealthStatusReporting = true
)

func TestExpandNrqlAlertConditionInput(t *testing.T) {
Expand Down Expand Up @@ -714,17 +715,19 @@ func TestExpandNrqlConditionTerm(t *testing.T) {
Priority: "critical",
ConditionType: "static",
Term: map[string]interface{}{
"threshold": 10.9,
"threshold_duration": 5,
"threshold_occurrences": "ALL",
"operator": "equals",
"threshold": 10.9,
"threshold_duration": 5,
"threshold_occurrences": "ALL",
"operator": "equals",
"disable_health_status_reporting": true,
},
Expected: &alerts.NrqlConditionTerm{
Operator: alerts.AlertsNRQLConditionTermsOperator("EQUALS"),
Priority: alerts.NrqlConditionPriority("CRITICAL"),
Threshold: &testThresholdHigh,
ThresholdDuration: 5,
ThresholdOccurrences: "ALL",
Operator: alerts.AlertsNRQLConditionTermsOperator("EQUALS"),
Priority: alerts.NrqlConditionPriority("CRITICAL"),
Threshold: &testThresholdHigh,
ThresholdDuration: 5,
ThresholdOccurrences: "ALL",
DisableHealthStatusReporting: &testDisableHealthStatusReporting,
},
},
"critical explicit priority": {
Expand Down
131 changes: 66 additions & 65 deletions website/docs/r/alert_condition.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ description: |-
Create and manage alert conditions for APM, Browser, and Mobile in New Relic.
---

# Resource: newrelic\_alert\_condition
# Resource: newrelic_alert_condition

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

Expand Down Expand Up @@ -49,63 +49,63 @@ resource "newrelic_alert_condition" "foo" {

The following arguments are supported:

* `policy_id` - (Required) The ID of the policy where this condition should be used.
* `name` - (Required) The title of the condition. Must be between 1 and 64 characters, inclusive.
* `type` - (Required) The type of condition. One of: `apm_app_metric`, `apm_jvm_metric`, `apm_kt_metric`, `browser_metric`, `mobile_metric`
* `entities` - (Required) The instance IDs associated with this condition.
* `metric` - (Required) The metric field accepts parameters based on the `type` set. One of these metrics based on `type`:
* `apm_app_metric`
* `apdex`
* `error_percentage`
* `response_time_background`
* `response_time_web`
* `throughput_background`
* `throughput_web`
* `user_defined`
* `apm_jvm_metric`
* `cpu_utilization_time`
* `deadlocked_threads`
* `gc_cpu_time`
* `heap_memory_usage`
* `apm_kt_metric`
* `apdex`
* `error_count`
* `error_percentage`
* `response_time`
* `throughput`
* `browser_metric`
* `ajax_response_time`
* `ajax_throughput`
* `dom_processing`
* `end_user_apdex`
* `network`
* `page_rendering`
* `page_view_throughput`
* `page_views_with_js_errors`
* `request_queuing`
* `total_page_load`
* `user_defined`
* `web_application`
* `mobile_metric`
* `database`
* `images`
* `json`
* `mobile_crash_rate`
* `network_error_percentage`
* `network`
* `status_error_percentage`
* `user_defined`
* `view_loading`
* `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).
* `enabled` - (Optional) Whether the condition is enabled or not. Defaults to true.
* `gc_metric` - (Optional) A valid Garbage Collection metric e.g. `GC/G1 Young Generation`.
* `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:
* when `type` = `apm_app_metric` and `condition_scope` = `instance`
* when `type` = `apm_jvm_metric`
* `runbook_url` - (Optional) Runbook URL to display in notifications.
* `term` - (Required) A list of terms for this condition. See [Terms](#terms) below for details.
* `user_defined_metric` - (Optional) A custom metric to be evaluated.
* `user_defined_value_function` - (Optional) One of: `average`, `min`, `max`, `total`, `sample_size`, `rate` or `percent`.
- `policy_id` - (Required) The ID of the policy where this condition should be used.
- `name` - (Required) The title of the condition. Must be between 1 and 64 characters, inclusive.
- `type` - (Required) The type of condition. One of: `apm_app_metric`, `apm_jvm_metric`, `apm_kt_metric`, `browser_metric`, `mobile_metric`
- `entities` - (Required) The instance IDs associated with this condition.
- `metric` - (Required) The metric field accepts parameters based on the `type` set. One of these metrics based on `type`:
- `apm_app_metric`
- `apdex`
- `error_percentage`
- `response_time_background`
- `response_time_web`
- `throughput_background`
- `throughput_web`
- `user_defined`
- `apm_jvm_metric`
- `cpu_utilization_time`
- `deadlocked_threads`
- `gc_cpu_time`
- `heap_memory_usage`
- `apm_kt_metric`
- `apdex`
- `error_count`
- `error_percentage`
- `response_time`
- `throughput`
- `browser_metric`
- `ajax_response_time`
- `ajax_throughput`
- `dom_processing`
- `end_user_apdex`
- `network`
- `page_rendering`
- `page_view_throughput`
- `page_views_with_js_errors`
- `request_queuing`
- `total_page_load`
- `user_defined`
- `web_application`
- `mobile_metric`
- `database`
- `images`
- `json`
- `mobile_crash_rate`
- `network_error_percentage`
- `network`
- `status_error_percentage`
- `user_defined`
- `view_loading`
- `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).
- `enabled` - (Optional) Whether the condition is enabled or not. Defaults to true.
- `gc_metric` - (Optional) A valid Garbage Collection metric e.g. `GC/G1 Young Generation`.
- `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:
- when `type` = `apm_app_metric` and `condition_scope` = `instance`
- when `type` = `apm_jvm_metric`
- `runbook_url` - (Optional) Runbook URL to display in notifications.
- `term` - (Required) A list of terms for this condition. See [Terms](#terms) below for details.
- `user_defined_metric` - (Optional) A custom metric to be evaluated.
- `user_defined_value_function` - (Optional) One of: `average`, `min`, `max`, `total`, `sample_size`, `rate` or `percent`.

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

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

The `term` mapping supports the following arguments:

* `duration` - (Required) In minutes, must be in the range of `5` to `120`, inclusive.
* `operator` - (Optional) `above`, `below`, or `equal`. Defaults to `equal`.
* `priority` - (Optional) `critical` or `warning`. Defaults to `critical`. Terms must include at least one `critical` priority term
* `threshold` - (Required) Must be 0 or greater.
* `time_function` - (Required) `all` or `any`.
- `duration` - (Required) In minutes, must be in the range of `5` to `120`, inclusive.
- `operator` - (Optional) `above`, `below`, or `equal`. Defaults to `equal`.
- `priority` - (Optional) `critical` or `warning`. Defaults to `critical`. Terms must include at least one `critical` priority term
- `threshold` - (Required) Must be 0 or greater.
- `time_function` - (Required) `all` or `any`.
- `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.

## Attributes Reference

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

* `id` - The ID of the alert condition.
* `entity_guid` - The unique entity identifier of the condition in New Relic.
- `id` - The ID of the alert condition.
- `entity_guid` - The unique entity identifier of the condition in New Relic.

## Import

Expand Down