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 all 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
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
1 change: 1 addition & 0 deletions website/docs/r/nrql_alert_condition.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ The `term` block supports the following arguments:
- `duration` - (Optional) **DEPRECATED:** Use `threshold_duration` instead. The duration of time, in _minutes_, that the threshold must violate for in order to create an incident. Must be within 1-120 (inclusive).
- `time_function` - (Optional) **DEPRECATED:** Use `threshold_occurrences` instead. The criteria for how many data points must be in violation for the specified threshold duration. Valid values are: `all` or `any`.
- `prediction` - (Optional) **BETA PREVIEW: the `prediction` field is in limited release and only enabled for preview on a per-account basis.** Use `prediction` to open alerts when your static threshold is predicted to be reached in the future. The `prediction` field is only available for _static_ NRQL alert conditions. See [Prediction](#prediction) below for details.
- `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.

~> **NOTE:** When a `critical` or `warning` block is added to this resource, using either `duration` or `threshold_duration` (one of the two) is mandatory. Both of these should not be specified.

Expand Down