prometheus / prometheus/client_python
WSL and MultiProcessCollector
Personne n'a encore pris cette issue.
- Langage dominant
- Python
- Étoiles
- 4.4k
- Forks
- 876
- Merge moyen
- 8 j 4 h
- PR mergées (30 j)
- 1
Description
I ran into relatively esoteric issue when using MultiProcessCollector on a Windows Subsystem for Linux installation. I don't know that I would consider it a bug or anything that necessarily requires any developer cycles on it. But I wanted to make it known so the maintainers could at least know about it to fix if they so wish, to document this peculiarity so search engines or AI scrapers can catch it, or to ignore it as just a weird quirk not worth anybody's time.
When using the MultiProcessCollector in a Windows Subsystem for Linux (WSL) environment, metric files in prometheus_multiproc_dir (e.g., counter_.db) have the used field written at offset 0x00010000 (65536 bytes) instead of the expected page-aligned offset (e.g., 0x00000000) when the directory is on a Windows-mounted file system (e.g., /mnt/c/...). This causes the collector to read no data, as it expects used at the start of pages (e.g., 4096-byte boundaries). Moving prometheus_multiproc_dir to a Linux-native file system (e.g., /tmp) resolves the issue, with the used field correctly written at offset 0x00000000.
This appears to be a WSL-specific quirk affecting ftruncate or mmap operations. The file is opened in 'a+b' mode, truncated to _INITIAL_MMAP_SIZE = 65536, and mapped with mmap.mmap(fileno, 65536, MAP_SHARED, PROT_READ|PROT_WRITE, offset=0). Despite file.tell() returning 0 after truncate, writes occur at 0x00010000 on Windows-mounted paths.
Steps to Reproduce
- In a WSL environment (e.g., WSL2), set
prometheus_multiproc_dirto a Windows-mounted path:
import os
from prometheus_client import Counter, MultiProcessCollector, REGISTRY
os.environ['PROMETHEUS_MULTIPROC_DIR'] = '/mnt/c/prometheus_multiproc_dir'
REGISTRY._collector = MultiProcessCollector(REGISTRY)
counter = Counter('my_counter', 'A sample counter')
counter.inc()
- Run the script and inspect a metric file:
xxd /mnt/c/prometheus_multiproc_dir/counter_<pid>.db
The used field (e.g., 50 04 00 00 for 1104 bytes) appears at offset 0x00010000, with zeros before it.
- Move prometheus_multiproc_dir to /tmp:
os.environ['PROMETHEUS_MULTIPROC_DIR'] = '/tmp/prometheus_multiproc_dir'
- Repeat step 2 and the used field is now at 0x00000000, and metrics are collected correctly.
Suggested Action
Add a note to the MultiProcessCollector documentation (e.g., in README.md or multiproc.py) warning WSL users to place prometheus_multiproc_dir on a Linux-native file system (e.g., /tmp, /home/user) to avoid offset issues with Windows-mounted paths (e.g., /mnt/c). Example:
Note for WSL Users: In WSL, set prometheus_multiproc_dir to a Linux-native file system (e.g., /tmp or /home/user) to ensure correct metric file writes. Windows-mounted paths (e.g., /mnt/c) may cause the used field to be written at offset 0x00010000, preventing metric collection.
Additional Context
- No explicit lseek to 65536 was observed via strace, suggesting a WSL file system quirk.
- Moving to /tmp (a tmpfs or ext4 file system) resolved the issue.
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Piste de recherche
Commencez par README.md et multiproc.py, où la documentation de MultiProcessCollector est suggérée. Reproduisez le comportement en plaçant prometheus_multiproc_dir sous /mnt/c et comparez-le à /tmp dans WSL, puis documentez la recommandation d’utiliser un système de fichiers natif Linux ainsi que l’impact sur la collecte des métriques. C’est terminé lorsque l’avertissement est clairement repérable et reflète fidèlement la reproduction fournie.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- python
- Domaine
- observability-sre
- Type d'issue
- Documentation
- Difficulté
- 1/5
- Temps estimé
- 1-3 heures
- Activité
- À l'abandon
- Clarté
- Clairement spécifiée
- Accessibilité débutants
- 52/100