Skip to content

Commit

Permalink
Merge pull request #2336 from elendiastarman/gevent-statsd-fix
Browse files Browse the repository at this point in the history
Fixed two bugs related to gevent + gunicorn + statsd.
  • Loading branch information
benoitc authored Aug 6, 2024
2 parents 5e39f88 + 0d28529 commit 26c22af
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 2 additions & 0 deletions gunicorn/instrument/statsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ def access(self, resp, req, environ, request_time):
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)
Expand Down
6 changes: 5 additions & 1 deletion gunicorn/workers/ggevent.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,11 @@ def log_request(self):
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:
Expand Down

0 comments on commit 26c22af

Please sign in to comment.