prometheus / prometheus/client_python
Metric without `labelnames` causes issues in when MULTIPROC is enabled
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 4.4k
- Fork
- 876
- Merge medio
- 8g 4h
- PR unite (30g)
- 1
Descrizione
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_DIRis 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:
- Some histogram metrics set in a threaded celery worker where
PROMETHEUS_MULTIPROC_DIRare not reported - No such issue in pre-fork workers
- The issue was resolved by adding the
labelnamesargument to a metric where it was missing (which was an histogram as well)
Other observations:
- 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.
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia riproducendo la configurazione a processo singolo con thread e PROMETHEUS_MULTIPROC_DIR abilitato, quindi confronta le metriche definite con e senza labelnames. Osserva l'inizializzazione delle metriche, i file di database creati e l'output di esposizione, quindi traccia la gestione multiprocess coinvolta. Il lavoro è completato quando il comportamento è compreso e le metriche vengono riportate in modo coerente, con una decisione chiara sulla validazione dei labelnames mancanti.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- observability-sre
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 45/100