prometheus / prometheus/client_python

write_to_textfile: tmp file is left behind if generator code fails

オープン
#607 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

enhancement
主要言語
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.

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

prometheus_client/exposition.py の 202-203 行付近にある write_to_textfile の実装から始めます。ここでは、一時ファイルの作成中に generate_latest(registry) が実行されます。collector コードが例外を発生させた場合の失敗経路を追跡し、最終的な動作で一時ファイルが残らず、アトミックなリネームのフローが維持されることを確認してください。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
backend
issue の種類
バグ
難易度
2/5
見積もり時間
1〜3時間
活発さ
停滞
明瞭さ
明確に書かれている
初心者へのやさしさ
45/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。