Title: Assert label values be str or unicode by kehao95 · Pull Request #177 · prometheus/client_python · GitHub
Open Graph Title: Assert label values be str or unicode by kehao95 · Pull Request #177 · prometheus/client_python
X Title: Assert label values be str or unicode by kehao95 · Pull Request #177 · prometheus/client_python
Description: Right now, if you call add_metric() method with no string variables. Nothing will happen. But will raise meanless AttributError when first scrape.
quick reproduce
import time
from prometheus_client import start_http_server
from prometheus_client.core import GaugeMetricFamily, REGISTRY
class CustomCollector(object):
def collect(self):
foo = GaugeMetricFamily('foo_bar', '', labels=['label1', 'label2'])
foo.add_metric([1, 'bar'], 1) # Use an int as label value
yield foo
REGISTRY.register(CustomCollector())
if __name__ == '__main__':
start_http_server(9091)
while True:
time.sleep(30)
When you try to scrape the metrics, it will raise a helpless Tracback.
----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 64728)
----------------------------------------
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/socketserver.py", line 318, in _handle_request_noblock
self.process_request(request, client_address)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/socketserver.py", line 344, in process_request
self.finish_request(request, client_address)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/socketserver.py", line 357, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/socketserver.py", line 684, in __init__
self.handle()
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/http/server.py", line 415, in handle
self.handle_one_request()
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/http/server.py", line 403, in handle_one_request
method()
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/prometheus_client/exposition.py", line 86, in do_GET
output = generate_latest(registry)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/prometheus_client/exposition.py", line 72, in generate_latest
for k, v in sorted(labels.items())]))
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/prometheus_client/exposition.py", line 72, in
Open Graph Description: Right now, if you call add_metric() method with no string variables. Nothing will happen. But will raise meanless AttributError when first scrape. quick reproduce import time from prometheus_client...
X Description: Right now, if you call add_metric() method with no string variables. Nothing will happen. But will raise meanless AttributError when first scrape. quick reproduce import time from prometheus_client...
Opengraph URL: https://github.com/prometheus/client_python/pull/177
X: @github
Domain: patch-diff.githubusercontent.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:e68663ff-d2b6-7655-9fb8-4ad2a2e17aa6 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | CE02:42376:1A25A8E:22024AD:69925E73 |
| html-safe-nonce | 0c2dd74756e4d295ee55ef9c63f7274ba4886a74ccb85db81a45f5a6bc8c585b |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDRTAyOjQyMzc2OjFBMjVBOEU6MjIwMjRBRDo2OTkyNUU3MyIsInZpc2l0b3JfaWQiOiI2NzU5NzEzNTE4NDMyNDQ0MDE5IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 3755f9884a7a36a8935319d9c1b0e434e4afdff0303100b306672209793610ed |
| hovercard-subject-tag | pull_request:130066388 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/prometheus/client_python/pull/177/files |
| twitter:image | https://avatars.githubusercontent.com/u/6213976?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/6213976?s=400&v=4 |
| og:image:alt | Right now, if you call add_metric() method with no string variables. Nothing will happen. But will raise meanless AttributError when first scrape. quick reproduce import time from prometheus_client... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 42c603b9d642c4a9065a51770f75e5e27132fef0e858607f5c9cb7e422831a7b |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/prometheus/client_python git https://github.com/prometheus/client_python.git |
| octolytics-dimension-user_id | 3380462 |
| octolytics-dimension-user_login | prometheus |
| octolytics-dimension-repository_id | 30618733 |
| octolytics-dimension-repository_nwo | prometheus/client_python |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 30618733 |
| octolytics-dimension-repository_network_root_nwo | prometheus/client_python |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 848bc6032dcc93a9a7301dcc3f379a72ba13b96e |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width