prometheus / prometheus/client_python
gauge.set_function() doesn't work in multiprocess mode
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 4.4k
- フォーク
- 876
- 平均マージ
- 8日 4時間
- マージ済み PR(30日)
- 1
説明
Multiprocess mode's collect() reads the registry files and aggregates metrics that have been written to prometheus_multiproc_dir.
This doesn't work with gauge.set_function() which does not record its value. The provided function is just called during collection.
That means with the following code:
registry = CollectorRegistry()
Gauge("test", "test", registry=self._registry).set_function(lambda: 100)
multiprocess.MultiProcessCollector(registry)
The output will be:
# HELP test test
# TYPE test gauge
test 100.0
# HELP test Multiprocess metric
# TYPE test gauge
test{pid="10705"} 0.0
Current side effects:
- If any mode other than
allorliveallis used, thepidtag won't be included. This results in duplicate metrics being reported to Prometheus. Prometheus currently only uses the first metric it reads, which is non-deterministic due to iteration over the registry's dictionary. - If
registry=Noneto avoid double reporting, only the default value of0.0is reported. - Current way to work around it is to use the mode
alland to ignore gauges in Prometheus and with the tagpid.
Proposal:
I'm not sure how you could incorporate set_function into the multiprocess registry and I'm not convinced how useful of a feature it would be. Is it reasonable to add a new multiprocess_mode: exclude which would prevent the incorrect 0.0 value being reported? Or would it be better to just add documentation to recommend using two independent registries?
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
prometheus_multiproc_dirを設定した状態で、multiprocess.pyのcollect()エントリポイントとregistry.pyのset_function()の動作を使用して差異を再現します。multiprocessモード間で報告される値を比較し、set_function()に期待される処理を判断します。選択した動作が文書化され、0.0の重複または誤った報告が修正されれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- observability-sre
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- 説明が足りない
- 初心者へのやさしさ
- 35/100