diff --git a/newrelic/data_source_newrelic_service_level_alert_helper.go b/newrelic/data_source_newrelic_service_level_alert_helper.go index da8564578..6a499e32e 100644 --- a/newrelic/data_source_newrelic_service_level_alert_helper.go +++ b/newrelic/data_source_newrelic_service_level_alert_helper.go @@ -96,7 +96,7 @@ func dataSourceNewRelicServiceLevelAlertHelperRead(ctx context.Context, d *schem return diag.Errorf("For 'fast_burn' alert type do not fill 'custom_evaluation_period' or 'custom_tolerated_budget_consumption', we use 60 minutes and 2%%.") } - if err := fillData(d, 60, 2); err != nil { + if err := fillData(d, 3600, 2); err != nil { return diag.FromErr(err) } @@ -105,7 +105,7 @@ func dataSourceNewRelicServiceLevelAlertHelperRead(ctx context.Context, d *schem return diag.Errorf("For 'slow_burn' alert type do not fill 'custom_evaluation_period' or 'custom_tolerated_budget_consumption', we use 360 minutes and 5%%.") } - if err := fillData(d, 360, 5); err != nil { + if err := fillData(d, 21600, 5); err != nil { return diag.FromErr(err) } @@ -154,5 +154,5 @@ func fillData(d *schema.ResourceData, evaluationPeriod int, toleratedBudgetConsu } func calculateThreshold(sloTarget float64, toleratedBudgetConsumption float64, sloPeriod int, evaluationPeriod int) float64 { - return (100.0 - sloTarget) * ((toleratedBudgetConsumption / 100 * float64(sloPeriod) * 24) / (float64(evaluationPeriod) / 60.0)) + return (100.0 - sloTarget) * ((toleratedBudgetConsumption / 100 * float64(sloPeriod) * 24) / (float64(evaluationPeriod) / 3600.0)) } diff --git a/newrelic/data_source_newrelic_service_level_alert_helper_integration_test.go b/newrelic/data_source_newrelic_service_level_alert_helper_integration_test.go index 406db7849..26f5b053a 100644 --- a/newrelic/data_source_newrelic_service_level_alert_helper_integration_test.go +++ b/newrelic/data_source_newrelic_service_level_alert_helper_integration_test.go @@ -243,7 +243,7 @@ func testAccCheckNewRelicServiceLevelAlertHelper_FastBurn(n string) resource.Tes "alert_type": "fast_burn", "custom_evaluation_period": "", "custom_tolerated_budget_consumption": "", - "evaluation_period": "60", + "evaluation_period": "3600", "tolerated_budget_consumption": "2", "threshold": "1.3439999999999237", "sli_guid": "sliGuid", @@ -279,7 +279,7 @@ func testAccCheckNewRelicServiceLevelAlertHelper_SlowBurn(n string) resource.Tes "alert_type": "slow_burn", "custom_evaluation_period": "", "custom_tolerated_budget_consumption": "", - "evaluation_period": "360", + "evaluation_period": "21600", "tolerated_budget_consumption": "5", "threshold": "0.5599999999999682", "sli_guid": "sliGuid", @@ -304,7 +304,7 @@ data "newrelic_service_level_alert_helper" "custom" { slo_target = 98 slo_period = 7 custom_tolerated_budget_consumption = 5 - custom_evaluation_period = 120 + custom_evaluation_period = 7200 } `) } @@ -326,9 +326,9 @@ func testAccCheckNewRelicServiceLevelAlertHelper_Custom(n string) resource.TestC "slo_period": "7", "slo_target": "98", "alert_type": "custom", - "custom_evaluation_period": "120", + "custom_evaluation_period": "7200", "custom_tolerated_budget_consumption": "5", - "evaluation_period": "120", + "evaluation_period": "7200", "tolerated_budget_consumption": "5", "threshold": "8.4", "sli_guid": "sliGuidCustom", @@ -353,7 +353,7 @@ data "newrelic_service_level_alert_helper" "custom" { slo_target = 98 slo_period = 7 custom_tolerated_budget_consumption = 5 - custom_evaluation_period = 120 + custom_evaluation_period = 7200 is_bad_events = true } `) @@ -376,9 +376,9 @@ func testAccCheckNewRelicServiceLevelAlertHelper_CustomBadEvents(n string) resou "slo_period": "7", "slo_target": "98", "alert_type": "custom", - "custom_evaluation_period": "120", + "custom_evaluation_period": "7200", "custom_tolerated_budget_consumption": "5", - "evaluation_period": "120", + "evaluation_period": "7200", "tolerated_budget_consumption": "5", "threshold": "8.4", "sli_guid": "sliGuidCustom", diff --git a/newrelic/data_source_newrelic_service_level_alert_helper_unit_test.go b/newrelic/data_source_newrelic_service_level_alert_helper_unit_test.go index 973ec10c4..e483d89ea 100644 --- a/newrelic/data_source_newrelic_service_level_alert_helper_unit_test.go +++ b/newrelic/data_source_newrelic_service_level_alert_helper_unit_test.go @@ -13,7 +13,7 @@ func TestCalculateAlertThreshold(t *testing.T) { var sloPeriod = 28 var sloTarget = 99.9 var toleratedBudgetConsumption = 2.0 - var evaluationPeriod = 60 + var evaluationPeriod = 3600 threshold := calculateThreshold(sloTarget, toleratedBudgetConsumption, sloPeriod, evaluationPeriod) diff --git a/website/docs/d/service_level_alert_helper.html.markdown b/website/docs/d/service_level_alert_helper.html.markdown index 0f2713946..ea39a607b 100644 --- a/website/docs/d/service_level_alert_helper.html.markdown +++ b/website/docs/d/service_level_alert_helper.html.markdown @@ -52,15 +52,55 @@ Then use the helper to obtain the necessary fields to set up an alert on that Se Note that the Service Level was set up using bad events, that's why `is_bad_events` is set to `true`. If the Service Level was configured with good events that would be unnecessary as the field defaults to `false`. +Here is an example of a `slow_burn` alert. + ```hcl +data "newrelic_service_level_alert_helper" "foo_slow_burn" { + alert_type = "slow_burn" + sli_guid = newrelic_service_level.foo.sli_guid + slo_target = local.foo_target + slo_period = local.foo_period + is_bad_events = true +} + +resource "newrelic_nrql_alert_condition" "your_condition" { + account_id = 12345678 + policy_id = 67890 + type = "static" + name = "Slow burn alert" + enabled = true + violation_time_limit_seconds = 259200 + + nrql { + query = data.newrelic_service_level_alert_helper.foo_slow_burn.nrql + } + + critical { + operator = "above_or_equals" + threshold = data.newrelic_service_level_alert_helper.foo_slow_burn.threshold + threshold_duration = 900 + threshold_occurrences = "at_least_once" + } + fill_option = "none" + aggregation_window = data.newrelic_service_level_alert_helper.foo_slow_burn.evaluation_period + aggregation_method = "event_flow" + aggregation_delay = 120 + slide_by = 900 +} +``` + +Here is an example of a custom alert: + + +```hcl data "newrelic_service_level_alert_helper" "foo_custom" { alert_type = "custom" sli_guid = newrelic_service_level.foo.sli_guid slo_target = local.foo_target slo_period = local.foo_period - custom_tolerated_budget_consumption = 5 - custom_evaluation_period = 90 + custom_tolerated_budget_consumption = 4 + custom_evaluation_period = 5400 is_bad_events = true } @@ -68,7 +108,7 @@ resource "newrelic_nrql_alert_condition" "your_condition" { account_id = 12345678 policy_id = 67890 type = "static" - name = "Successs (custom)" + name = "Custom burn alert" enabled = true violation_time_limit_seconds = 259200 @@ -79,11 +119,11 @@ resource "newrelic_nrql_alert_condition" "your_condition" { critical { operator = "above_or_equals" threshold = data.newrelic_service_level_alert_helper.foo_custom.threshold - threshold_duration = data.newrelic_service_level_alert_helper.foo_custom.evaluation_period + threshold_duration = 900 threshold_occurrences = "at_least_once" } fill_option = "none" - aggregation_window = 3600 + aggregation_window = data.newrelic_service_level_alert_helper.foo_custom.evaluation_period aggregation_method = "event_flow" aggregation_delay = 120 slide_by = 60 @@ -97,13 +137,13 @@ The following arguments are supported: * `alert_type` - (Required) The type of alert we want to set. Valid values are: * `custom` - Tolerated budget consumption and evaluation period have to be specified. - * `fast_burn` - Tolerated budget consumption is 2% and evaluation period is 60min. - * `slow_burn` - Tolerated budget consumption is 5% and evaluation period is 360min. + * `fast_burn` - Tolerated budget consumption is 2% and evaluation period is 1 hour (3600 seconds). + * `slow_burn` - Tolerated budget consumption is 5% and evaluation period is 6 hours (21600 seconds). * `sli_guid` - (Required) The guid of the sli we want to set the alert on. * `slo_target` - (Required) The target of the Service Level Objective, valid values between `0` and `100`. * `slo_period` - (Required) The time window of the Service Level Objective in days. Valid values are `1`, `7` and `28`. * `custom_tolerated_budget_consumption` - (Optional) How much budget you tolerate to consume during the custom evaluation period, valid values between `0` and `100`. Mandatory if `alert_type` is `custom`. - * `custom_evaluation_period` - (Optional) Aggregation window taken into consideration in minutes. Mandatory if `alert_type` is `custom`. + * `custom_evaluation_period` - (Optional) Aggregation window taken into consideration in seconds. Mandatory if `alert_type` is `custom`. * `is_bad_events` - (Optional) If the SLI is defined using bad events. Defaults to `false` ## Attributes Reference