-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(api): per-endpoint metric tags (#13374)
This allows endpoints to add tags to the resulting `view.response` metric that gets recorded in middleware. The immediate use for this is to tag all Integration Platform endpoints with a corresponding tag so that we can split them out downstream.
- Loading branch information
Showing
8 changed files
with
149 additions
and
10 deletions.
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
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
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
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
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
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
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
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 |
---|---|---|
@@ -0,0 +1,75 @@ | ||
from __future__ import absolute_import | ||
|
||
from django.test import RequestFactory | ||
from exam import fixture | ||
from mock import patch | ||
|
||
from sentry.middleware.stats import RequestTimingMiddleware, add_request_metric_tags | ||
from sentry.testutils import TestCase | ||
from sentry.testutils.helpers.faux import Mock | ||
|
||
|
||
class RequestTimingMiddlewareTest(TestCase): | ||
middleware = fixture(RequestTimingMiddleware) | ||
factory = fixture(RequestFactory) | ||
|
||
@patch('sentry.utils.metrics.incr') | ||
def test_records_default_api_metrics(self, incr): | ||
request = self.factory.get('/') | ||
request._view_path = '/' | ||
response = Mock(status_code=200) | ||
|
||
self.middleware.process_response(request, response) | ||
|
||
incr.assert_called_with( | ||
'view.response', | ||
instance=request._view_path, | ||
tags={ | ||
'method': 'GET', | ||
'status_code': 200, | ||
}, | ||
skip_internal=False, | ||
) | ||
|
||
@patch('sentry.utils.metrics.incr') | ||
def test_records_endpoint_specific_metrics(self, incr): | ||
request = self.factory.get('/') | ||
request._view_path = '/' | ||
request._metric_tags = {'a': 'b'} | ||
|
||
response = Mock(status_code=200) | ||
|
||
self.middleware.process_response(request, response) | ||
|
||
incr.assert_called_with( | ||
'view.response', | ||
instance=request._view_path, | ||
tags={ | ||
'method': 'GET', | ||
'status_code': 200, | ||
'a': 'b', | ||
}, | ||
skip_internal=False, | ||
) | ||
|
||
@patch('sentry.utils.metrics.incr') | ||
def test_add_request_metric_tags(self, incr): | ||
request = self.factory.get('/') | ||
request._view_path = '/' | ||
|
||
add_request_metric_tags(request, foo='bar') | ||
|
||
response = Mock(status_code=200) | ||
|
||
self.middleware.process_response(request, response) | ||
|
||
incr.assert_called_with( | ||
'view.response', | ||
instance=request._view_path, | ||
tags={ | ||
'method': 'GET', | ||
'status_code': 200, | ||
'foo': 'bar', | ||
}, | ||
skip_internal=False, | ||
) |