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

[ENG-6119] api changes for institution-users updates #10742

Merged

Conversation

aaxelb
Copy link
Contributor

@aaxelb aaxelb commented Sep 6, 2024

Purpose

update api to serve institutional-user metrics based on the monthly report added in #10722

Changes

reusable things added:

  • toggle_view_by_flag util to ease feature-flagged views
    • also allow non-class views to exist (minor updates to api tests and bases)
  • base view ElasticsearchListView
    • use elasticsearch_dsl.Search as queryset-analogue, for code reuse
    • allows filtering (with 'eq' and 'ne' operators) following filterable_fields on the serializer (using api.base.filters.FilterMixin)
    • allows sorting, following default_ordering and ordering_fields on the view
    • allows pagination (with page and page[size] params), using default paginator
  • api.base.serializers.YearmonthField
  • MonthlyReport.most_recent_yearmonth classmethod

specific to this project:

  • add feature flag INSTITUTIONAL_DASHBOARD_2024
  • rename prior institution-user view and serializer with Old prefix
  • use toggle_view_by_flag to toggle new/old views (with new/old serializers)
  • add "new" institution-user metrics view (using ElasticsearchListView)
  • add "new" institution-user metrics serializer

incidental:

  • fix: old institution-user metrics tests
    • set INSTITUTIONAL_DASHBOARD_2024 flag inactive for existing institution-user metrics tests
    • remove time.sleep calls; use index refreshes instead (saves ~70 sec)
    • unskip tests -- "non-deterministic fails" may be fixed by refreshes?
  • avoid clobbering all indexes by running tests
    • rename the es pytest marker to es_metrics (for clarity)
    • update the effect of that marker:
      • patch a prefix to each metric class's index and template names
      • instead of deleting ALL indexes and index templates, delete only
        those with the patched prefix
    • update api_tests.metrics.test_raw_metrics to clean up after itself
      and stop depending on the clobbering

QA Notes

Please make verification statements inspired by your code and what your code touches.

  • Verify
  • Verify

What are the areas of risk?

Any concerns/considerations/questions that development raised?

Documentation

Side Effects

Ticket

ENG-6119

@aaxelb aaxelb force-pushed the eng-6119 branch 5 times, most recently from 6241ca4 to 46fdfb4 Compare September 9, 2024 21:36
@aaxelb aaxelb force-pushed the eng-6119 branch 3 times, most recently from 5328629 to 012fd0b Compare September 10, 2024 17:46
@aaxelb aaxelb changed the title [wip][ENG-6119] api changes for institution-users updates [ENG-6119] api changes for institution-users updates Sep 10, 2024
@aaxelb aaxelb marked this pull request as ready for review September 10, 2024 20:02
Copy link
Contributor

@Johnetordoff Johnetordoff left a comment

Choose a reason for hiding this comment

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

I don't really have any hard changes, just a couple questions and ideas. Good work! 💯

api/base/elasticsearch_dsl_views.py Show resolved Hide resolved
operator: str,
value: str,
) -> edsl.Search:
match operator: # operators from FilterMixin
Copy link
Contributor

Choose a reason for hiding this comment

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

Are we sure there's no [lt]/[lte]/[gt]/[gte] ? Thinking about if admins want custom csv files in certain date ranges they may want to filter by date. I'm not sure it's necessary from this view, not for the user's tab anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i'm open to adding range filters if/when we have a use for it (would be nice to make this base view a more generally reusable thing), but there's been no ask for it yet and i'm trying to embrace at least the good parts of agile :)

(if we decide to offer an institution-summary history and/or use this to improve the unstable/terrible /_/metrics/reports/ api, then yeah, range queries for sure)

api/base/serializers.py Outdated Show resolved Hide resolved
api/institutions/serializers.py Show resolved Hide resolved
api/institutions/serializers.py Show resolved Hide resolved
api_tests/base/test_views.py Outdated Show resolved Hide resolved
api/base/serializers.py Outdated Show resolved Hide resolved
api/institutions/views.py Outdated Show resolved Hide resolved
- add skeletons for new institution-user metrics view and serializer
- add `toggle_view_by_flag` util to ease feature-flagged views
- use that util to toggle new/old views (with new/old serializers)
- (nit) use django's `view_fn.view_class` instead of drf's `view_fn.cls`
- set INSTITUTIONAL_DASHBOARD_2024 flag inactive for existing
  institution-user metrics tests
- remove `time.sleep` calls; use index refreshes instead (saves ~70 sec)
- unskip tests -- "non-deterministic fails" may be fixed by refreshes?
- add base `ElasticsearchListView`
    - use `elasticsearch_dsl.Search` as queryset-analogue for code reuse
    - allows filtering (with 'eq' and 'ne' operators) following
      `filterable_fields` on the serializer
    - allows sorting, following `default_ordering` and `ordering_fields`
      on the view
    - allows pagination (with `page` and `page[size]` params)
- update "new" institution user metrics view with ElasticsearchListView
- add `MonthlyReport.most_recent_yearmonth`
- rename the `es` pytest marker to `es_metrics` (for clarity)
- update the effect of that marker:
    - patch a prefix to each metric class's index and template names
    - instead of deleting ALL indexes and index templates, delete only
      those with the patched prefix
- update `api_tests.metrics.test_raw_metrics` to clean up after itself
  and stop depending on the clobbering
@aaxelb aaxelb merged commit 9384d76 into CenterForOpenScience:feature/insti-dash-improv Sep 11, 2024
6 checks passed
@aaxelb aaxelb deleted the eng-6119 branch September 11, 2024 17:57
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