prometheus / prometheus/client_python

Metric without `labelnames` causes issues in when MULTIPROC is enabled

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

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

主要言語
Python
スター
4.4k
フォーク
876
平均マージ
8日 4時間
マージ済み PR(30日)
1

説明

Hello,
I noticed (see https://github.com/prometheus/client_python/issues/902#issuecomment-3013566209 for example ) that when

  • having a metric defined without a label
  • multiprocess mode is enabled (i.e. PROMETHEUS_MULTIPROC_DIR is set )
  • an app has a single process

then this causes issues, and some metrics will not be reported.

It's not exactly clear to me what is happening, but an indication that something is wrong is that a prometheus db file is created at load time (i.e. when metrics are defined, before they are set).

Here's what I have in more details:


Observations in a prod application:

  1. Some histogram metrics set in a threaded celery worker where PROMETHEUS_MULTIPROC_DIR are not reported
  2. No such issue in pre-fork workers
  3. The issue was resolved by adding the labelnames argument to a metric where it was missing (which was an histogram as well)

Other observations:

  1. When starting the app, a prom db file is created for the metric that was missing labelnames (before any measurement is made)

Hypothesis:

  • in a celery worker in pre-fork mode, the process creating the first db file is not the same process were metrics are set afterwards, so there is no "collision" (because of the pid suffix)
  • in a celery worker in threaded mode, there is a single process creating the first db file and setting the metrics, and somehow collisions happens and some metrics are not reported

Values set at startup:

$ curl localhost:8000

# HELP test_histogram_no_label test Histogram
# TYPE test_histogram_no_label histogram
test_histogram_no_label_sum 0.0
test_histogram_no_label_bucket{le="1.0"} 0.0
test_histogram_no_label_bucket{le="2.0"} 0.0
test_histogram_no_label_bucket{le="+Inf"} 0.0
test_histogram_no_label_count 0.0


It seems to me that a simple way to address this would be to raise when a metric is defined without labelnames, as labelnames are mandatory anyway.

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

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

はじめの一歩

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

調査の方向性

まず、PROMETHEUS_MULTIPROC_DIR を有効にしたシングルプロセスのスレッド構成を再現し、labelnames ありとなしで定義したメトリクスを比較します。メトリクスの初期化、作成されたデータベースファイル、exposition の出力を観察し、その後、関係する multiprocess 処理を追跡します。動作を理解し、メトリクスが一貫して報告され、欠落した labelnames を検証するかどうかについて明確な判断ができれば完了です。

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

評価

技術スタック
python
領域
observability-sre
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
45/100

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

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