prometheus / prometheus/client_python
Remove gauge metric
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
Hi all,
I have written a custom exporter for calculating the cost of using a node in AWS.
Here is how it works:
Lets assume I have 3 nodes, each costs 5$/ 1h, when I plot using grafana the sum(cost_metric{}) i get 15$ (3x5$). Lets say after 2 hours one of the nodes get deleted (autoscaling). In that case the total cost should drop to 10$.
The problem is that in my case the metric is preserved and even though the node has been deleted the cost is kept and thus it displays 15$ instead of dropping to 10$
How would I go about saving that problem?
cost_metric = Gauge(
"cost_metric ",
"Cost of running an instance for 1 hour",
["node_name", "instance_type"],
)
...
node_names = get_nodes()
for node_name in node_names:
node_info = get_node_info(node_name)
if node_info is None:
continue
logging.info(f"Updating metrics for node: {node_name}")
# labels section
labels = node_info["metadata"]["labels"]
instance_type = labels.get("beta.kubernetes.io/instance-type", "unknown")
cost = get_cost_of_instance(instance_type)
if cost is not None:
cost_metric.labels(node_name=node_name, instance_type=instance_type).set(cost)
I tried
I collected previous and current nodes in form of dict and then wanted to removed the ones that arent existing, the issue is that :
cost_metric.remove(node_name=node_name, instance_type=instance_type)
Traceback (most recent call last):
File "/home/XXXX/projects/main.py", line 154, in <module>
previous_nodes = update_metrics(previous_nodes)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/eksohio/projects/main.py", line 131, in update_metrics
cost.remove(node_name=node_name, instance_type=instance_type)
TypeError: MetricWrapperBase.remove() got an unexpected keyword argument 'node_name'
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
El payload menciona la declaración de Gauge y la llamada a MetricWrapperBase.remove en el traceback, pero no ningún archivo del repositorio ni ninguna prueba. Empieza comprobando las API de Gauge y MetricWrapperBase para la eliminación de labels y revisa el bucle del exporter mostrado. La tarea estará terminada cuando se haya establecido la forma compatible de eliminar la métrica del nodo eliminado o se haya confirmado que es necesario cambiar la biblioteca.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- aws, kubernetes, prometheus, python
- Área
- cloud, infrastructure, observability
- Tipo de issue
- Error
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Estancado
- Claridad
- Necesita aclaración
- Aptitud para principiantes
- 25/100