Prometheus reads all .db files from PROMETHEUS_MULTIPROC_DIR without regard
还没有人认领这个 Issue。
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 48/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 停滞
- 技术栈
- python
调研方向
从 prometheus_client/multiprocess.py 中的 MultiProcessCollector.collect 开始,在复现报告的 prometheus-client 0.15.0 traceback 的同时,跟踪它对 merge 和 mmap_dict.py 的调用。确定应如何识别 PROMETHEUS_MULTIPROC_DIR 中的文件,然后验证无关或格式错误的 .db 文件不再导致收集过程读取无效数据,同时有效的 metric 文件仍能正常工作。
由索引模型根据 Issue 内容生成。
描述
prometheus-client==0.15.0
The method collect on prometheus_client.multiprocess.MultiProcessCollector reads all .db files, leading to memory issues, as it reads SQLite databases.
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/........./........../.............py", line 20, in .........................
data = generate_latest(registry)
File "/usr/lib/python3.8/site-packages/prometheus_client/exposition.py", line 198, in generate_latest
for metric in registry.collect():
File "/usr/lib/python3.8/site-packages/prometheus_client/registry.py", line 97, in collect
yield from collector.collect()
File "/usr/lib/python3.8/site-packages/prometheus_client/multiprocess.py", line 153, in collect
return self.merge(files, accumulate=True)
File "/usr/lib/python3.8/site-packages/prometheus_client/multiprocess.py", line 45, in merge
metrics = MultiProcessCollector._read_metrics(files)
File "/usr/lib/python3.8/site-packages/prometheus_client/multiprocess.py", line 73, in _read_metrics
for key, value, _ in file_values:
File "/usr/lib/python3.8/site-packages/prometheus_client/mmap_dict.py", line 43, in _read_all_values
value = _unpack_double(data, pos)[0]
struct.error: unpack_from requires a buffer of at least 1634562696 bytes for unpacking 8 bytes at offset 1634562688 (actual buffer size is 12288)
The issue is on collect() method:
def collect(self):
files = glob.glob(os.path.join(self._path, '*.db'))
return self.merge(files, accumulate=True)
I believe that there should be some kind of file validation to assure that the file is related to a prometheus metric, e.g:
import re
POSSIBLE_PROMETHEUS_FILENAMES_INCLUDE = {'counter', '...', 'histogram', 'gauge_livesum'}
def collect(self):
files = glob.glob(os.path.join(self._path, '*.db'))
#
# assert files
valid_files = [f for f in files if re.split('_\d+.db', f)[0] in POSSIBLE_PROMETHEUS_FILENAMES_INCLUDE]
#
#
return self.merge(valid_files, accumulate=True)
- 主要语言
- Python
- 星标
- 4.4k
- 派生
- 876
- 平均合并
- 8 天 4 小时
- 30 天内合并 PR
- 1
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
prometheus/client_python 的其他 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 70/100
prometheus/client_python#1177 · 1 条评论 ·
-
难度 4/5 3-5 天 新手友好度 45/100
prometheus/client_python#1210 ·
-
难度 2/5 1-3 小时 新手友好度 58/100
prometheus/client_python#1199 · 1 个 reaction ·
-
难度 5/5 一周以上 新手友好度 35/100
prometheus/client_python#1176 ·
-
难度 1/5 1-3 小时 新手友好度 52/100
prometheus/client_python#1126 · 2 条评论 ·
查看 prometheus/client_python 的全部 Issue
相似的 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 75/100
stephrobert/dsoxlab#238 ·
-
难度 2/5 1-3 小时 新手友好度 75/100
-
难度 2/5 1-3 小时 新手友好度 75/100
sublimehq/package_control#1780 ·
-
难度 2/5 1-3 小时 新手友好度 65/100
-
难度 2/5 1-3 小时 新手友好度 70/100
nwg-piotr/nwg-displays#145 ·