prometheus / prometheus/client_python
Labels on function decorator that are defined at runtime
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 4.4k
- フォーク
- 876
- 平均マージ
- 8日 4時間
- マージ済み PR(30日)
- 1
説明
Referring back to this thread: https://github.com/prometheus/client_python/issues/157
I wanted to know if there's a way to use the function decorator syntax with labels that will be instantiated at a later point? I need to fetch the label values from another service first. I am currently filling in some dummy values which will give me duplicated metrics:
inference_time_created{edge="EMPTY_SCOPE",line="EMPTY_SCOPE",module="EMPTY_SCOPE",plant="EMPTY_SCOPE",workload="EMPTY_SCOPE"} 1.6311126626366935e+09
inference_time_created{edge="ACTUAL_VALUE",line="ACTUAL_VALUE",module="ACTUAL_VALUE",plant="ACTUAL_VALUE",workload="ACTUAL_VALUE"} 1.6311126626709173e+09
So my question is if there's a way to not have the EMPTY_SCOPE metric on the endpoint.
This is the basic idea of what I'm doing:
scope_keys = ["plant", "edge", "line", "workload", "module"]
scope_values = ["EMPTY_SCOPE"] * 5
inference_time_created= Gauge('inference_time', 'How long (in seconds) does it take for an inference', scope_keys)
inference_time_created_labeled = inference_time_created.labels(*scope_values)
def set_metrics_scope(scope): # this function gets called later in the main code
scope_values = scope
inference_time_created_labeled = inference_time_created.labels(*scope_values)
@inference_time_created_labeled.time()
def inference():
# do some calculations
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
issue ではソースファイルもテストも特定されていません。まず、Gauge.labels の呼び出しと、例で使用されているデコレータの .time() エントリポイントを追跡してください。done によって、初期の EMPTY_SCOPE メトリクスを公開せずに、後からラベル値を指定できるようにする必要があります。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- observability-sre
- issue の種類
- 機能追加
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100