Hello again!
We're creating a large set of alert conditions, including ones which help us ensure that critical processes are running on our EC2 instances. We want to know when a process dies on a running instance, but avoid alerts when the whole instance starts shutting down.
We're using the newrelic_nrql_alert_condition resource, Terraform v0.12.29, and New Relic provider v2.3.0. For cross-reference, we have an open ticket with New Relic Support. The support agent directed us to NerdGraph API: Loss of signal and gap filling.
In my experience, applying the following configuration to an existing alert condition resolves the issue of alerts going off when an EC2 instance terminates:
"openViolationOnExpiration": false ← Do NOT open a new violation when the signal is lost
"closeViolationsOnExpiration": true ← Close lost signal violations when they expire
"expirationDuration": 1200 ← Amount of time, in seconds, before considering the signal as lost.
Here is a sample alert condition:
resource "newrelic_nrql_alert_condition" "cond_process_ecs_init" {
name = "TEST Name"
enabled = true
# Bind this condition to the following alert policy
policy_id = newrelic_alert_policy.ops.id
# Type of metric and where to read it from
type = "static"
value_function = "single_value"
# Query
nrql {
query = "FROM ProcessSample SELECT uniqueCount(entityAndPid) WHERE commandName = 'amazon-ecs-init' AND contained = 'false' AND label.BusinessService = '${local.tag_business_service}' AND ec2State = 'running' FACET ec2InstanceId LIMIT MAX"
since_value = "15" # Evaluation offset
}
# CRIT
critical {
operator = "below"
threshold = 1
threshold_occurrences = "all"
threshold_duration = 900
}
# Minutes until it auto-closes
violation_time_limit = "ONE_HOUR"
}
These settings can be applied to _existing_ alert conditions with the following request to the NerdGraph GraphQL API:
mutation {
alertsNrqlConditionStaticUpdate(
accountId: XXXXXXX
id: XXXXXXXX
condition: {
expiration: {
closeViolationsOnExpiration: true
expirationDuration: 1200
openViolationOnExpiration: false
}
}
) {
id
}
}
Expose the following attributes of the GraphQL mutation (above) via Terraform as read/write: openViolationOnExpiration, closeViolationsOnExpiration, expirationDuration. This would allow us to keep everything directly in Terraform without having to make additional ad-hoc mutation calls to the GraphQL API.
Hi @skyzyx, this was a very recent addition to the GraphQL schema for NRQL alert conditions. We have it on the radar :)
Great. Thank you!
Most helpful comment
Hi @skyzyx, this was a very recent addition to the GraphQL schema for NRQL alert conditions. We have it on the radar :)