Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
77f111b2
Commit
77f111b2
authored
Mar 31, 2017
by
Robert Raposa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Moves and rename common/djangoapps/newrelic_custom_metrics.
parent
d9562077
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
49 additions
and
37 deletions
+49
-37
common/djangoapps/student/views.py
+2
-3
lms/djangoapps/courseware/user_state_client.py
+4
-4
lms/envs/common.py
+1
-1
openedx/core/djangoapps/monitoring/README.rst
+6
-0
openedx/core/djangoapps/monitoring_utils/__init__.py
+16
-13
openedx/core/djangoapps/monitoring_utils/middleware.py
+7
-4
openedx/core/djangoapps/monitoring_utils/tests.py
+13
-12
No files found.
common/djangoapps/student/views.py
View file @
77f111b2
...
...
@@ -89,6 +89,7 @@ from openedx.core.djangoapps.external_auth.login_and_register import (
login
as
external_auth_login
,
register
as
external_auth_register
)
from
openedx.core.djangoapps
import
monitoring_utils
import
track.views
...
...
@@ -120,8 +121,6 @@ from openedx.core.djangoapps.embargo import api as embargo_api
import
analytics
from
eventtracking
import
tracker
import
newrelic_custom_metrics
# Note that this lives in LMS, so this dependency should be refactored.
from
notification_prefs.views
import
enable_notifications
...
...
@@ -654,7 +653,7 @@ def dashboard(request):
# Record how many courses there are so that we can get a better
# understanding of usage patterns on prod.
newrelic_custom_metric
s
.
accumulate
(
'num_courses'
,
len
(
course_enrollments
))
monitoring_util
s
.
accumulate
(
'num_courses'
,
len
(
course_enrollments
))
# sort the enrollment pairs by the enrollment date
course_enrollments
.
sort
(
key
=
lambda
x
:
x
.
created
,
reverse
=
True
)
...
...
lms/djangoapps/courseware/user_state_client.py
View file @
77f111b2
...
...
@@ -12,7 +12,6 @@ try:
except
ImportError
:
import
json
import
newrelic_custom_metrics
import
dogstats_wrapper
as
dog_stats_api
from
django.contrib.auth.models
import
User
from
django.db
import
transaction
...
...
@@ -20,6 +19,7 @@ from django.db.utils import IntegrityError
from
xblock.fields
import
Scope
from
courseware.models
import
StudentModule
,
BaseStudentModuleHistory
from
edx_user_state_client.interface
import
XBlockUserStateClient
,
XBlockUserState
from
openedx.core.djangoapps
import
monitoring_utils
log
=
logging
.
getLogger
(
__name__
)
...
...
@@ -136,7 +136,7 @@ class DjangoXBlockUserStateClient(XBlockUserStateClient):
"""
Accumulate arbitrary NR stats (not specific to block types).
"""
newrelic_custom_metric
s
.
accumulate
(
monitoring_util
s
.
accumulate
(
self
.
_nr_metric_name
(
function_name
,
stat_name
),
value
)
...
...
@@ -151,11 +151,11 @@ class DjangoXBlockUserStateClient(XBlockUserStateClient):
"""
Accumulate NR stats related to block types.
"""
newrelic_custom_metric
s
.
accumulate
(
monitoring_util
s
.
accumulate
(
self
.
_nr_metric_name
(
function_name
,
stat_name
),
value
,
)
newrelic_custom_metric
s
.
accumulate
(
monitoring_util
s
.
accumulate
(
self
.
_nr_metric_name
(
function_name
,
stat_name
,
block_type
=
block_type
),
value
,
)
...
...
lms/envs/common.py
View file @
77f111b2
...
...
@@ -1109,7 +1109,7 @@ MIDDLEWARE_CLASSES = (
'crum.CurrentRequestUserMiddleware'
,
'request_cache.middleware.RequestCache'
,
'
newrelic_custom_metrics.middleware.NewRelic
CustomMetrics'
,
'
openedx.core.djangoapps.monitoring_utils.middleware.Monitoring
CustomMetrics'
,
'mobile_api.middleware.AppVersionUpgrade'
,
'openedx.core.djangoapps.header_control.middleware.HeaderControlMiddleware'
,
...
...
openedx/core/djangoapps/monitoring/README.rst
0 → 100644
View file @
77f111b2
This djangoapp is incorrectly named 'monitoring'.
The name is related to old functionality that used to be a part of this app.
TODO: The current contents of this app should be joined with other generic
platform utilities and renamed appropriately.
common/djangoapps/newrelic_custom_metric
s/__init__.py
→
openedx/core/djangoapps/monitoring_util
s/__init__.py
View file @
77f111b2
"""
This is an interface to the newrelic_custom_metrics middleware. Functions
defined in this module can be used to report custom metrics to New Relic. For
example:
This is an interface to the monitoring_utils middleware. Functions
defined in this module can be used to report monitoring custom metrics.
import newrelic_custom_metrics
Usage:
from openedx.core.djangoapps import monitoring_utils
...
newrelic_custom_metric
s.accumulate('xb_user_state.get_many.num_items', 4)
monitoring_util
s.accumulate('xb_user_state.get_many.num_items', 4)
There is no need to do anything else. The metrics are automatically cleared
before the next request.
...
...
@@ -14,24 +15,26 @@ We try to keep track of our custom metrics at:
https://openedx.atlassian.net/wiki/display/PERF/Custom+Metrics+in+New+Relic
At this time, these custom metrics will only be reported to New Relic.
TODO: supply additional public functions for storing strings and booleans.
"""
from
newrelic_custom_metrics
import
middleware
"""
from
.
import
middleware
def
accumulate
(
name
,
value
):
"""
Accumulate
custom New Relic
metric for the current request.
Accumulate
monitoring custom
metric for the current request.
The named metric is accumulated by a numerical amount using the sum. All
metrics are queued up in the request_cache for this request. At the end of
the request, the
newrelic_custom_metric
s middleware will batch report all
queued accumulated metrics to
NR
.
the request, the
monitoring_util
s middleware will batch report all
queued accumulated metrics to
the monitoring tool (e.g. New Relic)
.
Arguments:
name (str): The metric name. It should be period-delimited, and
increase in specificty from left to right. For example:
increase in specific
i
ty from left to right. For example:
'xb_user_state.get_many.num_items'.
value (number): The amount to accumulate into the named metric. When
accumulate() is called multiple times for a given metric name
...
...
@@ -39,12 +42,12 @@ def accumulate(name, value):
for that metric. For metrics which don't make sense to accumulate,
make sure to only call this function once during a request.
"""
middleware
.
NewRelic
CustomMetrics
.
accumulate_metric
(
name
,
value
)
middleware
.
Monitoring
CustomMetrics
.
accumulate_metric
(
name
,
value
)
def
increment
(
name
):
"""
Increment a
custom New Relic
metric representing a counter.
Increment a
monitoring custom
metric representing a counter.
Here we simply accumulate a new custom metric with a value of 1, and the
middleware should automatically aggregate this metric.
...
...
common/djangoapps/newrelic_custom_metric
s/middleware.py
→
openedx/core/djangoapps/monitoring_util
s/middleware.py
View file @
77f111b2
"""
Middleware for handling the storage, aggregation, and reporing of custom New
Relic metrics.
Middleware for handling the storage, aggregation, and reporting of custom
metrics for monitoring.
At this time, the custom metrics can only reported to New Relic.
This middleware will only call on the newrelic agent if there are any metrics
to report for this request, so it will not incur any processing overhead for
request handlers which do not record custom metrics.
"""
import
logging
log
=
logging
.
getLogger
(
__name__
)
...
...
@@ -16,10 +19,10 @@ except ImportError:
import
request_cache
REQUEST_CACHE_KEY
=
'
newrelic
_custom_metrics'
REQUEST_CACHE_KEY
=
'
monitoring
_custom_metrics'
class
NewRelic
CustomMetrics
(
object
):
class
Monitoring
CustomMetrics
(
object
):
"""
The middleware class. Make sure to add below the request cache in
MIDDLEWARE_CLASSES.
...
...
common/djangoapps/newrelic_custom_metric
s/tests.py
→
openedx/core/djangoapps/monitoring_util
s/tests.py
View file @
77f111b2
"""
Tests for
newrelic
custom metrics.
Tests for
monitoring
custom metrics.
"""
from
django.test
import
TestCase
from
mock
import
patch
,
call
import
newrelic_custom_metrics
from
openedx.core.djangoapps
import
monitoring_utils
from
openedx.core.djangoapps.monitoring_utils.middleware
import
MonitoringCustomMetrics
class
Test
NewRelic
CustomMetrics
(
TestCase
):
class
Test
Monitoring
CustomMetrics
(
TestCase
):
"""
Test the
newrelic_custom_metric
s middleware and helpers
Test the
monitoring_util
s middleware and helpers
"""
@patch
(
'newrelic.agent'
)
def
test_c
ache_normal_contents
(
self
,
mock_newrelic_agent
):
def
test_c
ustom_metrics_with_new_relic
(
self
,
mock_newrelic_agent
):
"""
Test normal usage of collecting
and reporting custom New Relic metrics
Test normal usage of collecting
custom metrics and reporting to New Relic
"""
newrelic_custom_metric
s
.
accumulate
(
'hello'
,
10
)
newrelic_custom_metric
s
.
accumulate
(
'world'
,
10
)
newrelic_custom_metric
s
.
accumulate
(
'world'
,
10
)
newrelic_custom_metric
s
.
increment
(
'foo'
)
newrelic_custom_metric
s
.
increment
(
'foo'
)
monitoring_util
s
.
accumulate
(
'hello'
,
10
)
monitoring_util
s
.
accumulate
(
'world'
,
10
)
monitoring_util
s
.
accumulate
(
'world'
,
10
)
monitoring_util
s
.
increment
(
'foo'
)
monitoring_util
s
.
increment
(
'foo'
)
# based on the metric data above, we expect the following calls to newrelic:
nr_agent_calls_expected
=
[
...
...
@@ -31,7 +32,7 @@ class TestNewRelicCustomMetrics(TestCase):
]
# fake a response to trigger metrics reporting
newrelic_custom_metrics
.
middleware
.
NewRelic
CustomMetrics
()
.
process_response
(
Monitoring
CustomMetrics
()
.
process_response
(
'fake request'
,
'fake response'
,
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment