prometheus / prometheus/client_python
Labels on function decorator that are defined at runtime
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
Referring back to this thread: https://github.com/prometheus/client_python/issues/157
I wanted to know if there's a way to use the function decorator syntax with labels that will be instantiated at a later point? I need to fetch the label values from another service first. I am currently filling in some dummy values which will give me duplicated metrics:
inference_time_created{edge="EMPTY_SCOPE",line="EMPTY_SCOPE",module="EMPTY_SCOPE",plant="EMPTY_SCOPE",workload="EMPTY_SCOPE"} 1.6311126626366935e+09
inference_time_created{edge="ACTUAL_VALUE",line="ACTUAL_VALUE",module="ACTUAL_VALUE",plant="ACTUAL_VALUE",workload="ACTUAL_VALUE"} 1.6311126626709173e+09
So my question is if there's a way to not have the EMPTY_SCOPE metric on the endpoint.
This is the basic idea of what I'm doing:
scope_keys = ["plant", "edge", "line", "workload", "module"]
scope_values = ["EMPTY_SCOPE"] * 5
inference_time_created= Gauge('inference_time', 'How long (in seconds) does it take for an inference', scope_keys)
inference_time_created_labeled = inference_time_created.labels(*scope_values)
def set_metrics_scope(scope): # this function gets called later in the main code
scope_values = scope
inference_time_created_labeled = inference_time_created.labels(*scope_values)
@inference_time_created_labeled.time()
def inference():
# do some calculations
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
En el issue no se identifica ningún archivo fuente ni ninguna prueba. Empieza siguiendo la llamada Gauge.labels y el punto de entrada .time() del decorador utilizado en el ejemplo; done debería permitir proporcionar los valores de las etiquetas más adelante sin exponer la métrica EMPTY_SCOPE inicial.
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
- Nueva funcionalidad
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 35/100