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

KEDA缩放时keda-operator-metrics-apiserver指标前缀异常的排查与解决

KEDA Prometheus触发器指标匹配失败问题排查与解决

原因分析

出现s0-prometheus-http_requests_in_progress找不到的错误,核心逻辑如下:

  1. KEDA会为每个ScaledObject的触发器生成唯一的内部指标名,格式为{ScaledObject短ID}-{触发器类型}-{配置的metricName},这里的s0是ScaledObject keda-so-prmts的短标识,因此生成的指标名是s0-prometheus-http_requests_in_progress。
  2. 错误本质是KEDA执行配置的PromQL查询后,未返回任何符合条件的指标数据,导致metrics-apiserver无法生成该带前缀的指标,进而抛出“找不到匹配指标”的提示。
  3. 结合你的配置,具体触发点大概率是:
    • PromQL中的exported_endpoint="api/FetchService/getData/{productId}"过滤条件过于严格,实际Prometheus指标中该标签值是具体的productId而非占位符,导致无匹配数据。
    • 触发器metadata中重复配置的namespace可能干扰KEDA的标签关联逻辑。

解决步骤

1. 先验证PromQL查询有效性

直接在Prometheus UI中执行以下查询,确认是否能返回数据:

sum(http_requests_in_progress{action="getData", container="abc-test-yy", controller="Fetching", endpoint="8080", exported_endpoint="api/FetchService/getData/{productId}", job="abc-test-yy", method="POST", namespace="mynamespace", service="abc-test-yy"})by(container)
  • 若无返回结果:
    • 修改exported_endpoint的匹配规则为正则匹配,适配具体的productId值:exported_endpoint=~"api/FetchService/getData/.*"。
    • 逐一核对其他标签(如controller、action)的拼写和值是否与Prometheus中的实际指标完全一致。

2. 调整ScaledObject配置

修改后的配置示例如下(移除冗余配置,优化查询条件):

apiVersion: keda.sh/v1alpha1
kind: ScaledObject
metadata:
  name: keda-so-prmts
  namespace: mynamespace
spec:
  scaleTargetRef:
    name: abc-test-yy
  pollingInterval:  10
  cooldownPeriod:   300
  minReplicaCount:  1
  maxReplicaCount:  10
  triggers:
  - type: prometheus
    metadata:
      serverAddress: http://10.1.254.12:9090
      metricName: http_requests_in_progress
      # 优化exported_endpoint的匹配规则,移除冗余的namespace配置
      query: sum(http_requests_in_progress{action="getData", container="abc-test-yy", controller="Fetching", endpoint="8080", exported_endpoint=~"api/FetchService/getData/.*", job="abc-test-yy", method="POST", namespace="mynamespace", service="abc-test-yy"})by(container)
      threshold: '1'

3. 验证配置生效

  • 重新应用ScaledObject:
    kubectl apply -f your-scaledobject.yaml -n mynamespace
    
  • 查看keda-operator-metrics-apiserver日志,确认错误消失。
  • 验证KEDA暴露的指标是否正常:
    kubectl get --raw "/apis/custom.metrics.k8s.io/v1beta1/namespaces/mynamespace/pods/*/s0-prometheus-http_requests_in_progress"
    
    若返回包含指标值的JSON数据,说明配置已生效,容器可正常触发弹性缩放。

内容的提问来源于stack exchange,提问作者Bishan Vithanage

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.20 03:05:23