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

Closed
wants to merge 4 commits into from
Closed
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 @@ -1494,3 +1516,36 @@ resource "newrelic_nrql_alert_condition" "foo" {

`, name, signalSeasonality)
}

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 @@ -311,6 +311,11 @@
ThresholdOccurrences: *thresholdOccurrences,
}

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

Check failure on line 316 in newrelic/structures_newrelic_nrql_alert_condition.go

View workflow job for this annotation

GitHub Actions / compile (ubuntu-latest)

expandedTerm.DisableHealthStatusReporting undefined (type alerts.NrqlConditionTerm has no field or method DisableHealthStatusReporting)

Check failure on line 316 in newrelic/structures_newrelic_nrql_alert_condition.go

View workflow job for this annotation

GitHub Actions / compile (macos-latest)

expandedTerm.DisableHealthStatusReporting undefined (type alerts.NrqlConditionTerm has no field or method DisableHealthStatusReporting)

Check failure on line 316 in newrelic/structures_newrelic_nrql_alert_condition.go

View workflow job for this annotation

GitHub Actions / test-unit

expandedTerm.DisableHealthStatusReporting undefined (type alerts.NrqlConditionTerm has no field or method DisableHealthStatusReporting)

Check failure on line 316 in newrelic/structures_newrelic_nrql_alert_condition.go

View workflow job for this annotation

GitHub Actions / test-unit

expandedTerm.DisableHealthStatusReporting undefined (type alerts.NrqlConditionTerm has no field or method DisableHealthStatusReporting)

Check failure on line 316 in newrelic/structures_newrelic_nrql_alert_condition.go

View workflow job for this annotation

GitHub Actions / test-integration

expandedTerm.DisableHealthStatusReporting undefined (type alerts.NrqlConditionTerm has no field or method DisableHealthStatusReporting)

Check failure on line 316 in newrelic/structures_newrelic_nrql_alert_condition.go

View workflow job for this annotation

GitHub Actions / test-integration

expandedTerm.DisableHealthStatusReporting undefined (type alerts.NrqlConditionTerm has no field or method DisableHealthStatusReporting)

Check failure on line 316 in newrelic/structures_newrelic_nrql_alert_condition.go

View workflow job for this annotation

GitHub Actions / test-integration

expandedTerm.DisableHealthStatusReporting undefined (type alerts.NrqlConditionTerm has no field or method DisableHealthStatusReporting)

Check failure on line 316 in newrelic/structures_newrelic_nrql_alert_condition.go

View workflow job for this annotation

GitHub Actions / test-integration

expandedTerm.DisableHealthStatusReporting undefined (type alerts.NrqlConditionTerm has no field or method DisableHealthStatusReporting)

Check failure on line 316 in newrelic/structures_newrelic_nrql_alert_condition.go

View workflow job for this annotation

GitHub Actions / lint

expandedTerm.DisableHealthStatusReporting undefined (type alerts.NrqlConditionTerm has no field or method DisableHealthStatusReporting)

Check failure on line 316 in newrelic/structures_newrelic_nrql_alert_condition.go

View workflow job for this annotation

GitHub Actions / lint

expandedTerm.DisableHealthStatusReporting undefined (type alerts.NrqlConditionTerm has no field or method DisableHealthStatusReporting)
}

if conditionType == "baseline" {
return &expandedTerm, nil
}
Expand Down Expand Up @@ -810,6 +815,10 @@
dst["threshold_occurrences"] = strings.ToLower(string(term.ThresholdOccurrences))
}

if term.DisableHealthStatusReporting != nil {

Check failure on line 818 in newrelic/structures_newrelic_nrql_alert_condition.go

View workflow job for this annotation

GitHub Actions / compile (ubuntu-latest)

term.DisableHealthStatusReporting undefined (type alerts.NrqlConditionTerm has no field or method DisableHealthStatusReporting)

Check failure on line 818 in newrelic/structures_newrelic_nrql_alert_condition.go

View workflow job for this annotation

GitHub Actions / compile (macos-latest)

term.DisableHealthStatusReporting undefined (type alerts.NrqlConditionTerm has no field or method DisableHealthStatusReporting)

Check failure on line 818 in newrelic/structures_newrelic_nrql_alert_condition.go

View workflow job for this annotation

GitHub Actions / test-unit

term.DisableHealthStatusReporting undefined (type alerts.NrqlConditionTerm has no field or method DisableHealthStatusReporting)

Check failure on line 818 in newrelic/structures_newrelic_nrql_alert_condition.go

View workflow job for this annotation

GitHub Actions / test-unit

term.DisableHealthStatusReporting undefined (type alerts.NrqlConditionTerm has no field or method DisableHealthStatusReporting)

Check failure on line 818 in newrelic/structures_newrelic_nrql_alert_condition.go

View workflow job for this annotation

GitHub Actions / test-integration

term.DisableHealthStatusReporting undefined (type alerts.NrqlConditionTerm has no field or method DisableHealthStatusReporting)

Check failure on line 818 in newrelic/structures_newrelic_nrql_alert_condition.go

View workflow job for this annotation

GitHub Actions / test-integration

term.DisableHealthStatusReporting undefined (type alerts.NrqlConditionTerm has no field or method DisableHealthStatusReporting)

Check failure on line 818 in newrelic/structures_newrelic_nrql_alert_condition.go

View workflow job for this annotation

GitHub Actions / test-integration

term.DisableHealthStatusReporting undefined (type alerts.NrqlConditionTerm has no field or method DisableHealthStatusReporting)

Check failure on line 818 in newrelic/structures_newrelic_nrql_alert_condition.go

View workflow job for this annotation

GitHub Actions / test-integration

term.DisableHealthStatusReporting undefined (type alerts.NrqlConditionTerm has no field or method DisableHealthStatusReporting)

Check failure on line 818 in newrelic/structures_newrelic_nrql_alert_condition.go

View workflow job for this annotation

GitHub Actions / lint

term.DisableHealthStatusReporting undefined (type alerts.NrqlConditionTerm has no field or method DisableHealthStatusReporting)

Check failure on line 818 in newrelic/structures_newrelic_nrql_alert_condition.go

View workflow job for this annotation

GitHub Actions / lint

term.DisableHealthStatusReporting undefined (type alerts.NrqlConditionTerm has no field or method DisableHealthStatusReporting)
dst["disable_health_status_reporting"] = term.DisableHealthStatusReporting

Check failure on line 819 in newrelic/structures_newrelic_nrql_alert_condition.go

View workflow job for this annotation

GitHub Actions / compile (ubuntu-latest)

term.DisableHealthStatusReporting undefined (type alerts.NrqlConditionTerm has no field or method DisableHealthStatusReporting)

Check failure on line 819 in newrelic/structures_newrelic_nrql_alert_condition.go

View workflow job for this annotation

GitHub Actions / compile (macos-latest)

term.DisableHealthStatusReporting undefined (type alerts.NrqlConditionTerm has no field or method DisableHealthStatusReporting)

Check failure on line 819 in newrelic/structures_newrelic_nrql_alert_condition.go

View workflow job for this annotation

GitHub Actions / test-unit

term.DisableHealthStatusReporting undefined (type alerts.NrqlConditionTerm has no field or method DisableHealthStatusReporting)

Check failure on line 819 in newrelic/structures_newrelic_nrql_alert_condition.go

View workflow job for this annotation

GitHub Actions / test-unit

term.DisableHealthStatusReporting undefined (type alerts.NrqlConditionTerm has no field or method DisableHealthStatusReporting)

Check failure on line 819 in newrelic/structures_newrelic_nrql_alert_condition.go

View workflow job for this annotation

GitHub Actions / test-integration

term.DisableHealthStatusReporting undefined (type alerts.NrqlConditionTerm has no field or method DisableHealthStatusReporting)

Check failure on line 819 in newrelic/structures_newrelic_nrql_alert_condition.go

View workflow job for this annotation

GitHub Actions / test-integration

term.DisableHealthStatusReporting undefined (type alerts.NrqlConditionTerm has no field or method DisableHealthStatusReporting)

Check failure on line 819 in newrelic/structures_newrelic_nrql_alert_condition.go

View workflow job for this annotation

GitHub Actions / test-integration

term.DisableHealthStatusReporting undefined (type alerts.NrqlConditionTerm has no field or method DisableHealthStatusReporting)

Check failure on line 819 in newrelic/structures_newrelic_nrql_alert_condition.go

View workflow job for this annotation

GitHub Actions / test-integration

term.DisableHealthStatusReporting undefined (type alerts.NrqlConditionTerm has no field or method DisableHealthStatusReporting)

Check failure on line 819 in newrelic/structures_newrelic_nrql_alert_condition.go

View workflow job for this annotation

GitHub Actions / lint

term.DisableHealthStatusReporting undefined (type alerts.NrqlConditionTerm has no field or method DisableHealthStatusReporting)

Check failure on line 819 in newrelic/structures_newrelic_nrql_alert_condition.go

View workflow job for this annotation

GitHub Actions / lint

term.DisableHealthStatusReporting undefined (type alerts.NrqlConditionTerm has no field or method DisableHealthStatusReporting)
}

out = append(out, dst)
}

Expand Down Expand Up @@ -837,6 +846,10 @@
dst["prediction"] = []interface{}{predictionBlockContents}
}

if term.DisableHealthStatusReporting != nil {

Check failure on line 849 in newrelic/structures_newrelic_nrql_alert_condition.go

View workflow job for this annotation

GitHub Actions / compile (ubuntu-latest)

term.DisableHealthStatusReporting undefined (type alerts.NrqlConditionTerm has no field or method DisableHealthStatusReporting)

Check failure on line 849 in newrelic/structures_newrelic_nrql_alert_condition.go

View workflow job for this annotation

GitHub Actions / compile (macos-latest)

term.DisableHealthStatusReporting undefined (type alerts.NrqlConditionTerm has no field or method DisableHealthStatusReporting)

Check failure on line 849 in newrelic/structures_newrelic_nrql_alert_condition.go

View workflow job for this annotation

GitHub Actions / test-unit

term.DisableHealthStatusReporting undefined (type alerts.NrqlConditionTerm has no field or method DisableHealthStatusReporting)

Check failure on line 849 in newrelic/structures_newrelic_nrql_alert_condition.go

View workflow job for this annotation

GitHub Actions / test-unit

term.DisableHealthStatusReporting undefined (type alerts.NrqlConditionTerm has no field or method DisableHealthStatusReporting)

Check failure on line 849 in newrelic/structures_newrelic_nrql_alert_condition.go

View workflow job for this annotation

GitHub Actions / test-integration

term.DisableHealthStatusReporting undefined (type alerts.NrqlConditionTerm has no field or method DisableHealthStatusReporting)

Check failure on line 849 in newrelic/structures_newrelic_nrql_alert_condition.go

View workflow job for this annotation

GitHub Actions / test-integration

term.DisableHealthStatusReporting undefined (type alerts.NrqlConditionTerm has no field or method DisableHealthStatusReporting)

Check failure on line 849 in newrelic/structures_newrelic_nrql_alert_condition.go

View workflow job for this annotation

GitHub Actions / test-integration

term.DisableHealthStatusReporting undefined (type alerts.NrqlConditionTerm has no field or method DisableHealthStatusReporting)

Check failure on line 849 in newrelic/structures_newrelic_nrql_alert_condition.go

View workflow job for this annotation

GitHub Actions / test-integration

term.DisableHealthStatusReporting undefined (type alerts.NrqlConditionTerm has no field or method DisableHealthStatusReporting)

Check failure on line 849 in newrelic/structures_newrelic_nrql_alert_condition.go

View workflow job for this annotation

GitHub Actions / lint

term.DisableHealthStatusReporting undefined (type alerts.NrqlConditionTerm has no field or method DisableHealthStatusReporting)

Check failure on line 849 in newrelic/structures_newrelic_nrql_alert_condition.go

View workflow job for this annotation

GitHub Actions / lint

term.DisableHealthStatusReporting undefined (type alerts.NrqlConditionTerm has no field or method DisableHealthStatusReporting)
dst["disable_health_status_reporting"] = term.DisableHealthStatusReporting

Check failure on line 850 in newrelic/structures_newrelic_nrql_alert_condition.go

View workflow job for this annotation

GitHub Actions / compile (ubuntu-latest)

term.DisableHealthStatusReporting undefined (type alerts.NrqlConditionTerm has no field or method DisableHealthStatusReporting)

Check failure on line 850 in newrelic/structures_newrelic_nrql_alert_condition.go

View workflow job for this annotation

GitHub Actions / compile (macos-latest)

term.DisableHealthStatusReporting undefined (type alerts.NrqlConditionTerm has no field or method DisableHealthStatusReporting)

Check failure on line 850 in newrelic/structures_newrelic_nrql_alert_condition.go

View workflow job for this annotation

GitHub Actions / test-unit

term.DisableHealthStatusReporting undefined (type alerts.NrqlConditionTerm has no field or method DisableHealthStatusReporting)

Check failure on line 850 in newrelic/structures_newrelic_nrql_alert_condition.go

View workflow job for this annotation

GitHub Actions / test-unit

term.DisableHealthStatusReporting undefined (type alerts.NrqlConditionTerm has no field or method DisableHealthStatusReporting)

Check failure on line 850 in newrelic/structures_newrelic_nrql_alert_condition.go

View workflow job for this annotation

GitHub Actions / test-integration

term.DisableHealthStatusReporting undefined (type alerts.NrqlConditionTerm has no field or method DisableHealthStatusReporting)

Check failure on line 850 in newrelic/structures_newrelic_nrql_alert_condition.go

View workflow job for this annotation

GitHub Actions / test-integration

term.DisableHealthStatusReporting undefined (type alerts.NrqlConditionTerm has no field or method DisableHealthStatusReporting)

Check failure on line 850 in newrelic/structures_newrelic_nrql_alert_condition.go

View workflow job for this annotation

GitHub Actions / test-integration

term.DisableHealthStatusReporting undefined (type alerts.NrqlConditionTerm has no field or method DisableHealthStatusReporting)

Check failure on line 850 in newrelic/structures_newrelic_nrql_alert_condition.go

View workflow job for this annotation

GitHub Actions / test-integration

term.DisableHealthStatusReporting undefined (type alerts.NrqlConditionTerm has no field or method DisableHealthStatusReporting)

Check failure on line 850 in newrelic/structures_newrelic_nrql_alert_condition.go

View workflow job for this annotation

GitHub Actions / lint

term.DisableHealthStatusReporting undefined (type alerts.NrqlConditionTerm has no field or method DisableHealthStatusReporting)) (typecheck)
}

out = append(out, dst)
}

Expand All @@ -857,8 +870,9 @@
"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 @@ -737,17 +738,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 @@ -130,6 +130,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
Loading