Skip to content

Commit

Permalink
chore: deprecate edx-sphinx-theme
Browse files Browse the repository at this point in the history
  • Loading branch information
huniafatima-arbi committed Oct 29, 2024
1 parent 36bc403 commit ed51eb0
Show file tree
Hide file tree
Showing 25 changed files with 313 additions and 694 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ build/
.coverage
dist/
/pii_report/*.yaml
docs/_build
venv
41 changes: 41 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,47 @@ Change Log
Unreleased
~~~~~~~~~~

[5.0.0] - 2024-10-22
~~~~~~~~~~~~~~~~~~~~
Removed
-------
* Deleted Datadog diagnostics plugin app and middleware, which are no longer in use in edxapp.

[4.5.0] - 2024-09-19
~~~~~~~~~~~~~~~~~~~~
Added
-----
* Datadog diagnostics middleware can now attempt to close anomalous spans. Can be enabled via Waffle flag ``datadog.diagnostics.close_anomalous_spans`` (controlled separately from logging feature).

[4.4.0] - 2024-09-10
~~~~~~~~~~~~~~~~~~~~
Changed
-------
* Datadog diagnostics now logs ancestor spans when an anomaly is encountered, up to a limit of 10 (controlled by new Django setting ``DATADOG_DIAGNOSTICS_LOG_SPAN_DEPTH``). Spans are logged in full and on separate lines, so this logging is now much more verbose; consider only enabling this logging for short periods. Log format of first line has also changed slightly.

[4.3.0] - 2024-08-22
~~~~~~~~~~~~~~~~~~~~
Added
-----
* Added celery lifecycle logging for Datadog diagnostics, to be enabled using ``DATADOG_DIAGNOSTICS_CELERY_LOG_SIGNALS``.

[4.2.0] - 2024-08-13
~~~~~~~~~~~~~~~~~~~~
Fixed
-----
* Fixed loading of ``DATADOG_DIAGNOSTICS_ENABLE``, which was previously not loaded properly and therefore was always True. Also fixed loading of ``DATADOG_DIAGNOSTICS_MAX_SPANS``, which was presumably broken as well.

Removed
-------
* Removed early span-start logging. It never worked properly, possibly because workers are continually being destroyed and created, leading to high log volume.

[4.1.0] - 2024-08-09
~~~~~~~~~~~~~~~~~~~~
Changed
-------
* Datadog diagnostics will now log all span-starts for the first minute after server startup
* **WARNING**: Do not use this version; see 4.2.0 release notes.

[4.0.0] - 2024-08-05
~~~~~~~~~~~~~~~~~~~~
Changed
Expand Down
49 changes: 40 additions & 9 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
import re
import sys
from subprocess import check_call

import edx_theme
from datetime import datetime
import sphinx_book_theme
from django import setup as django_setup


Expand Down Expand Up @@ -59,7 +59,7 @@ def get_version(*file_paths):
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'edx_theme',
'sphinx_book_theme',
'sphinx.ext.autodoc',
'sphinx.ext.doctest',
'sphinx.ext.intersphinx',
Expand Down Expand Up @@ -90,8 +90,8 @@ def get_version(*file_paths):

# General information about the project.
project = 'edx-arch-experiments'
copyright = edx_theme.COPYRIGHT # pylint: disable=redefined-builtin
author = edx_theme.AUTHOR
copyright = f'{datetime.now().year}, edX Inc.' # pylint: disable=redefined-builtin
author ="edX Inc."
project_title = 'edx-arch-experiments'
documentation_title = f"{project_title}"

Expand Down Expand Up @@ -162,16 +162,47 @@ def get_version(*file_paths):
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.

html_theme = 'edx_theme'
html_theme = 'sphinx_book_theme'

# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
# documentation.
#
# html_theme_options = {}

# Add any paths that contain custom themes here, relative to this directory.
html_theme_path = [edx_theme.get_html_theme_path()]
html_theme_options = {

"repository_url": "https://github.com/edx/edx-arch-experiments",
"repository_branch": "main",
"path_to_docs": "docs/",
"use_repository_button": True,
"use_issues_button": True,
"use_edit_page_button": True,
# Please don't change unless you know what you're doing.
"extra_footer": """
<a rel="license" href="https://creativecommons.org/licenses/by-sa/4.0/">
<img
alt="Creative Commons License"
style="border-width:0"
src="https://i.creativecommons.org/l/by-sa/4.0/80x15.png"/>
</a>
<br>
These works by
<a
xmlns:cc="https://creativecommons.org/ns#"
href="https://edx.org"
property="cc:attributionName"
rel="cc:attributionURL"
>edX LLC</a>
are licensed under a
<a
rel="license"
href="https://creativecommons.org/licenses/by-sa/4.0/"
>Creative Commons Attribution-ShareAlike 4.0 International License</a>.
"""
}

html_logo = "https://logos.openedx.org/open-edx-logo-color.png"
html_favicon = "https://logos.openedx.org/open-edx-favicon.ico"

# The name for this set of Sphinx documents.
# "<project> v<release> documentation" by default.
Expand Down
2 changes: 1 addition & 1 deletion edx_arch_experiments/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
A plugin to include applications under development by the architecture team at 2U.
"""

__version__ = '4.0.0'
__version__ = '5.0.0'
6 changes: 0 additions & 6 deletions edx_arch_experiments/datadog_diagnostics/README.rst

This file was deleted.

Empty file.
74 changes: 0 additions & 74 deletions edx_arch_experiments/datadog_diagnostics/apps.py
Original file line number Diff line number Diff line change
@@ -1,74 +0,0 @@
"""
App for emitting additional diagnostic information for the Datadog integration.
"""

import logging

from django.apps import AppConfig
from django.conf import settings

log = logging.getLogger(__name__)


# .. toggle_name: DATADOG_DIAGNOSTICS_ENABLE
# .. toggle_implementation: DjangoSetting
# .. toggle_default: True
# .. toggle_description: Enables logging of Datadog diagnostics information.
# .. toggle_use_cases: circuit_breaker
# .. toggle_creation_date: 2024-07-11
# .. toggle_tickets: https://github.com/edx/edx-arch-experiments/issues/692
DATADOG_DIAGNOSTICS_ENABLE = getattr(settings, 'DATADOG_DIAGNOSTICS_ENABLE', True)

# .. setting_name: DATADOG_DIAGNOSTICS_MAX_SPANS
# .. setting_default: 100
# .. setting_description: Limit of how many spans to hold onto and log
# when diagnosing Datadog tracing issues. This limits memory consumption
# avoids logging more data than is actually needed for diagnosis.
DATADOG_DIAGNOSTICS_MAX_SPANS = getattr(settings, 'DATADOG_DIAGNOSTICS_MAX_SPANS', 100)


class MissingSpanProcessor:
"""Datadog span processor that logs unfinished spans at shutdown."""

def __init__(self):
self.spans_started = 0
self.spans_finished = 0
self.open_spans = {}

def on_span_start(self, span):
self.spans_started += 1
if len(self.open_spans) < DATADOG_DIAGNOSTICS_MAX_SPANS:
self.open_spans[span.span_id] = span

def on_span_finish(self, span):
self.spans_finished += 1
self.open_spans.pop(span.span_id, None) # "delete if present"

def shutdown(self, _timeout):
log.info(f"Spans created = {self.spans_started}; spans finished = {self.spans_finished}")
for span in self.open_spans.values():
log.error(f"Span created but not finished: {span._pprint()}") # pylint: disable=protected-access


class DatadogDiagnostics(AppConfig):
"""
Django application to log diagnostic information for Datadog.
"""
name = 'edx_arch_experiments.datadog_diagnostics'

# Mark this as a plugin app
plugin_app = {}

def ready(self):
if not DATADOG_DIAGNOSTICS_ENABLE:
return

try:
from ddtrace import tracer # pylint: disable=import-outside-toplevel
tracer._span_processors.append(MissingSpanProcessor()) # pylint: disable=protected-access
log.info("Attached MissingSpanProcessor for Datadog diagnostics")
except ImportError:
log.warning(
"Unable to attach MissingSpanProcessor for Datadog diagnostics"
" -- ddtrace module not found."
)
106 changes: 0 additions & 106 deletions edx_arch_experiments/datadog_diagnostics/middleware.py

This file was deleted.

Empty file.
51 changes: 0 additions & 51 deletions edx_arch_experiments/datadog_diagnostics/tests/test_app.py
Original file line number Diff line number Diff line change
@@ -1,51 +0,0 @@
"""
Tests for plugin app.
"""

from unittest.mock import patch

from django.test import TestCase

from .. import apps


class FakeSpan:
"""A fake Span instance that just carries a span_id."""
def __init__(self, span_id):
self.span_id = span_id

def _pprint(self):
return f"span_id={self.span_id}"


class TestMissingSpanProcessor(TestCase):
"""Tests for MissingSpanProcessor."""

@patch.object(apps, 'DATADOG_DIAGNOSTICS_MAX_SPANS', new=3)
def test_metrics(self):
proc = apps.MissingSpanProcessor()
ids = [2, 4, 6, 8, 10]

for span_id in ids:
proc.on_span_start(FakeSpan(span_id))

assert {(sk, sv.span_id) for sk, sv in proc.open_spans.items()} == {(2, 2), (4, 4), (6, 6)}
assert proc.spans_started == 5
assert proc.spans_finished == 0

for span_id in ids:
proc.on_span_finish(FakeSpan(span_id))

assert proc.open_spans.keys() == set()
assert proc.spans_started == 5
assert proc.spans_finished == 5

@patch('edx_arch_experiments.datadog_diagnostics.apps.log.info')
@patch('edx_arch_experiments.datadog_diagnostics.apps.log.error')
def test_logging(self, mock_log_error, mock_log_info):
proc = apps.MissingSpanProcessor()
proc.on_span_start(FakeSpan(17))
proc.shutdown(0)

mock_log_info.assert_called_once_with("Spans created = 1; spans finished = 0")
mock_log_error.assert_called_once_with("Span created but not finished: span_id=17")
Loading

0 comments on commit ed51eb0

Please sign in to comment.