10000 Bugfix urlparse in python >= 3.7.6 (#497) · lweith/client_python@470b2d3 · GitHub
[go: up one dir, main page]

Skip to content

Commit 470b2d3

Browse files
gmossessianbrian-brazil
authored andcommitted
Bugfix urlparse in python >= 3.7.6 (prometheus#497)
* set http prefix in python geq 3.7.6 Signed-off-by: George Mossessian <gmossessian@gmail.com>
1 parent 87d08de commit 470b2d3

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

prometheus_client/exposition.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"""Content type of the latest text format"""
3030

3131
PYTHON26_OR_OLDER = sys.version_info < (2, 7)
32-
32+
PYTHON376_OR_NEWER = sys.version_info > (3, 7, 5)
3333

3434
def make_wsgi_app(registry=REGISTRY):
3535
"""Create a WSGI app which serves the metrics from a registry."""
@@ -341,7 +341,11 @@ def delete_from_gateway(
341341

342342
def _use_gateway(method, gateway, job, registry, grouping_key, timeout, handler):
343343
gateway_url = urlparse(gateway)
344-
if not gateway_url.scheme or (PYTHON26_OR_OLDER and gateway_url.scheme not in ['http', 'https']):
344+
# See https://bugs.python.org/issue27657 for details on urlparse in py>=3.7.6.
345+
if not gateway_url.scheme or (
346+
(PYTHON376_OR_NEWER or PYTHON26_OR_OLDER)
347+
and gateway_url.scheme not in ['http', 'https']
348+
):
345349
gateway = 'http://{0}'.format(gateway)
346350
url = '{0}/metrics/{1}/{2}'.format(gateway, *_escape_grouping_key("job", job))
347351

tests/test_exposition.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,13 @@ def test_push(self):
235235
self.assertEqual(self.requests[0][0].headers.get('content-type'), CONTENT_TYPE_LATEST)
236236
self.assertEqual(self.requests[0][1], b'# HELP g help\n# TYPE g gauge\ng 0.0\n')
237237

238+
def test_push_schemeless_url(self):
239+
push_to_gateway(self.address.replace('http://', ''), "my_job", self.registry)
240+
self.assertEqual(self.requests[0][0].command, 'PUT')
241+
self.assertEqual(self.requests[0][0].path, '/metrics/job/my_job')
242+
self.assertEqual(self.requests[0][0].headers.get('content-type'), CONTENT_TYPE_LATEST)
243+
self.assertEqual(self.requests[0][1], b'# HELP g help\n# TYPE g gauge\ng 0.0\n')
244+
238245
def test_push_with_groupingkey(self):
239246
push_to_gateway(self.address, "my_job", self.registry, {'a': 9})
240247
self.assertEqual(self.requests[0][0].command, 'PUT')

0 commit comments

Comments
 (0)
0