菜单
开源

cri

注意

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

cri stage 是一个解析 stage,它使用标准的 CRI 日志格式读取日志行。

模式

yaml
cri:
  # Max buffer size to hold partial lines.
  [max_partial_lines: <int> | default = 100]

  # Max line size to hold a single partial line, if max_partial_line_size_truncate is true. Example: 262144.
  [max_partial_line_size: <int> | default = 0]

  # Allows to pretruncate partial lines before storing in partial buffer.
  [max_partial_line_size_truncate: <bool> | default = false]

与大多数 stage 不同,cri stage 不提供配置选项,仅支持特定的 CRI 日志格式。CRI 将日志行指定为以空格分隔的值,包含以下组件:

  1. time:日志的时间戳字符串
  2. stream:标准输出 (stdout) 或标准错误 (stderr)
  3. flags:包括 F 或 P 的 CRI 标志
  4. log:日志行的内容

组件之间不允许有空格。在以下示例中,只有第一行日志可以使用 cri stage 进行正确格式化:

"2019-01-01T01:00:00.000000001Z stderr P test\ngood"
"2019-01-01 T01:00:00.000000001Z stderr testgood"
"2019-01-01T01:00:00.000000001Z testgood"

示例

对于给定的 pipeline:

yaml
- cri: {}

给定以下日志行:

"2019-04-30T02:12:41.8443515Z stdout F message"

将在提取的数据集中创建以下键值对:

  • content: message
  • stream: stdout
  • flags: F
  • timestamp: 2019-04-30T02:12:41.8443515 - cri stage 既将时间戳提取为标签,也将其设置为日志条目的时间戳。