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

get_sites: configurable backend to filter active sites #321

Merged
merged 7 commits into from
Jan 20, 2021

Conversation

OmarIthawi
Copy link
Contributor

@OmarIthawi OmarIthawi commented Jan 15, 2021

RED-1721. This will help to make Figures use the openedx.core.djangoapps.appsembler.sites.utils.get_active_sites via configurations to make the pipeline run only for active sites.

This should help as both stopgap and long term solution for the increasing time of the pipeline.

TODO

  • Fix existing broken tests
  • Add tests to cover both with/without backend
  • Document the setting variable?

@OmarIthawi OmarIthawi marked this pull request as ready for review January 15, 2021 21:38
@OmarIthawi
Copy link
Contributor Author

OmarIthawi commented Jan 15, 2021

@johnbaldwin this isn't much ready for merge but should have everything I got in mind.

Please review it and let me know what do you think especially regarding the inline notes in the code.

@OmarIthawi OmarIthawi requested a review from melvinsoft January 19, 2021 12:09
# Would be really Really REALLY great to be able to filter out dead sites

sites = Site.objects.all()
sites = get_sites()
Copy link
Contributor

Choose a reason for hiding this comment

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

Yay!

# Would be really Really REALLY great to be able to filter out dead sites

sites = Site.objects.all()
sites = get_sites()
Copy link
Contributor

Choose a reason for hiding this comment

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

Yay!


:return list of Site (QuerySet)
"""
sites_backend_path = settings.ENV_TOKENS['FIGURES'].get('SITES_BACKEND')
Copy link
Contributor

Choose a reason for hiding this comment

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

Just to note: Confirming it is ok to assume settings.ENV_TOKENS['FIGURES'] will always exist.

Figures sets a default empty dict for settings.ENV_TOKENS['FIGURES']. See here: https://github.com/appsembler/figures/blob/0.4.dev7/figures/settings/lms_production.py#L80

sites_backend_path = settings.ENV_TOKENS['FIGURES'].get('SITES_BACKEND')
if sites_backend_path:
sites_backend = import_from_path(sites_backend_path)
sites = sites_backend()
Copy link
Contributor

Choose a reason for hiding this comment

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

Was first thinking, why not just do sites = import_from_path(sites_backend_path)() But this is probably clearer

@@ -378,8 +376,8 @@ def populate_monthly_metrics_for_site(site_id):
@shared_task
def run_figures_monthly_metrics():
"""
TODO: only run for active sites. Requires knowing which sites we can skip
Populate monthly metrics for all sites.
Copy link
Contributor

Choose a reason for hiding this comment

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

Technically, this is is only all sites when a filtered sites backend is not used

@@ -899,8 +899,10 @@ class SiteViewSet(StaffUserOnDefaultSiteAuthMixin, viewsets.ReadOnlyModelViewSet
Access is restricted to global (Django instance) staff
"""
model = Site
queryset = Site.objects.all()
Copy link
Contributor

Choose a reason for hiding this comment

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

You should probably just be able to set queryset = figures.sites.get_sites() and not need the get_queryset method. I'd need to look through the DRF code to see if there is any significant difference

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If get_sites returns an already evaluated list (and memory cached) there could be a problem of having the list of sites stale.

If it did have a stale sites, it means the only way to refresh the list is to restart the workers.

While this issue may not happen, it would be a rabbit hole to discover it.

Therefore I'm erring on the safe side of using a method since it's out of the control of Figures.

Copy link
Contributor

Choose a reason for hiding this comment

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

Fair enough

@@ -220,3 +221,30 @@ def test_first_last_days_for_month():
assert last_day.year == year
assert first_day.day == 1
assert last_day.day == 29


Copy link
Contributor

Choose a reason for hiding this comment

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

@OmarIthawi Nice simple set of tests here, I like them!

@OmarIthawi
Copy link
Contributor Author

OmarIthawi commented Jan 20, 2021

@johnbaldwin where to document the Figures settings? If there's no configuration doc, where should be created?

Copy link
Contributor

@johnbaldwin johnbaldwin left a comment

Choose a reason for hiding this comment

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

LGTM, thanks @OmarIthawi !

@OmarIthawi OmarIthawi merged commit 1e5642e into master Jan 20, 2021
@OmarIthawi OmarIthawi deleted the omar/sites-backend branch January 20, 2021 17:11
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