This repository has been archived by the owner on Apr 26, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Add a metric which increments when a request is received #2965
Merged
Merged
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,6 +60,11 @@ | |
) | ||
) | ||
|
||
requests_counter = metrics.register_counter( | ||
"requests_received", | ||
labels=["method", "servlet", ], | ||
) | ||
|
||
outgoing_responses_counter = metrics.register_counter( | ||
"responses", | ||
labels=["method", "code"], | ||
|
@@ -146,7 +151,8 @@ def wrapped_request_handler(self, request): | |
# at the servlet name. For most requests that name will be | ||
# JsonResource (or a subclass), and JsonResource._async_render | ||
# will update it once it picks a servlet. | ||
request_metrics.start(self.clock, name=self.__class__.__name__) | ||
servlet_name = self.__class__.__name__ | ||
request_metrics.start(self.clock, name=servlet_name) | ||
|
||
request_context.request = request_id | ||
with request.processing(): | ||
|
@@ -155,6 +161,7 @@ def wrapped_request_handler(self, request): | |
if include_metrics: | ||
yield request_handler(self, request, request_metrics) | ||
else: | ||
requests_counter.inc(request.method, servlet_name) | ||
yield request_handler(self, request) | ||
except CodeMessageException as e: | ||
code = e.code | ||
|
@@ -286,6 +293,7 @@ def _async_render(self, request, request_metrics): | |
servlet_classname = "%r" % callback | ||
|
||
request_metrics.name = servlet_classname | ||
requests_counter.inc(request.method, servlet_classname) | ||
|
||
# Now trigger the callback. If it returns a response, we send it | ||
# here. If it throws an exception, that is handled by the wrapper | ||
|
@@ -342,7 +350,7 @@ def _send_response(self, request, code, response_json_object, | |
|
||
|
||
def _options_handler(request): | ||
return {} | ||
return 200, {} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was just finding it very confusing to try to guess whether the {} is a response body, or parsed URL segments, or what - especially _get_handler_for_request seems to append its own {} tuple alongside the returned handler... just a snidget of pydoc feels like it would be useful for confused bears There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (especially as it looks like you were confused too, based on missing the 200) |
||
|
||
|
||
def _unrecognised_request_handler(request): | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should have been in dbe80a2, but I'm a crank