运行terraform apply创建New Relic NRQL告警条件报Validation Error
你的配置存在两处不符合New Relic API规则的问题:
- NRQL查询中手动添加了
since时间限定
New Relic NRQL告警条件的查询时间窗口由平台根据你配置的threshold_duration、evaluation_offset等参数自动计算,不允许在自定义查询语句中手动加since/until限定,你的since 1 month ago写法会触发API侧校验失败。 - 配置逻辑冲突
你设置的value_function = "single_value"要求每次查询仅返回单个数值结果,但NRQL中用了facet name按事务名称分组,会返回多组结果,二者规则不匹配。如果保留facet逻辑,查询中的limit 500也超出了告警场景最多支持50个facet值的限制,需要调整到50以内。
你可以根据业务需求选择对应修改方案:
方案1:按事务名称分别告警(保留facet逻辑)
resource "newrelic_nrql_alert_condition" "median_duration" { policy_id = newrelic_alert_policy.rpm_production_alert_policy.id name = "median_duration" description = "Alert when transactions are taking too long (this is a test description)" nrql { query = "SELECT median(duration) from Transaction where team = 'rpm' facet name limit 50" evaluation_offset = 3 } critical { operator = "above" threshold = 2 threshold_duration = 60 threshold_occurrences = "AT_LEAST_ONCE" } violation_time_limit_seconds = 3600 value_function = "sum" }
方案2:全局监控所有事务总中位数耗时(无分组)
resource "newrelic_nrql_alert_condition" "median_duration" { policy_id = newrelic_alert_policy.rpm_production_alert_policy.id name = "median_duration" description = "Alert when transactions are taking too long (this is a test description)" nrql { query = "SELECT median(duration) from Transaction where team = 'rpm'" evaluation_offset = 3 } critical { operator = "above" threshold = 2 threshold_duration = 60 threshold_occurrences = "AT_LEAST_ONCE" } violation_time_limit_seconds = 3600 value_function = "single_value" }
修改后重新执行terraform apply即可正常创建资源。
内容的提问来源于stack exchange,提问作者Richie Thomas
相关产品推荐
相关产品推荐

