prometheus / prometheus/client_python
write_to_textfile: tmp file is left behind if generator code fails
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 4.4k
- フォーク
- 876
- 平均マージ
- 8日 4時間
- マージ済み PR(30日)
- 1
説明
In the write_to_textfile function, the code to run the collector registry is in the temp file creation block: https://github.com/prometheus/client_python/blob/master/prometheus_client/exposition.py#L202-L203
In my case, I had an error in my collector code (run by generate_latest(registry)). This resulted in many tmp files left over from the errors.
I'm wondering if it would be preferable to run the code before the temp file block, e.g.:
tmppath = '%s.%s.%s' % (path, os.getpid(), threading.current_thread().ident)
out = generate_latest(registry)
with open(tmppath, 'wb') as f:
f.write(out)
# rename(2) is atomic.
os.rename(tmppath, path)
Unless leaving temp files behind is the desired/intended behavior.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
prometheus_client/exposition.py の 202-203 行付近にある write_to_textfile の実装から始めます。ここでは、一時ファイルの作成中に generate_latest(registry) が実行されます。collector コードが例外を発生させた場合の失敗経路を追跡し、最終的な動作で一時ファイルが残らず、アトミックなリネームのフローが維持されることを確認してください。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- backend
- issue の種類
- バグ
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 活発さ
- 停滞
- 明瞭さ
- 明確に書かれている
- 初心者へのやさしさ
- 45/100