Prometheus exporter greedy regex in unit annotation stripping corrupts compound and ratio metric units
I maintainer di solito rispondono entro 2 giorni
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 68/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- prometheus, python
- Ambito
- observability
Direzione di ricerca
La rimozione delle unità si trova in opentelemetry/exporter/prometheus/_mapping.py, nell'espressione regolare _UNIT_ANNOTATION usata da map_unit. Inizia eseguendo le tre chiamate di riproduzione dell'issue (m{length}/s{time}, By{total}/s{interval}, {requests}/s{interval}) per vedere l'output attuale. È completato quando questi input vengono mappati su meters_per_second, bytes_per_second e per_second e i test unitari esistenti dell'exporter continuano a passare. Ottieni l'approvazione dei maintainer prima di aprire una pull request, perché al momento non è assegnato nessuno.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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.
- Lingua principale
- Python
- Stelle
- 2.7k
- Fork
- 1k
- Merge medio
- 3g 8h
- PR unite (30g)
- 45
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi 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.
Altre issue di open-telemetry/opentelemetry-python
-
W3CBaggagePropagator.extract ignores all but the first baggage headerForse già presa Una pull request collegata a questa issue è aperta o già unita. Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
open-telemetry/opentelemetry-python#5811 ·
I maintainer di solito rispondono entro 2 giorni
-
Delta exponential histogram never goes back to the maximum scale after a wide-range intervalForse già presa @inchang-ing l’ha presa 22 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
open-telemetry/opentelemetry-python#5716 ·
I maintainer di solito rispondono entro 2 giorni
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 70/100
open-telemetry/opentelemetry-python#5700 · 1 commento ·
I maintainer di solito rispondono entro 2 giorni
-
Tests in test_metric_reader_storage.py assert on process-global mock state instead of on the storage under testForse già presa @ocelotl l’ha presa 44 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
open-telemetry/opentelemetry-python#5638 ·
I maintainer di solito rispondono entro 2 giorni
-
`SpanProcessor.on_end` exceptions escape cleanup and replace application exceptionsForse già presa @somuai l’ha presa 48 giorni fa. Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
open-telemetry/opentelemetry-python#5624 ·
I maintainer di solito rispondono entro 2 giorni
Tutte le issue di open-telemetry/opentelemetry-python
Issue simili
-
Difficoltà 1/5 1-3 ore Idoneità per principianti 88/100
fossasia/visdom-dev#69 ·
I maintainer di solito rispondono entro 3 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
I maintainer di solito rispondono entro 1 giorno
-
Frontend build fails with Frappe version-16: DataImport is no longer exported by @framework/uiApertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
BUG: PROD: v1.3.0-beta Onboarding Profile Picture Misaligns When Name Validation Error AppearsForse già presa @RitikaSen27 l’ha presa oggi. Apertabug good first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
AOSSIE-Org/PictoPy#1647 · 2 commenti ·
I maintainer di solito rispondono entro 2 giorni
-
[oblt-aw][autodoc] Update workflow docs for gh-aw v0.92.5 and detector permission scopeForse già presa @github-actions l’ha presa oggi. Aperta
Difficoltà 1/5 1-3 ore Idoneità per principianti 88/100
I maintainer di solito rispondono entro 1 giorno