Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: refactor code_owner code from edx-dajango-utils #838

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

robrap
Copy link
Contributor

@robrap robrap commented Oct 23, 2024

Note to Reviewer: The original edx-django-utils code was copied in as a separate commit to make it easier to see what was added and what was updated if you review commit by commit.

Initial rollout of moving code_owner monitoring code from edx-django-utils to this plugin.

  • Adds near duplicate of code owner middleware from edx-django-utils.
  • Adds code owner for celery using Datadog span processing of celery.run spans.
  • Uses temporary span tags names using _2, like code_owner_2, for rollout and comparison with the original span tags.

See #784

Merge checklist:
Check off if complete or not applicable:

  • Version bumped
  • Changelog record added
  • Documentation updated (not only docstrings)
  • Fixup commits are squashed away
  • Unit tests added/updated
  • Manual testing instructions provided
  • Noted any: Concerns, dependencies, migration issues, deadlines, tickets

This is the code_owner code as found in edx-django-utils.
Initial rollout of moving code_owner monitoring code from
edx-django-utils to this plugin.

- Adds near duplicate of code owner middleware from
  edx-django-utils.
- Adds code owner for celery using Datadog span processing
  of celery.run spans.
- Uses temporary span tags names using `_2`, like
  `code_owner_2`, for rollout and comparison with the original span tags.

See #784
Comment on lines +91 to +93
code_owner_mappings = getattr(settings, 'CODE_OWNER_MAPPINGS', None)
if code_owner_mappings is None:
return None
Copy link
Contributor Author

@robrap robrap Oct 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note for Reviewer: A bug was found in this code, because there was a bug in the original test for this that didn't catch this problem.
As a reviewer, feel free to mark this resolved once you have read this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What impact would this have had?

requirements/base.txt Outdated Show resolved Hide resolved
@robrap robrap force-pushed the robrap/add-code-owner-monitoring branch from ce0a75e to 1d3af1c Compare October 24, 2024 14:52
@robrap
Copy link
Contributor Author

robrap commented Oct 24, 2024

Note to Reviewer: I did initial local testing to POC the celery span resource name was available locally, but I did not do a final local test. I wasn't able to get to a real celery task locally.

# We can use this for celery spans, because the resource name is more predictable
# and available from the start. For django requests, we'll instead continue to use
# django middleware for setting code owner.
get_code_owner_from_module(span.resource)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be set_code_owner_attribute_from_module?

code_owner_squad IN ('old-squad-name', 'new-squad-name')
code_owner_theme IN ('old-theme-name', 'new-theme-name')
code_owner_2_squad:('old-squad-name', 'new-squad-name')
code_owner_2_theme:('old-theme-name', 'new-theme-name')

Example contract phase NRQL::
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still some NRQL references here.


Usage::

@task()
@set_code_owner_attribute
@set_code_owner_2_attribute
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unneeded change here -- can just delete these functions, though.


If you first need some background on the ``code_owner_2_squad`` and ``code_owner_2_theme`` custom attributes, see `Using Code_Owner Custom Span Tags`_.

.. _Using Code_Owner Custom Span Tags: https://github.com/openedx/edx-arch-experiments/blob/master/edx_arch_experiments/datadog_monitoring/docs/how_tos/add_code_owner_custom_attribute_to_an_ida.rst
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.. _Using Code_Owner Custom Span Tags: https://github.com/openedx/edx-arch-experiments/blob/master/edx_arch_experiments/datadog_monitoring/docs/how_tos/add_code_owner_custom_attribute_to_an_ida.rst
.. _Using Code_Owner Custom Span Tags: https://github.com/edx/edx-arch-experiments/blob/main/edx_arch_experiments/datadog_monitoring/docs/how_tos/add_code_owner_custom_attribute_to_an_ida.rst

class TestDatadogMonitoringSpanProcessor(TestCase):
"""Tests for DatadogMonitoringSpanProcessor."""

@patch('edx_arch_experiments.datadog_monitoring.apps.get_code_owner_from_module')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should these patches be adjusted to mock out the setter?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants