You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

运行terraform apply创建New Relic NRQL告警条件报Validation Error

你的配置存在两处不符合New Relic API规则的问题:

  1. NRQL查询中手动添加了since时间限定
    New Relic NRQL告警条件的查询时间窗口由平台根据你配置的threshold_duration、evaluation_offset等参数自动计算,不允许在自定义查询语句中手动加since/until限定,你的since 1 month ago写法会触发API侧校验失败。
  2. 配置逻辑冲突
    你设置的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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.30 18:57:03