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

GKE Config Connector配置告警策略时resource.type必填问题求助

问题:Config Connector配置告警策略时要求resource.type但Metrics UI和gcloud导出无此限制的矛盾

我通过Config Connector配置了告警策略资源,配置内容如下:

apiVersion: monitoring.cnrm.cloud.google.com/v1beta1
kind: MonitoringAlertPolicy
metadata:
  name: testing-bff-alert
  namespace: config-connector
spec:
  alertStrategy:
    autoClose: 604800s
  combiner: OR
  conditions:
    - conditionThreshold:
        aggregations:
          - alignmentPeriod: 120s
            crossSeriesReducer: REDUCE_MEAN
            perSeriesAligner: ALIGN_DELTA
        comparison: COMPARISON_GT
        duration: 0s
        filter: metric.type="logging.googleapis.com/user/bff-prod-response-times"
        thresholdValue: 50
        trigger:
          count: 1
      displayName: 'BFF Response Times [Mean]'
  displayName: 'BFF Response Times [Mean] above 0.8s'
  documentation:
    content: BFF Response times are too high
    mimeType: text/markdown
  enabled: true
  notificationChannels:
    - external: "projects/my-project/notificationChannels/17980363"
    - name: slack-notification
      namespace: config-connector

应用该配置时,服务器报错提示filter缺少resource.type限制,错误信息如下:

Update call failed: error applying desired state: summary: Error updating AlertPolicy "my-project projects/my-project/alertPolicies/65948650919": googleapi: Error 400: Field alert_policy.conditions[0].condition_threshold.filter had an invalid value of "metric.type="logging.googleapis.com/user/bff-prod-response-times"": must specify a restriction on "resource.type" in the filter; see "https://cloud.google.com/monitoring/api/resources" for a list of available resource types.

但在Metrics UI中,仅使用metric.type过滤即可正常工作,添加AND resource.type="metric"后图表无数据,说明该resource.type取值不正确。另外通过gcloud CLI导出的配置也仅包含metric.type字段。

请问这一矛盾情况的原因是什么?应如何修复?或者我应该使用哪个有效的resource.type取值?我已查阅相关资源列表文档,但未找到合适的取值。


原因分析

  • Metrics UI和gcloud导出的配置属于兼容简化模式:UI会自动补全resource.type参数,gcloud导出的是经过封装的简化配置,实际调用API时会隐式补充必要参数;而Config Connector直接调用Google Monitoring v3 API,该API对自定义日志指标(即logging.googleapis.com/user/开头的指标)的filter有强制要求,必须显式指定resource.type。
  • 你填入的resource.type="metric"是错误的,这类自定义指标的resource.type是其关联日志条目对应的资源类型,和通用的"metric"无关。

修复方案&正确resource.type获取方法

  1. 定位正确的resource.type
    • 方法一:打开Metrics UI中该指标的图表,点击右上角「查看MQL」,生成的MQL语句中会明确显示对应的resource.type(比如k8s_container、cloud_run_revision、global等,取决于你的BFF服务部署环境)。
    • 方法二:进入日志页面,搜索生成该指标的原始日志条目,查看日志详情中的「资源类型」字段,该值就是你需要的resource.type。
  2. 修改告警策略的filter
    • 将filter修改为metric.type="logging.googleapis.com/user/bff-prod-response-times" AND resource.type="你找到的正确类型",例如如果BFF部署在K8s容器中,filter应为:
      metric.type="logging.googleapis.com/user/bff-prod-response-times" AND resource.type="k8s_container"
      
  3. 验证配置
    • 修改后重新应用Config Connector配置,即可通过API校验;同时该filter在Metrics UI中也能正常展示数据。

内容的提问来源于stack exchange,提问作者Jty.tan

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.27 02:12:05