菜单
开源

labels

注意

Promtail 已被弃用,并通过长期支持 (LTS) 持续到 2026 年 2 月 28 日。Promtail 将于 2026 年 3 月 2 日终止生命周期 (EOL)。您可以在此处找到迁移资源。

labels 阶段是一个操作阶段,它从提取的映射中获取数据,并修改与日志条目一起发送到 Loki 的标签集。

模式

yaml
labels:
  # Key is REQUIRED and the name for the label that will be created.
  # Value is optional and will be the name from extracted data whose value
  # will be used for the value of the label. If empty, the value will be
  # inferred to be the same as the key.
  [ <string>: [<string>] ... ]

示例

对于给定的管道

yaml
- json:
    expressions:
      stream: stream
- labels:
    stream:

给定以下日志行

{"log":"log message\n","stream":"stderr","time":"2019-04-30T02:12:41.8443515Z"}

第一个阶段会将 stream 提取到提取的映射中,值为 stderr。labels 阶段会将该键值对转换为一个标签,因此发送到 Loki 的日志行将包含标签 stream,其值为 stderr