Prometheus exporter greedy regex in unit annotation stripping corrupts compound and ratio metric units
Los mantenedores suelen responder en 2 días
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 68/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Stack tecnológico
- prometheus, python
- Área
- observability
Línea de trabajo
La eliminación de unidades está en opentelemetry/exporter/prometheus/_mapping.py, en la expresión regular _UNIT_ANNOTATION que usa map_unit. Empieza ejecutando las tres llamadas de reproducción del issue (m{length}/s{time}, By{total}/s{interval}, {requests}/s{interval}) para ver la salida actual. Está terminado cuando esas entradas se mapean a meters_per_second, bytes_per_second y per_second, y las pruebas unitarias existentes del exportador siguen pasando. Obtén la aprobación de los mantenedores antes de abrir un pull request, ya que todavía no hay nadie asignado.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Describe your environment
OS: Linux / macOS / Windows
Python version: Python 3.10 / 3.11 / 3.12
SDK version: main (1.30.0dev / current)
API version: main (1.30.0dev / current)
What happened?
In opentelemetry-exporter-prometheus, the unit mapping logic in opentelemetry/exporter/prometheus/_mapping.py uses a regex to strip UCUM curly-brace annotations from metric units:
_UNIT_ANNOTATION = compile(r"{.*}")
Because the regex pattern compile(r"{.}") is greedy, the . quantifier matches from the first opening curly brace to the last closing curly brace across the entire unit string.
When a metric unit contains multiple annotations or an annotation in both the numerator and denominator of a compound ratio (for example, By{total}/s{interval} or m{length}/s{time}), the greedy match consumes everything between the braces including the slash and the denominator unit identifier.
This causes the Prometheus exporter to produce incorrect Prometheus metric names that corrupt or invert the metric semantics. For example:
- By{total}/s{interval} (bytes per second) is stripped to By and exported as bytes instead of bytes_per_second.
- m{length}/s{time} (meters per second) is stripped to m and exported as meters instead of meters_per_second.
- {requests}/s{interval} (requests per second) is stripped to an empty string and exported without per_second.
- km{distance}/h{duration} is stripped to km and exported as km instead of km_per_hour.
- foo{a}bar{b} has bar stripped, leaving foobar truncated to foo.
Steps to Reproduce
Run the following minimal script:
from opentelemetry.exporter.prometheus._mapping import map_unit
print("m{length}/s{time} ->", map_unit("m{length}/s{time}"))
print("By{total}/s{interval} ->", map_unit("By{total}/s{interval}"))
print("{requests}/s{interval} ->", map_unit("{requests}/s{interval}"))
Expected Result
The annotations inside curly braces should be stripped individually without erasing intervening unit tokens:
m{length}/s{time} -> meters_per_second
By{total}/s{interval} -> bytes_per_second
{requests}/s{interval} -> per_second
Actual Result
m{length}/s{time} -> meters
By{total}/s{interval} -> bytes
{requests}/s{interval} ->
Additional context
In the OpenTelemetry Collector Contrib Prometheus translator, which this mapping was ported from, the regex is bounded by braces:
regexp.MustCompile with pattern {[^}]*}
Replacing compile(r"{.}") with compile(r"{[^{}]}") in opentelemetry/exporter/prometheus/_mapping.py resolves the issue cleanly and ensures annotations are stripped without erasing intermediate units or denominators.
If approved, I would like to work on this one.
- Lenguaje dominante
- Python
- Estrellas
- 2.7k
- Forks
- 1k
- Merge medio
- 3 d 5 h
- PR fusionados (30 d)
- 45
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la 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.
Más de open-telemetry/opentelemetry-python
-
W3CBaggagePropagator.extract ignores all but the first baggage headerPosiblemente ocupada @knowprasad la tomó hace 1 día. Abiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
open-telemetry/opentelemetry-python#5811 ·
Los mantenedores suelen responder en 2 días
-
Delta exponential histogram never goes back to the maximum scale after a wide-range intervalPosiblemente ocupada @inchang-ing la tomó hace 23 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
open-telemetry/opentelemetry-python#5716 ·
Los mantenedores suelen responder en 2 días
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 70/100
open-telemetry/opentelemetry-python#5700 · 1 comentario ·
Los mantenedores suelen responder en 2 días
-
Tests in test_metric_reader_storage.py assert on process-global mock state instead of on the storage under testPosiblemente ocupada @ocelotl la tomó hace 45 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
open-telemetry/opentelemetry-python#5638 ·
Los mantenedores suelen responder en 2 días
-
`SpanProcessor.on_end` exceptions escape cleanup and replace application exceptionsPosiblemente ocupada @somuai la tomó hace 49 días. Abiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
open-telemetry/opentelemetry-python#5624 ·
Los mantenedores suelen responder en 2 días
Todos los issues de open-telemetry/opentelemetry-python
Issues similares
-
Project submission:Abierto
Dificultad 1/5 Menos de una hora Aptitud para principiantes 72/100
slavakurilyak/awesome-ai-agents#845 ·
Los mantenedores suelen responder en 1 día
-
tests: pin that the atomic writers in utils/paths.py stage the temporary file in the target's directoryPosiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. Abiertodifficulty:2 enhancement good first issue
Dificultad 1/5 1-3 horas Aptitud para principiantes 92/100
MakazhanAlpamys/Soup#2178 ·
Los mantenedores suelen responder en 1 día
-
[BUG] dcg.waggr permutation p-values are folded twice, so near-zero scores get the smallest p-valuesAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
scverse/rapids-singlecell#854 ·
Los mantenedores suelen responder en 1 día
-
Slang input: int8_t4_packed and uint8_t4_packed are copied into CrossGLPosiblemente ocupada @ninglinLiu la tomó hoy. Abiertoarea:frontend backend:slang bug direction:input
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
Los mantenedores suelen responder en 13 días