Commit Graph

22 Commits

Author SHA1 Message Date
Usama Sadiq
8de47ef51f refactor: Ran pyupgrade on openedx/core
Ran pyupgrade on openedx/core/{djangolib, lib}
2021-04-08 18:34:24 +05:00
Robert Raposa
d4bbd9d03e fix: move ignored error message custom attribute (#27047)
The `error_expected` custom attribute used to contain
both the class name and the error message. This had
the following issues:

* Combining data in the same custom attribute limits
the ability to query.
* The additional error class and message data is only
needed for ignored errors, since this data isn't
available elsewhere.

The following changes were made:
* `error_expected` will always have the value True
if present.
* `error_ignored` no longer exists.
* `error_ignored_class` will contain the error module
and class for ignored errors.
* `error_ignored_message` will contain the error message
for ignored errors.

ARCHBOM-1708
2021-03-18 10:37:47 -04:00
Robert Raposa
2c0a8242f7 ARCHBOM-1708: feat: monitor and log expected errors (#26980)
Adds logging and monitoring capabilities for expected
errors. See the ADR and how-to  documentation for
details of how to configure and use the EXPECTED_ERRORS
setting and new monitoring and logging.

ARCHBOM-1708

Co-authored-by: Tim McCormack <tmccormack@edx.org>
2021-03-17 07:27:13 -04:00
Feanil Patel
d2343b1f07 doc: Correctly annotate the setting name.
The `setting_name` annotation needed a space before it so that it's
picked up properly by the toggle annotations tooling.
2021-03-01 16:35:41 -05:00
David Ormsbee
843668a011 Revert "feat: 403 logging for exchange_access_token (#26511)" (#26608)
This reverts commit 0517603b6d.

This was masking a LabXchange error by blowing up with:
"Stack trace builtins:AttributeError: 'NoneType' object has no attribute 'status_code'"
2021-02-17 17:08:44 -05:00
Robert Raposa
0517603b6d feat: 403 logging for exchange_access_token (#26511)
The mobile app is getting unexpected 403s from
/oauth2/exchange_access_token/, but we have been unable
to pinpoint from where they are coming. This commit
introduces a temporary exception handler to provide stack info
for 403s on this endpoint to try to track down the source.

Requires the ENABLE_403_MONITORING setting to be set to
True to enable the logging.

ARCHBOM-1667
2021-02-12 15:34:55 -05:00
Robert Raposa
cf626667d6 annotate cookie monitoring toggle
* Annotate cookie monitoring toggle and settings.
* Refactor to replace LegacyWaffleFlag.
2021-01-25 14:42:44 -05:00
Robert Raposa
8b4ea05d5e fix cookie monitoring middleware
The cases of no cookies or no cookie groups
found would cause an error. This was fixed
and additional test coverage was added.
2021-01-15 15:07:22 -05:00
Feanil Patel
e5e2b7f7b6 Only capture the top N cookies and cookie groups.
Instead of adding new attributes for each cookie name we create
consistent attribute names.  This should prevent any issues where we
have too many different unique attribute names because the cookie names
are unique to the user.

We added two new settings to make the number of cookies and groups
capture configurable:

- TOP_N_COOKIES_CAPTURED
- TOP_N_COOKIE_GROUPS_CAPTURED
2021-01-14 15:49:15 -05:00
Feanil Patel
1a1da89f55 Drop setting attributes for the size of each cookie.
Setting a new metric per cookie name resulted in a lot of metrics
getting added to New Relic.  In some cases, this was causing other
more important metrics to not get registered.
2021-01-14 11:03:28 -05:00
Feanil Patel
1ae50fc466 Add more cookie logging code.
We want to be able to easily figure out what our biggest cookies are and we
want to also group cookies by prefix because certain services create multiple
cookies and then put unique identifiers in the cookie name.

For example braze cookie names use the following pattern:
    ab.storage.<userId>
    ab.storage.<deviceId>
    ab.storage.<sessionId>

In this case we want to group all the `ab` cookies together so we can see
their total size.

New attributes:

cookies.<group_prefix>.group.size: The size of a group of cookies. For example
	the sum of the size of all braze cookies would be the value of the
	`cookies.ab.group.size` attribute.
cookies.max.name: The name of the largest cookie sent by the user.
cookies.max.size: The size of the largest cookie sent by the user.
cookies.max.group.name: The name of the largest group of cookies. A single cookie
	counts as a group of one for this calculation.
cookies.max.group.size: The sum total size of all the cookies in the largest group.
2021-01-14 09:55:49 -05:00
Régis Behmo
a16cd71046 Start waffle namespace deprecation
By explicitly importing the legacy namespace classes, we make it clear
that we are using soon-to-be-deprecated classes. We will then be able to
start removing the legacy classes, one module at a time.
2020-12-03 16:06:14 +01:00
Régis Behmo
4586002956 Import waffle classes from edx_toggles instead of waffle_utils
Those classes were ported to edx_toggles. The imports remain in
waffle_utils.__init__ for backward compatibility.
2020-11-03 19:25:37 +01:00
Tim McCormack
92135ad567 Avoid direct use of newrelic (while we're in there) 2020-09-22 23:25:50 +00:00
Tim McCormack
0f33afc20a Fix my weird typo 2020-09-22 22:59:28 +00:00
Tim McCormack
328e790e8a Rename CookieMetricsMiddleware to CookingMonitoringMiddleware
This fixes a misuse of New Relic terminology. Here we are in fact using
custom attributes; custom metrics are a different thing that we may start
using in the future.
2020-09-18 14:25:50 +00:00
Régis Behmo
307457a255 Simplify hack to obtain waffle module names
Instead of going up the stacktrace to find the module names of waffle
flags and switches, we manually pass the module __name__ whenever the
flag is created. This is similar to `logging.getLogger(__name__)`
standard behaviour.

As the waffle classes are used outside of edx-platform, we make the new
module_name argument an optional keyword argument. This will change once
we pull waffle_utils outside of edx-platform.

Note that the module name is normally only required to view the list of
existing waffle flags and switches. The module name should not be
necessary to verify if a flag is enabled. Thus, maybe it would make
sense to create a `add` class methor similar to:

    class WaffleFlag:
        @classmethod
        def add(cls, namespace, flag, module):
            instance = cls(namespace, flag)
            cls._class_instances.add((instance, module))
2020-09-14 09:30:24 +02:00
Aarif
6ee2089077 fixed warnings for wrong-import-order 2020-04-08 23:43:06 +05:00
Feanil Patel
9cf2f9f298 Run 2to3 -f future . -w
This will remove imports from __future__ that are no longer needed.

https://docs.python.org/3.5/library/2to3.html#2to3fixer-future
2019-12-30 10:35:30 -05:00
Andrés González
26b3a40133 INCR-108 (#20058)
* INCR-108: Run python-modernize on openedx/core/lib

* Fixed urlencode import

* Fixed diff quality warnings and six.string_types error

* Fixed pickle import

* Fixed iteritems import

* Fixed ungrouped imports

* Fixed six.moves import issues
2019-04-02 10:26:00 -04:00
David Ormsbee
76620e0bf2 Add cookie size monitoring New Relic metrics.
This adds middleware that will create custom parameter metrics in
New Relic to track the size of all the cookies being received for
our domain. The custom fields are "cookies_total_size" and a
separate named parameter for every cookie size, e.g.
"cookies.csrftoken.size".

This is intended to help us track cookie growth and better diagnose
issues where users lose their sessions. It is toggled by the
'request_utils.capture_cookie_sizes' Waffle Flag.
2019-02-22 18:18:41 -05:00
Nimisha Asthagiri
700a902b68 Cleanup and remove deprecated RequestCache Django app
ARCH-223
2018-09-12 14:39:11 -04:00