Fixed two bugs related to gevent + gunicorn + statsd.

This commit is contained in:
Lee Burnette 2020-05-20 12:11:14 -04:00 committed by Lee Burnette
parent 6aab4decde
commit 0d28529cb0
2 changed files with 7 additions and 1 deletions

View File

@ -95,6 +95,8 @@ class Statsd(Logger):
Logger.access(self, resp, req, environ, request_time)
duration_in_ms = request_time.seconds * 1000 + float(request_time.microseconds) / 10 ** 3
status = resp.status
if isinstance(status, bytes):
status = status.decode('utf-8')
if isinstance(status, str):
status = int(status.split(None, 1)[0])
self.histogram("gunicorn.request.duration", duration_in_ms)

View File

@ -165,7 +165,11 @@ class PyWSGIHandler(pywsgi.WSGIHandler):
finish = datetime.fromtimestamp(self.time_finish)
response_time = finish - start
resp_headers = getattr(self, 'response_headers', {})
resp = GeventResponse(self.status, resp_headers, self.response_length)
# Status is expected to be a string but is encoded to bytes in gevent for PY3
# Except when it isn't because gevent uses hardcoded strings for network errors.
status = self.status.decode() if isinstance(self.status, bytes) else self.status
resp = GeventResponse(status, resp_headers, self.response_length)
if hasattr(self, 'headers'):
req_headers = self.headers.items()
else: