菜单
开源

limit

注意

Promtail 已弃用,并将提供长期支持 (LTS) 至 2026 年 2 月 28 日。Promtail 将于 2026 年 3 月 2 日终止支持 (EOL)。您可以在此处找到迁移资源。

limit stage 是一个限速 stage,它根据多个选项对日志进行限制。

Limit Stage Schema

这个 Pipeline Stage 对 Promtail 推送到 Loki 的日志行的速率或突发数量设置限制。设置不同的突发和速率限制的概念与 Loki 分发器组件可以设置的限制方法相似:ingestion_rate_mbingestion_burst_size_mb,如limits_config 中所定义。

yaml
limit:
  # The rate limit in lines per second that Promtail will push to Loki
  [rate: <int>]

  # The cap in the quantity of burst lines that Promtail will push to Loki
  [burst: <int>]
   
  # Ratelimit each label value independently. If label is not found, log line is not
  # considered for ratelimiting. Drop must be true if this is set.
  [by_label_name: <string>]  
    
  # When ratelimiting by label is enabled, keep track of this many last used labels
  [max_distinct_labels: <int> | default = 10000]  

  # When drop is true, log lines that exceed the current rate limit will be discarded.
  # When drop is false, log lines that exceed the current rate limit will only wait
  # to enter the back pressure mode. 
  [drop: <bool> | default = false]

示例

以下示例展示了如何使用 limit stage。

limit

简单的 limit stage 配置。

匹配一行并限制

给定 Pipeline

yaml
- limit:
    rate: 10
    burst: 10

将限制任何日志行。

匹配一行并丢弃

给定 Pipeline

yaml
- limit:
    rate: 10
    burst: 10
    drop: true

将限制任何日志行,并在达到速率限制时丢弃日志。

按标签进行限速

给定 Pipeline

yaml
- limit:
    rate: 10
    burst: 10
    drop: true
    by_label_name: "namespace"

将独立地对来自每个命名空间的日志消息进行限速。任何没有 namespace 标签的消息将不受限速。