Skip to content

Commit

Permalink
Merge branch 'master' into hamzawaleed01/upgrade-edx-enterprise-70f6f5a
Browse files Browse the repository at this point in the history
  • Loading branch information
hamzawaleed01 authored Oct 4, 2023
2 parents 2255be0 + d9af2df commit 4887f7a
Show file tree
Hide file tree
Showing 10 changed files with 312 additions and 255 deletions.
6 changes: 3 additions & 3 deletions lms/envs/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -2188,8 +2188,8 @@ def _make_locale_paths(settings): # pylint: disable=missing-function-docstring
# Before anything that looks at cookies, especially the session middleware
'openedx.core.djangoapps.cookie_metadata.middleware.CookieNameChange',

# Monitoring and logging for expected and ignored errors
'openedx.core.lib.request_utils.ExpectedErrorMiddleware',
# Monitoring and logging for ignored errors
'openedx.core.lib.request_utils.IgnoredErrorMiddleware',

'lms.djangoapps.mobile_api.middleware.AppVersionUpgrade',
'openedx.core.djangoapps.header_control.middleware.HeaderControlMiddleware',
Expand Down Expand Up @@ -3330,7 +3330,7 @@ def _make_locale_paths(settings): # pylint: disable=missing-function-docstring
'DEFAULT_RENDERER_CLASSES': (
'rest_framework.renderers.JSONRenderer',
),
'EXCEPTION_HANDLER': 'openedx.core.lib.request_utils.expected_error_exception_handler',
'EXCEPTION_HANDLER': 'openedx.core.lib.request_utils.ignored_error_exception_handler',
'PAGE_SIZE': 10,
'URL_FORMAT_OVERRIDE': None,
'DEFAULT_THROTTLE_RATES': {
Expand Down
30 changes: 26 additions & 4 deletions lms/static/js/learner_dashboard/spec/program_details_view_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,28 @@ describe('Program Details View', () => {
.toContainText(body);
};

const testSubscriptionSunsetting = (state, heading, body) => {
const subscriptionData = {
...options.subscriptionData[0],
subscription_state: state,
};
// eslint-disable-next-line no-use-before-define
view = initView({
// eslint-disable-next-line no-undef
programData: $.extend({}, options.programData, {
subscription_eligible: false,
}),
isUserB2CSubscriptionsEnabled: true,
subscriptionData: [subscriptionData],
});
view.render();
expect(view.$('.upgrade-subscription')[0]).not.toBeInDOM();
expect(view.$('.upgrade-subscription .upgrade-button')).not
.toContainText(heading);
expect(view.$('.upgrade-subscription .subscription-info-brief')).not
.toContainText(body);
};

const initView = (updates) => {
// eslint-disable-next-line no-undef
const viewOptions = $.extend({}, options, updates);
Expand Down Expand Up @@ -709,8 +731,8 @@ describe('Program Details View', () => {
);
});

it('should render the get subscription link if program is subscription eligible', () => {
testSubscriptionState(
it('should not render the get subscription link if program is not active', () => {
testSubscriptionSunsetting(
'pre',
'Start 7-day free trial',
'$100/month USD subscription after trial ends. Cancel anytime.',
Expand All @@ -734,8 +756,8 @@ describe('Program Details View', () => {
);
});

it('should render appropriate subscription text when subscription is inactive', () => {
testSubscriptionState(
it('should not render appropriate subscription text when subscription is inactive', () => {
testSubscriptionSunsetting(
'inactive',
'Restart my subscription',
'$100/month USD subscription. Cancel anytime.',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,13 @@ class ProgramDetailsView extends Backbone.View {
&& this.remainingCourseCollection.length === 0
);

const isSubscriptionActiveSunsetting = (
this.subscriptionModel.get('subscriptionState') === 'active'
)

return (
this.options.isUserB2CSubscriptionsEnabled
&& this.options.programData.subscription_eligible
&& isSubscriptionActiveSunsetting
&& !programPurchasedWithoutSubscription
);
}
Expand Down
9 changes: 6 additions & 3 deletions openedx/core/djangoapps/enrollments/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1066,7 +1066,9 @@ def post(self, request):
**Example Request**
POST /api/enrollment/v1/enrollment_allowed
POST /api/enrollment/v1/enrollment_allowed/
Note: The URL for this request must finish with /
Example request data:
```
Expand All @@ -1086,7 +1088,6 @@ def post(self, request):
- `auto_enroll` (optional, bool: default=false, _body_)
**Responses**
- 200: Success, enrollment allowed found.
- 400: Bad request, missing data.
- 403: Forbidden, you need to be staff.
- 409: Conflict, enrollment allowed already exists.
Expand Down Expand Up @@ -1122,7 +1123,9 @@ def delete(self, request):
**Example Request**
DELETE /api/enrollment/v1/enrollment_allowed
DELETE /api/enrollment/v1/enrollment_allowed/
Note: The URL for this request must finish with /
Example request data:
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Logging and monitoring ignored errors
Status
------

Accepted
Partially Superseded (see 0002-logging-and-monitoring-expected-errors-removed.rst)

Context
-------
Expand All @@ -14,7 +14,7 @@ We had two recent Production issues that took longer than necessary to diagnose
Decision
________

Add a capability for logging and monitoring ignored errors and expected errors. The feature will be configurable, the monitoring will be available by default, and the logging will be opt-in as needed.
Add a capability for logging and monitoring ignored errors. The feature will be configurable, the monitoring will be available by default, and the logging will be opt-in as needed.

Note: This feature is being added to edx-platform to start, but could be moved to edx-django-utils monitoring for use in other IDAs.

Expand All @@ -23,6 +23,13 @@ Consequence

The new capabilities have been built in edx-platform, although they could be moved to edx-django-utils monitoring in the future for use in other IDAs.

The new feature adds the ability to mark errors as expected, temporarily or permanently, even without "ignoring" them everywhere. For example, the errors and stacktraces would still appear, but it would be possible for alert conditions to ignore expected errors.
The new feature adds the ability to mark errors as ignored, temporarily or permanently, even without "ignoring" them everywhere. For example, the errors and stacktraces would still appear, but it would be possible for alert conditions to ignore errors.

See how_tos/logging-and-monitoring-expected-errors.rst for more information.
See how_tos/logging-and-monitoring-ignored-errors.rst for more information.

Changelog
---------

* **2023-09-28** - Changed status to "Partially Superseded", because expected errors will no longer be handled. See 0002-logging-and-monitoring-expected-errors-removed.rst for details.

* **2021-03-17** - Original "Accepted" ADR
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
Logging and monitoring of expected errors removed
=================================================

Status
------

Accepted

Context
-------

The setting ``EXPECTED_ERRORS`` was used for both expected and ignored errors in edx-platform.

The functionality supporting expected errors was added:

* Because New Relic didn't yet support this for Python, and
* Because it was thought that people may want more flexibility for marking errors as expected in addition to just the class name, and
* The setting provides a place to document why the change is being made.

Updates regarding these three original reasons:

* New Relic now supports expected errors, so the custom functionality is redundant and complicated, and
* This functionality has yet to be used, so it is also unnecessary.

Note that the need for custom functionality for ignored errors differs from expected errors in the following ways:

* New Relic still has problems from time to time where it stops ignoring errors that it is supposed to be ignoring, and this redundant functionality is used to catch that issue, and
* Since New Relic does not capture details of ignored errors, the custom functionality to log these errors can still come in handy if more details are needed.

This context can also be found in `[DEPR] Expected error part of EXPECTED_ERRORS`_.

.. _[DEPR] Expected error part of EXPECTED_ERRORS: https://github.com/openedx/edx-platform/issues/32405

Decision
________

The custom ignored error functionality proposed in 0001-logging-and-monitoring-ignored-errors.rst will remain in place, but the custom expected error functionality will be removed.

Consequence
-----------

* A number of code changes are required to remove the expected functionality.

* In many placed in the code, "expected" was used to mean "ignored and expected", and all such instances will be renamed to "ignored".
* The setting ``EXPECTED_ERRORS`` will be renamed to ``IGNORED_ERRORS``, which better matches how it was being used in the first place.
* The setting ``EXPECTED_ERRORS[REASON_EXPECTED]`` will be renamed to ``IGNORED_ERRORS[REASON_IGNORED]``.
* The setting toggle ``EXPECTED_ERRORS[IS_IGNORED]`` will be removed, because it will now always be True.
* The how-to will be renamed to how_tos/logging-and-monitoring-ignored-errors.rst.
* For more details, see https://github.com/openedx/edx-platform/pull/33184 where this work is underway.

* If anyone ever uses New Relic's expected error functionality, the reason for marking an error as expected would need to be captured elsewhere.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
How to log and monitor ignored errors
======================================

What are ignored errors?
-------------------------------------

Operators of Open edX might use New Relic for monitoring, which can be configured to ignore errors. These errors get suppressed and leave no (stack) trace, and won't trigger error alerts.

Monitoring ignored errors
--------------------------

At a minimum, it is recommended that you add monitoring for any ignored errors. You do this by using the ``IGNORED_ERRORS`` setting. For details on configuring, see the documentation for `IGNORED_ERRORS settings and toggles on Readthedocs`_.

This will provide an ``error_ignored`` custom attribute for every ignored error. This custom attribute can be used in the following ways.

* Use ``SELECT * FROM TransactionError WHERE error_ignored IS True`` to find errors that should have been ignored, but are not. This may be due to a bug or misconfiguration in New Relic.

Additionally, a subset of ignored errors that are configured as ignored will also get ``error_ignored_class`` and ``error_ignored_message`` custom attributes.

* Using New Relic terminology, this extra error class and message data will live on the Transaction and not the TransactionError, because ignored errors won't have a TransactionError.
* Use these additional custom attributes to help diagnose unexpected issues with ignored errors.

.. _IGNORED_ERRORS settings and toggles on Readthedocs: https://edx.readthedocs.io/projects/edx-platform-technical/en/latest/search.html?q=IGNORED_ERRORS&check_keywords=yes&area=default

Logging ignored errors
-----------------------

Following the same documentation as for monitoring, you can also enable logging with or without a stack trace. This additional information may be useful for tracking down the source of a mysterious appearance of an otherwise ignored error.

More targeted scoping of errors
-------------------------------

The initial implementation only enables this functionality by error ``module.Class``. If you need to scope the monitoring/logging for a more limited subset, like for certain requests, the expectation would be to enhance and document these new capabilities.
Loading

0 comments on commit 4887f7a

Please sign in to comment.