prometheus / prometheus/client_python
labels method lead to memory leak
未关闭
还没有人认领这个 Issue。
bug
- 主要语言
- Python
- 星标
- 4.4k
- 派生
- 876
- 平均合并
- 8 天 4 小时
- 30 天内合并 PR
- 1
描述
I find metrics in my celery task will lead to memory leak. And I reproduced this problem issue locally.
import tracemalloc
from prometheus_client import Counter
counter_a = Counter('request_count_a', 'request count to a', ['name'])
counter_b = Counter('request_count_b', 'request count to b')
tracemalloc.start()
for _ in range(10):
counter_a.labels('a').inc()
curr_mem, peak_mem = tracemalloc.get_traced_memory()
print(f"curr mem: {curr_mem / 10**3} Kb, peak mem: {peak_mem / 10**3} Kb")
print("*****************************************")
for _ in range(10):
counter_b.inc()
curr_mem, peak_mem = tracemalloc.get_traced_memory()
print(f"curr mem: {curr_mem / 10 ** 3} Kb, peak mem: {peak_mem / 10 ** 3} Kb")
It seems to be caused by the labels method. PS: prometheus-client==0.17.1
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从提供的 tracemalloc 复现开始,检查 counter_a 使用的 labels 方法,并将其与 counter_b.inc() 进行比较。确认重复调用 labels 是否会导致报告中的内存增长,然后验证在不改变计数器正常行为的情况下,复现出的内存泄漏已得到解决。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- observability-sre
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 45/100