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
ead5b590
Commit
ead5b590
authored
Jan 04, 2017
by
David Ormsbee
Committed by
GitHub
Jan 04, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #14211 from edx/ormsbee/remove_dd_metrics
Remove Datadog instrumentation around model saves
parents
74a0d769
eaa2b9e7
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
0 additions
and
136 deletions
+0
-136
openedx/core/djangoapps/monitoring/signals.py
+0
-135
openedx/core/djangoapps/monitoring/startup.py
+0
-1
No files found.
openedx/core/djangoapps/monitoring/signals.py
deleted
100644 → 0
View file @
74a0d769
"""
Add receivers for django signals, and feed data into the monitoring system.
If a model has a class attribute 'METRIC_TAGS' that is a list of strings,
those fields will be retrieved from the model instance, and added as tags to
the recorded metrics.
"""
from
django.db.models.signals
import
post_save
,
post_delete
,
m2m_changed
,
post_init
from
django.dispatch
import
receiver
import
dogstats_wrapper
as
dog_stats_api
def
_database_tags
(
action
,
sender
,
kwargs
):
# pylint: disable=unused-argument
"""
Return a tags for the sender and database used in django.db.models signals.
Arguments:
action (str): What action is being performed on the db model.
sender (Model): What model class is the action being performed on.
kwargs (dict): The kwargs passed by the model signal.
"""
tags
=
_model_tags
(
kwargs
,
'instance'
)
tags
.
append
(
u'action:{}'
.
format
(
action
))
if
'using'
in
kwargs
:
tags
.
append
(
u'database:{}'
.
format
(
kwargs
[
'using'
]))
return
tags
def
_model_tags
(
kwargs
,
key
):
"""
Return a list of all tags for all attributes in kwargs[key].MODEL_TAGS,
plus a tag for the model class.
"""
if
key
not
in
kwargs
:
return
[]
instance
=
kwargs
[
key
]
tags
=
[
u'{}.{}:{}'
.
format
(
key
,
attr
,
getattr
(
instance
,
attr
))
for
attr
in
getattr
(
instance
,
'MODEL_TAGS'
,
[])
]
tags
.
append
(
u'model_class:{}'
.
format
(
instance
.
__class__
.
__name__
))
return
tags
@receiver
(
post_init
,
dispatch_uid
=
'edxapp.monitoring.post_init_metrics'
)
def
post_init_metrics
(
sender
,
**
kwargs
):
"""
Record the number of times that django models are instantiated.
Args:
sender (Model): The model class sending the signals.
using (str): The name of the database being used for this initialization (optional).
instance (Model instance): The instance being initialized (optional).
"""
tags
=
_database_tags
(
'initialized'
,
sender
,
kwargs
)
dog_stats_api
.
increment
(
'edxapp.db.model'
,
tags
=
tags
)
@receiver
(
post_save
,
dispatch_uid
=
'edxapp.monitoring.post_save_metrics'
)
def
post_save_metrics
(
sender
,
**
kwargs
):
"""
Record the number of times that django models are saved (created or updated).
Args:
sender (Model): The model class sending the signals.
using (str): The name of the database being used for this update (optional).
instance (Model instance): The instance being updated (optional).
"""
action
=
'created'
if
kwargs
.
pop
(
'created'
,
False
)
else
'updated'
tags
=
_database_tags
(
action
,
sender
,
kwargs
)
dog_stats_api
.
increment
(
'edxapp.db.model'
,
tags
=
tags
)
@receiver
(
post_delete
,
dispatch_uid
=
'edxapp.monitoring.post_delete_metrics'
)
def
post_delete_metrics
(
sender
,
**
kwargs
):
"""
Record the number of times that django models are deleted.
Args:
sender (Model): The model class sending the signals.
using (str): The name of the database being used for this deletion (optional).
instance (Model instance): The instance being deleted (optional).
"""
tags
=
_database_tags
(
'deleted'
,
sender
,
kwargs
)
dog_stats_api
.
increment
(
'edxapp.db.model'
,
tags
=
tags
)
@receiver
(
m2m_changed
,
dispatch_uid
=
'edxapp.monitoring.m2m_changed_metrics'
)
def
m2m_changed_metrics
(
sender
,
**
kwargs
):
"""
Record the number of times that Many2Many fields are updated. This is separated
from post_save and post_delete, because it's signaled by the database model in
the middle of the Many2Many relationship, rather than either of the models
that are the relationship participants.
Args:
sender (Model): The model class in the middle of the Many2Many relationship.
action (str): The action being taken on this Many2Many relationship.
using (str): The name of the database being used for this deletion (optional).
instance (Model instance): The instance whose many-to-many relation is being modified.
model (Model class): The model of the class being added/removed/cleared from the relation.
"""
if
'action'
not
in
kwargs
:
return
action
=
{
'post_add'
:
'm2m.added'
,
'post_remove'
:
'm2m.removed'
,
'post_clear'
:
'm2m.cleared'
,
}
.
get
(
kwargs
[
'action'
])
if
not
action
:
return
tags
=
_database_tags
(
action
,
sender
,
kwargs
)
if
'model'
in
kwargs
:
tags
.
append
(
'target_class:{}'
.
format
(
kwargs
[
'model'
]
.
__name__
))
pk_set
=
kwargs
.
get
(
'pk_set'
,
[])
or
[]
dog_stats_api
.
increment
(
'edxapp.db.model'
,
value
=
len
(
pk_set
),
tags
=
tags
)
openedx/core/djangoapps/monitoring/startup.py
View file @
ead5b590
...
...
@@ -2,5 +2,4 @@
Registers signal handlers at startup.
"""
# pylint: disable=unused-import
import
openedx.core.djangoapps.monitoring.signals
import
openedx.core.djangoapps.monitoring.exceptions
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