From 65433c9cd419f80ecbbd3372ab5dc86124e07167 Mon Sep 17 00:00:00 2001 From: John Eskew Date: Thu, 2 Nov 2017 17:07:16 -0400 Subject: [PATCH 1/2] Move datadog startup.py over to AppConfig::ready --- cms/envs/common.py | 2 +- lms/envs/common.py | 2 +- openedx/core/djangoapps/datadog/apps.py | 32 ++++++++++++++++++++++ openedx/core/djangoapps/datadog/startup.py | 27 ------------------ 4 files changed, 34 insertions(+), 29 deletions(-) create mode 100644 openedx/core/djangoapps/datadog/apps.py delete mode 100644 openedx/core/djangoapps/datadog/startup.py diff --git a/cms/envs/common.py b/cms/envs/common.py index 0e3caa4979..5857fa6ba4 100644 --- a/cms/envs/common.py +++ b/cms/envs/common.py @@ -963,7 +963,7 @@ INSTALLED_APPS = [ 'eventtracking.django.apps.EventTrackingConfig', # Monitoring - 'openedx.core.djangoapps.datadog', + 'openedx.core.djangoapps.datadog.apps.DatadogConfig', # For asset pipelining 'edxmako.apps.EdxMakoConfig', diff --git a/lms/envs/common.py b/lms/envs/common.py index 378680e1f6..bbba794cc7 100644 --- a/lms/envs/common.py +++ b/lms/envs/common.py @@ -2158,7 +2158,7 @@ INSTALLED_APPS = [ 'splash', # Monitoring - 'openedx.core.djangoapps.datadog', + 'openedx.core.djangoapps.datadog.apps.DatadogConfig', # User API 'rest_framework', diff --git a/openedx/core/djangoapps/datadog/apps.py b/openedx/core/djangoapps/datadog/apps.py new file mode 100644 index 0000000000..b14d1ebb1a --- /dev/null +++ b/openedx/core/djangoapps/datadog/apps.py @@ -0,0 +1,32 @@ +""" +Configuration for datadog Django app +""" +from django.apps import AppConfig +from django.conf import settings +from dogapi import dog_http_api, dog_stats_api + + +class DatadogConfig(AppConfig): + """ + Configuration class for datadog Django app + """ + name = 'openedx.core.djangoapps.datadog' + verbose_name = "Datadog" + + def ready(self): + """ + Initialize connection to datadog during django startup. + + Configure using DATADOG dictionary in the django project settings. + """ + # By default use the statsd agent + options = {'statsd': True} + + if hasattr(settings, 'DATADOG'): + options.update(settings.DATADOG) + + # Not all arguments are documented. + # Look at the source code for details. + dog_stats_api.start(**options) + + dog_http_api.api_key = options.get('api_key') diff --git a/openedx/core/djangoapps/datadog/startup.py b/openedx/core/djangoapps/datadog/startup.py deleted file mode 100644 index 8c02244742..0000000000 --- a/openedx/core/djangoapps/datadog/startup.py +++ /dev/null @@ -1,27 +0,0 @@ -""" -Start up initialization of datadog. -""" -from django.conf import settings -from dogapi import dog_http_api, dog_stats_api - - -def run(): - """ - Initialize connection to datadog during django startup. - - Can be configured using a dictionary named DATADOG in the django - project settings. - - """ - - # By default use the statsd agent - options = {'statsd': True} - - if hasattr(settings, 'DATADOG'): - options.update(settings.DATADOG) - - # Not all arguments are documented. - # Look at the source code for details. - dog_stats_api.start(**options) - - dog_http_api.api_key = options.get('api_key') From d7bab033f7504c596afda424831590cd8c5961d9 Mon Sep 17 00:00:00 2001 From: John Eskew Date: Thu, 2 Nov 2017 17:28:13 -0400 Subject: [PATCH 2/2] Move monitoring functionality to util and AppConfig. --- cms/envs/common.py | 3 --- lms/envs/common.py | 3 --- openedx/core/djangoapps/monitoring/README.rst | 6 ------ openedx/core/djangoapps/monitoring/__init__.py | 0 openedx/core/djangoapps/monitoring/startup.py | 5 ----- openedx/core/djangoapps/util/apps.py | 9 ++++++++- .../{monitoring/exceptions.py => util/signals.py} | 0 7 files changed, 8 insertions(+), 18 deletions(-) delete mode 100644 openedx/core/djangoapps/monitoring/README.rst delete mode 100644 openedx/core/djangoapps/monitoring/__init__.py delete mode 100644 openedx/core/djangoapps/monitoring/startup.py rename openedx/core/djangoapps/{monitoring/exceptions.py => util/signals.py} (100%) diff --git a/cms/envs/common.py b/cms/envs/common.py index 5857fa6ba4..3de5453055 100644 --- a/cms/envs/common.py +++ b/cms/envs/common.py @@ -1006,9 +1006,6 @@ INSTALLED_APPS = [ # Signals 'openedx.core.djangoapps.signals.apps.SignalConfig', - # Monitoring signals - 'openedx.core.djangoapps.monitoring', - # Course action state 'course_action_state', diff --git a/lms/envs/common.py b/lms/envs/common.py index bbba794cc7..fa3961713b 100644 --- a/lms/envs/common.py +++ b/lms/envs/common.py @@ -2199,9 +2199,6 @@ INSTALLED_APPS = [ # Country embargo support 'openedx.core.djangoapps.embargo', - # Monitoring functionality - 'openedx.core.djangoapps.monitoring', - # Course action state 'course_action_state', diff --git a/openedx/core/djangoapps/monitoring/README.rst b/openedx/core/djangoapps/monitoring/README.rst deleted file mode 100644 index 4b7617d88b..0000000000 --- a/openedx/core/djangoapps/monitoring/README.rst +++ /dev/null @@ -1,6 +0,0 @@ -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. diff --git a/openedx/core/djangoapps/monitoring/__init__.py b/openedx/core/djangoapps/monitoring/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/openedx/core/djangoapps/monitoring/startup.py b/openedx/core/djangoapps/monitoring/startup.py deleted file mode 100644 index 108f290772..0000000000 --- a/openedx/core/djangoapps/monitoring/startup.py +++ /dev/null @@ -1,5 +0,0 @@ -""" -Registers signal handlers at startup. -""" -# pylint: disable=unused-import -import openedx.core.djangoapps.monitoring.exceptions diff --git a/openedx/core/djangoapps/util/apps.py b/openedx/core/djangoapps/util/apps.py index 2fc4224a0b..852f4dbd09 100644 --- a/openedx/core/djangoapps/util/apps.py +++ b/openedx/core/djangoapps/util/apps.py @@ -7,8 +7,15 @@ from django.apps import AppConfig class UtilConfig(AppConfig): """ - Let Django know that this is an app with management commands. + Configuration class for the openedx.core.djangoapps.util Django application """ label = 'open_edx_util' name = 'openedx.core.djangoapps.util' verbose_name = 'Open edX Utilities' + + def ready(self): + """ + Registers signal handlers at startup. + """ + # pylint: disable=unused-import + import openedx.core.djangoapps.util.signals diff --git a/openedx/core/djangoapps/monitoring/exceptions.py b/openedx/core/djangoapps/util/signals.py similarity index 100% rename from openedx/core/djangoapps/monitoring/exceptions.py rename to openedx/core/djangoapps/util/signals.py