Eagerly convert value to float in *MetricFamily.add_metric()
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 4/5
- Tempo estimado
- 3-5 dias
- Facilidade para iniciantes
- 35/100
- Tipo de issue
- Funcionalidade
- Clareza
- Razoavelmente clara
- Status de atividade
- Estagnada
- Stack de tecnologia
- prometheus, python
- Domínio
- observability-sre
Direção de pesquisa
Comece por MetricFamily.add_metric() e depois compare o caminho de serialização em openmetrics/exposition.py e utils.py, incluindo generate_latest e floatToGoString do traceback. Está concluído quando valores inválidos falharem durante a adição da métrica, em vez de durante a serialização, e o impacto na compatibilidade e o comportamento relevante estiverem cobertos por testes.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
Hi there, an experience report and improvement suggestion.
I have a pretty simple exporter which queries a backend URL for JSON, grabs the JSON, stuffs it into prometheus metric families, which it then yields.
Sometimes it errors with stacktraces only when the request is finishing, with a stack traces that points at finish_request rather than the code that added the bad float:
TypeError: ("float() argument must be a string or a number, not 'NoneType'", Metric(bom_wind_speed, Wind speed (km/h) from the Bureau of Meterology, gauge, , [Sample(name='bom_wind_speed', labels={'location': 'Sydney Airport'}, value=None, timestamp=None, exemplar=None), Sample(name='bom_wind_speed', labels={'location': 'Sydney - Observatory Hill'}, value=20, timestamp=None, exemplar=None)]))
Traceback (most recent call last):
File "/usr/local/lib/python3.5/socketserver.py", line 625, in process_request_thread
self.finish_request(request, client_address)
File "/usr/local/lib/python3.5/socketserver.py", line 354, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "/usr/local/lib/python3.5/socketserver.py", line 681, in __init__
self.handle()
File "/usr/local/lib/python3.5/http/server.py", line 422, in handle
self.handle_one_request()
File "/usr/local/lib/python3.5/http/server.py", line 410, in handle_one_request
method()
File "/usr/local/lib/python3.5/site-packages/prometheus_client/exposition.py", line 152, in do_GET
output = encoder(registry)
File "/usr/local/lib/python3.5/site-packages/prometheus_client/openmetrics/exposition.py", line 56, in generate_latest
floatToGoString(s.value),
File "/usr/local/lib/python3.5/site-packages/prometheus_client/utils.py", line 8, in floatToGoString
d = float(d)
TypeError: ("float() argument must be a string or a number, not 'NoneType'", Metric(bom_wind_speed, Wind speed (km/h) from the Bureau of Meterology, gauge, , [Sample(name='bom_wind_speed', labels={'location': 'Sydney Airport'}, value=None, timestamp=None, exemplar=None), Sample(name='bom_wind_speed', labels={'location': 'Sydney - Observatory Hill'}, value=20, timestamp=None, exemplar=None)]))
I've hit this kind of bug a few times in different exporters (I guess it's to be expected to get type errors in Python sometimes).
How about eagerly converting the value passed to add_metric to a float? Then the stack trace would point at the exact cause.
This might be a breaking change - that'd be a reasonable reason to reject this. But any code doing this will likely fail soon after, as soon as an attempt is made to serialize the metric, so maybe it'd be worth the change for better debuggability? What do you think?
- Linguagem predominante
- Python
- Estrelas
- 4.4k
- Forks
- 876
- Merge médio
- 8d 4h
- PRs com merge (30d)
- 1
Guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de prometheus/client_python
-
bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 70/100
prometheus/client_python#1177 · 1 comentário ·
-
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 45/100
prometheus/client_python#1210 ·
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 58/100
prometheus/client_python#1199 · 1 reação ·
-
Dificuldade 5/5 Mais de uma semana Facilidade para iniciantes 35/100
prometheus/client_python#1176 ·
-
Dificuldade 1/5 1-3 horas Facilidade para iniciantes 52/100
prometheus/client_python#1126 · 2 comentários ·
Todas as issues de prometheus/client_python
Issues semelhantes
-
agent-ready documentation needs-triage
Dificuldade 1/5 1-3 horas Facilidade para iniciantes 88/100
-
documentation
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 91/100
-
workflow-status page template still says reusable workflows are "triggered only by workflow_call:" Aberta
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 92/100
-
instance instance add
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 72/100
searxng/searx-instances#939 · 1 comentário ·
-
area-deployment area-integrations triage:bot-seen
Dificuldade 2/5 Meio dia Facilidade para iniciantes 86/100