Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve metrics reporting #672

Merged
merged 2 commits into from
Sep 7, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions connexion/decorators/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import os
import time

from werkzeug.exceptions import HTTPException

try:
import uwsgi_metrics
HAS_UWSGI_METRICS = True # pragma: no cover
Expand Down Expand Up @@ -30,16 +32,19 @@ def __call__(self, function):

@functools.wraps(function)
def wrapper(request):
status_code = 500
status = 'unknown-exception'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW I can imagine this being a big pain for someone trying parse logs who expects the status to always be an integer.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'd still default this to 500, what do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also expect it to be 500, since that's what makes sense from an end-2-end visibility point of view.

start_time_s = time.time()
try:
response = function(request)
status_code = response.status_code
status = response.status_code
except HTTPException as http_e:
status = http_e.code
raise http_e
finally:
end_time_s = time.time()
delta_s = end_time_s - start_time_s
delta_ms = delta_s * 1000
key = '{status}.{suffix}'.format(status=status_code, suffix=self.key_suffix)
key = '{status}.{suffix}'.format(status=status, suffix=self.key_suffix)
uwsgi_metrics.timer(self.prefix, key, delta_ms)
return response

Expand Down