prometheus / prometheus/client_python
Metrics declared at toplevel of program interfere with autoreload
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
To reproduce:
- Create a file
bar.pywith contents
from prometheus_client import Gauge
my_gauge = Gauge('my_gauge', 'my description')
def add(x, y):
return x + y
- Create a Jupyter notebook with the contents
%load_ext autoreload
%autoreload 2
from bar import add
# ---- cell break ----
add(2, 3)
and run it.
3. Edit bar.py in some way (e.g. add a product(x, y) function).
4. Re-run the add(2, 3) cell in the notebook
Expected behavior
Autoreload works fine; the cell runs without issue.
Actual behavior
After running add(2, 3) a second time, it prints this error to stderr:
[autoreload of bar failed: Traceback (most recent call last):
File "/dev/shm/uid-21748-gid-32786/39d5b5d2-seed-nspid4026531836-ns-4026531841/lib/python3.10/site-packages/IPython/extensions/autoreload.py", line 245, in check
superreload(m, reload, self.old_objects)
File "/dev/shm/uid-21748-gid-32786/39d5b5d2-seed-nspid4026531836-ns-4026531841/lib/python3.10/site-packages/IPython/extensions/autoreload.py", line 394, in superreload
module = reload(module)
File "/dev/shm/uid-21748-gid-32786/39d5b5d2-seed-nspid4026531836-ns-4026531841/lib/python3.10/imp.py", line 315, in reload
return importlib.reload(module)
File "/dev/shm/uid-21748-gid-32786/39d5b5d2-seed-nspid4026531836-ns-4026531841/lib/python3.10/importlib/__init__.py", line 169, in reload
_bootstrap._exec(spec, module)
File "<frozen importlib._bootstrap>", line 619, in _exec
File "<frozen importlib._bootstrap_external>", line 883, in exec_module
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "/j/igm/user/kstaley/pub/Jupyter/play/bar.py", line 3, in <module>
my_gauge = Gauge('my_gauge', 'my description')
File "/dev/shm/uid-21748-gid-32786/39d5b5d2-seed-nspid4026531836-ns-4026531841/lib/python3.10/site-packages/prometheus_client/metrics.py", line 365, in __init__
super().__init__(
File "/dev/shm/uid-21748-gid-32786/39d5b5d2-seed-nspid4026531836-ns-4026531841/lib/python3.10/site-packages/prometheus_client/metrics.py", line 143, in __init__
registry.register(self)
ValueError: Duplicated timeseries in CollectorRegistry: {'my_gauge'}
]
Notes
I think instantiating a metric should be idempotent. If you are passing the exact same metric name, docstring, labels, etc., you should get back the same metric object instance. This would imply having a factory function instead of directly exposing the metric classes. Maybe this behavior could be opt-in if enabling it by default is worrisome.
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Reproduce el problema con bar.py, el notebook de Jupyter usando IPython autoreload y prometheus_client.Gauge, y luego inspecciona el traceback de duplicate CollectorRegistry. Determina el comportamiento previsto al recargar una métrica de nivel superior; done debe significar que volver a ejecutar la celda del notebook después de editar bar.py se completa sin el error de series temporales duplicadas.
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
- 5/5
- Tiempo estimado
- Más de una semana
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 35/100