Skip to content
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
9 changes: 7 additions & 2 deletions pyms/flask/services/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,14 @@ def before_request(self): # pylint: disable=R0201
request.start_time = time.time()

def after_request(self, response):
if hasattr(request.url_rule, "rule"):
Copy link
Member Author

Choose a reason for hiding this comment

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

@avara1986 Do you know if there's a real possibility that a request wouldn't have this attribute? I've tested locally and even without using dynamic values for the endpoints works. But the test doesn't, without the conditional. I'm not sure if it really should be like this and have a fallback or is the test_client that's not really complete.

Copy link
Member

Choose a reason for hiding this comment

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

I figure out this weekend :)

Copy link
Member

Choose a reason for hiding this comment

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

@alexppg the problem is not in tests. request.url_rule is None when you get 404 response. It makes sense if you visit a non-exists page therefore, you haven't a url_rule.

PR approved

PD: sorry, one week late... 🙈

path = request.url_rule.rule
else:
path = request.path

request_latency = time.time() - request.start_time
FLASK_REQUEST_LATENCY.labels(self.app_name, request.method, request.path, response.status_code).observe(request_latency)
FLASK_REQUEST_COUNT.labels(self.app_name, request.method, request.path, response.status_code).inc()
FLASK_REQUEST_LATENCY.labels(self.app_name, request.method, path, response.status_code).observe(request_latency)
FLASK_REQUEST_COUNT.labels(self.app_name, request.method, path, response.status_code).inc()

return response

Expand Down