Skip to content

Commit 2ebb3a6

Browse files
authored
ARCHBOM-1490: rename "custom metric" to "custom attribute" (#59)
Rename "custom metric" to "custom attribute" throughout the monitoring library. This decision can be read about in the ADR 0002-custom-monitoring-language.rst. The following have been deprecated: * set_custom_metric (use set_custom_attribute) * set_custom_metric_for_course_key (use set_custom_attribute_for_course_key) * MonitoringCustomMetricsMiddleware (use CachedCustomMonitoringMiddleware) * CachedCustomMonitoringMiddleware.accumulate_metric (use CachedCustomMonitoringMiddleware.accumulate_attribute) * CodeOwnerMetricMiddleware (use CodeOwnerMonitoringMiddleware) ARCHBOM-1490
1 parent 3110a05 commit 2ebb3a6

15 files changed

+369
-226
lines changed

CHANGELOG.rst

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,23 @@ Change Log
1515
Unreleased
1616
~~~~~~~~~~
1717

18+
[3.8.0] - 2020-08-31
19+
~~~~~~~~~~~~~~~~~~~~
20+
21+
Updated
22+
_______
23+
24+
* Renamed "custom metric" to "custom attribute" throughout the monitoring library. This decision can be read about in the ADR 0002-custom-monitoring-language.rst. The following have been deprecated:
25+
26+
* set_custom_metric (use set_custom_attribute)
27+
* set_custom_metrics_for_course_key (use set_custom_attributes_for_course_key)
28+
* MonitoringCustomMetricsMiddleware (use CachedCustomMonitoringMiddleware)
29+
* CachedCustomMonitoringMiddleware.accumulate_metric (use CachedCustomMonitoringMiddleware.accumulate_attribute)
30+
31+
* This wasn't meant to be used publicly, but was deprecated just in case.
32+
33+
* CodeOwnerMetricMiddleware (use CodeOwnerMonitoringMiddleware)
34+
1835
[3.7.4] - 2020-08-29
1936
~~~~~~~~~~~~~~~~~~~~
2037

@@ -23,10 +40,14 @@ Unreleased
2340
[3.7.3] - 2020-08-12
2441
~~~~~~~~~~~~~~~~~~~~
2542

43+
Updated
44+
_______
45+
2646
* Upgrade psutil to latest version
2747

2848
[3.7.2] - 2020-08-10
2949
~~~~~~~~~~~~~~~~~~~~
50+
3051
Updated
3152
_______
3253

edx_django_utils/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
EdX utilities for Django Application development..
33
"""
44

5-
__version__ = "3.7.4"
5+
__version__ = "3.8.0"
66

77
default_app_config = (
88
"edx_django_utils.apps.EdxDjangoUtilsConfig"

edx_django_utils/monitoring/README.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ Here is how you add the middleware:
2222
# Generate code ownership metrics. Keep this immediately after RequestCacheMiddleware.
2323
...
2424
# Monitoring middleware must come after RequestCacheMiddleware
25-
'edx_django_utils.monitoring.code_owner.middleware.CodeOwnerMetricMiddleware',
26-
'edx_django_utils.monitoring.middleware.MonitoringCustomMetricsMiddleware',
25+
'edx_django_utils.monitoring.code_owner.middleware.CodeOwnerMonitoringMiddleware',
26+
'edx_django_utils.monitoring.middleware.CachedCustomMonitoringMiddleware',
2727
'edx_django_utils.monitoring.middleware.MonitoringMemoryMiddleware',
2828
)
2929
@@ -35,4 +35,4 @@ In addition to adding the MonitoringMemoryMiddleware, you will need to enable a
3535
Code Owner Custom Metric
3636
------------------------
3737

38-
See docstrings for ``CodeOwnerMetricMiddleware`` for configuring the ``code_owner`` custom metric for your IDA.
38+
See docstrings for ``CodeOwnerMonitoringMiddleware`` for configuring the ``code_owner`` custom attribute for your IDA.

edx_django_utils/monitoring/__init__.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,12 @@
44
See README.rst for details.
55
"""
66
from .transactions import function_trace, get_current_transaction, ignore_transaction, set_monitoring_transaction_name
7-
from .utils import accumulate, increment, set_custom_metric, set_custom_metrics_for_course_key
7+
# "set_custom_metric*" methods are deprecated
8+
from .utils import (
9+
accumulate,
10+
increment,
11+
set_custom_attribute,
12+
set_custom_attributes_for_course_key,
13+
set_custom_metric,
14+
set_custom_metrics_for_course_key
15+
)
Lines changed: 43 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
11
"""
2-
Middleware for code_owner custom metric
2+
Middleware for code_owner custom attribute
33
"""
44
import logging
5+
import warnings
56

67
from django.urls import resolve
78

8-
from edx_django_utils.monitoring import get_current_transaction, set_custom_metric
9+
from edx_django_utils.monitoring import get_current_transaction, set_custom_attribute
910

1011
from .utils import get_code_owner_from_module, is_code_owner_mappings_configured
1112

1213
log = logging.getLogger(__name__)
1314

1415

15-
class CodeOwnerMetricMiddleware:
16+
class CodeOwnerMonitoringMiddleware:
1617
"""
17-
Django middleware object to set custom metrics for the owner of each view.
18+
Django middleware object to set custom attributes for the owner of each view.
1819
1920
For instructions on usage, see:
20-
https://github.com/edx/edx-django-utils/blob/master/edx_django_utils/monitoring/docs/how_tos/add_code_owner_custom_metric_to_an_ida.rst
21+
https://github.com/edx/edx-django-utils/blob/master/edx_django_utils/monitoring/docs/how_tos/add_code_owner_custom_attribute_to_an_ida.rst
2122
22-
Custom metrics set:
23+
Custom attributes set:
2324
- code_owner: The owning team mapped to the current view.
2425
- code_owner_mapping_error: If there are any errors when trying to perform the mapping.
2526
- code_owner_path_error: The error mapping by path, if code_owner isn't found in other ways.
@@ -35,58 +36,58 @@ def __init__(self, get_response):
3536

3637
def __call__(self, request):
3738
response = self.get_response(request)
38-
self._set_code_owner_metric(request)
39+
self._set_code_owner_attribute(request)
3940
return response
4041

4142
def process_exception(self, request, exception):
42-
self._set_code_owner_metric(request)
43+
self._set_code_owner_attribute(request)
4344

44-
def _set_code_owner_metric(self, request):
45+
def _set_code_owner_attribute(self, request):
4546
"""
46-
Sets the code_owner custom metric, as well as several supporting custom metrics.
47+
Sets the code_owner custom attribute, as well as several supporting custom attributes.
4748
48-
See CodeOwnerMetricMiddleware docstring for a complete list of metrics.
49+
See CodeOwnerMonitoringMiddleware docstring for a complete list of attributes.
4950
5051
"""
51-
code_owner, path_error = self._set_code_owner_metric_from_path(request)
52+
code_owner, path_error = self._set_code_owner_attribute_from_path(request)
5253
if code_owner:
53-
set_custom_metric('code_owner', code_owner)
54+
set_custom_attribute('code_owner', code_owner)
5455
return
5556
if not path_error:
5657
# module found, but mapping wasn't configured
57-
code_owner = self._set_code_owner_metric_catch_all()
58+
code_owner = self._set_code_owner_attribute_catch_all()
5859
if code_owner:
59-
set_custom_metric('code_owner', code_owner)
60+
set_custom_attribute('code_owner', code_owner)
6061
return
6162

62-
code_owner, transaction_error = self._set_code_owner_metric_from_current_transaction(request)
63+
code_owner, transaction_error = self._set_code_owner_attribute_from_current_transaction(request)
6364
if code_owner:
64-
set_custom_metric('code_owner', code_owner)
65+
set_custom_attribute('code_owner', code_owner)
6566
return
6667
if not transaction_error:
6768
# transaction name found, but mapping wasn't configured
68-
code_owner = self._set_code_owner_metric_catch_all()
69+
code_owner = self._set_code_owner_attribute_catch_all()
6970
if code_owner:
70-
set_custom_metric('code_owner', code_owner)
71+
set_custom_attribute('code_owner', code_owner)
7172
return
7273

73-
code_owner = self._set_code_owner_metric_catch_all()
74+
code_owner = self._set_code_owner_attribute_catch_all()
7475
if code_owner:
75-
set_custom_metric('code_owner', code_owner)
76+
set_custom_attribute('code_owner', code_owner)
7677
return
7778

7879
# only report errors if code_owner couldn't be found, including catch-all
7980
if path_error:
80-
set_custom_metric('code_owner_path_error', path_error)
81+
set_custom_attribute('code_owner_path_error', path_error)
8182
if transaction_error:
82-
set_custom_metric('code_owner_transaction_error', transaction_error)
83+
set_custom_attribute('code_owner_transaction_error', transaction_error)
8384

84-
def _set_code_owner_metric_from_path(self, request):
85+
def _set_code_owner_attribute_from_path(self, request):
8586
"""
86-
Uses the request path to find the view_func and then sets code owner metrics based on the view.
87+
Uses the request path to find the view_func and then sets code owner attributes based on the view.
8788
8889
Side-effects:
89-
Sets code_owner_path_module custom metric, used to determine code_owner
90+
Sets code_owner_path_module custom attribute, used to determine code_owner
9091
9192
Returns:
9293
(str, str): (code_owner, error_message), where at least one of these should be None
@@ -98,18 +99,18 @@ def _set_code_owner_metric_from_path(self, request):
9899
try:
99100
view_func, _, _ = resolve(request.path)
100101
path_module = view_func.__module__
101-
set_custom_metric('code_owner_path_module', path_module)
102+
set_custom_attribute('code_owner_path_module', path_module)
102103
code_owner = get_code_owner_from_module(path_module)
103104
return code_owner, None
104105
except Exception as e: # pylint: disable=broad-except
105106
return None, str(e)
106107

107-
def _set_code_owner_metric_from_current_transaction(self, request):
108+
def _set_code_owner_attribute_from_current_transaction(self, request):
108109
"""
109-
Uses the current transaction name to set the code owner metric.
110+
Uses the current transaction name to set the code owner attribute.
110111
111112
Side-effects:
112-
Sets code_owner_transaction_name custom metric, used to determine code_owner
113+
Sets code_owner_transaction_name custom attribute, used to determine code_owner
113114
114115
Returns:
115116
(str, str): (code_owner, error_message), where at least one of these should be None
@@ -123,14 +124,14 @@ def _set_code_owner_metric_from_current_transaction(self, request):
123124
transaction_name = get_current_transaction().name
124125
if not transaction_name:
125126
return None, 'No current transaction name found.'
126-
set_custom_metric('code_owner_transaction_name', transaction_name)
127+
set_custom_attribute('code_owner_transaction_name', transaction_name)
127128
module_name = transaction_name.split(':')[0]
128129
code_owner = get_code_owner_from_module(module_name)
129130
return code_owner, None
130131
except Exception as e: # pylint: disable=broad-except
131132
return None, str(e)
132133

133-
def _set_code_owner_metric_catch_all(self):
134+
def _set_code_owner_attribute_catch_all(self):
134135
"""
135136
If the catch-all module "*" is configured, return the code_owner.
136137
@@ -146,3 +147,13 @@ def _set_code_owner_metric_catch_all(self):
146147
return code_owner
147148
except Exception: # pylint: disable=broad-except; #pragma: no cover
148149
return None
150+
151+
152+
class CodeOwnerMetricMiddleware(CodeOwnerMonitoringMiddleware):
153+
"""
154+
Deprecated class for handling middleware. Class has been renamed to CodeOwnerMonitoringMiddleware.
155+
"""
156+
def __init__(self, *args, **kwargs): # pragma: no cover
157+
super(CodeOwnerMetricMiddleware, self).__init__(*args, **kwargs)
158+
msg = "Use 'CodeOwnerMonitoringMiddleware' in place of 'CodeOwnerMetricMiddleware'."
159+
warnings.warn(msg, DeprecationWarning)

0 commit comments

Comments
 (0)