prometheus / prometheus/client_python

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

Abierto
#1,123 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Lenguaje dominante
Python
Estrellas
4.4k
Forks
876
Merge medio
8 d 4 h
PR fusionados (30 d)
1

Descripción

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.

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Empieza reproduciendo la configuración de un solo proceso con hilos y PROMETHEUS_MULTIPROC_DIR habilitado, y compara las métricas definidas con y sin labelnames. Observa la inicialización de las métricas, los archivos de base de datos creados y la salida de exposición; después, sigue el procesamiento multiproceso involucrado. Se considera terminado cuando se comprende el comportamiento y las métricas se reportan de forma coherente, con una decisión clara sobre la validación de labelnames ausentes.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
python
Área
observability-sre
Tipo de issue
Error
Dificultad
4/5
Tiempo estimado
3-5 días
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
45/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.