prometheus / prometheus/client_python

OpenMetrics parser cannot parse the output of `promtool tsdb dump-openmetrics`

未关闭
#1,091 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

主要语言
Python
星标
4.4k
派生
876
平均合并
8 天 4 小时
30 天内合并 PR
1

描述

I tried using the example code...

import sys
from prometheus_client.openmetrics.parser import text_string_to_metric_families

for family in text_string_to_metric_families(sys.stdin.read()):
  for sample in family.samples:
      print("Name: {0} Labels: {1} Value: {2} Timestamp: {3}".format(*sample))

...to parse an OpenMetrics file produced by promtool tsdb dump-openmetrics, but I run into the following issue:

Traceback (most recent call last):
  File "/home/nicolas/IE6/synapse-meshsim/exp/./normalise_timestamps.py", line 6, in <module>
    for family in text_string_to_metric_families(sys.stdin.read()):
  File "/home/nicolas/IE6/synapse-meshsim/exp/venv/lib/python3.11/site-packages/prometheus_client/openmetrics/parser.py", line 18, in text_string_to_metric_families
    yield from text_fd_to_metric_families(StringIO.StringIO(text))
  File "/home/nicolas/IE6/synapse-meshsim/exp/venv/lib/python3.11/site-packages/prometheus_client/openmetrics/parser.py", line 543, in text_fd_to_metric_families
    yield build_metric(name, documentation, typ, unit, samples)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/nicolas/IE6/synapse-meshsim/exp/venv/lib/python3.11/site-packages/prometheus_client/openmetrics/parser.py", line 472, in build_metric
    raise ValueError("Clashing name: " + name + suffix)
ValueError: Clashing name: go_gc_duration_seconds

This comes from this code: https://github.com/prometheus/client_python/blob/46eae7bae88f76951f7246d9f359f2dd5eeff110/prometheus_client/openmetrics/parser.py#L487-L489

But I don't understand why this check exists in the first place? In my case, I have the same metrics for multiple instances, and dump-openmetrics groups them by instance, then by metrics name. Can't we just remove this check altogether?

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从链接的 build_metric 检查处开始查看 prometheus_client/openmetrics/parser.py,并将其假设与 promtool tsdb dump-openmetrics 的分组输出进行比较。使用示例 parser 代码和该输出重现失败。完成的标准是:定义 parser 对重复指标名称的行为,并解决已报告的名称冲突失败问题。

由索引模型根据 Issue 内容生成。

评估

技术栈
python
领域
observability-sre
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
38/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。