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

PP-495 Analytics as a container service #1487

Merged
merged 15 commits into from
Nov 6, 2023
Merged

Conversation

RishiDiwanTT
Copy link
Contributor

@RishiDiwanTT RishiDiwanTT commented Oct 30, 2023

Description

Using the dependency_injector framework, the Analytics class has been moved into a Container as a Singleton.
The Analytics no longer supports per library configurations, any configuration is for the entire CM.
Configurations have been moved to environment variables.
The API objects also make use of the dependency injection pattern for analytics.
The Admin UI for the Analytics service will display a "This service is no longer configurable" message.

Database entries for Analytics have not been removed in case a rollback is required.

Motivation and Context

The CM no longer needed per-library Analytics, it required only CM-wide configurations, not via the Admin Panel.
JIRA

How Has This Been Tested?

Manually tested some feeds and Admin pages.
Updated all unit tests to reflect the new patterns.

Checklist

  • I have updated the documentation accordingly.
  • All new and existing tests passed.

Analytics is no more a singleton, and is not library dependant
Analytics will be configured through env vars now and not the admin ui
The GET method returns a problem detail for the UI to display
@RishiDiwanTT RishiDiwanTT requested a review from a team October 30, 2023 12:28
@RishiDiwanTT RishiDiwanTT self-assigned this Oct 30, 2023
@RishiDiwanTT RishiDiwanTT changed the title Analytics as a container service PP-495 Analytics as a container service Oct 30, 2023
@codecov
Copy link

codecov bot commented Oct 30, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (dca7f61) 90.42% compared to head (4d0f59b) 90.37%.
Report is 7 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1487      +/-   ##
==========================================
- Coverage   90.42%   90.37%   -0.05%     
==========================================
  Files         231      232       +1     
  Lines       29513    29330     -183     
  Branches     6892     6852      -40     
==========================================
- Hits        26687    26507     -180     
- Misses       1798     1800       +2     
+ Partials     1028     1023       -5     
Flag Coverage Δ
Api 73.69% <88.46%> (-0.09%) ⬇️
Core 61.00% <90.19%> (+0.06%) ⬆️
migration 29.29% <72.54%> (+0.76%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
api/admin/controller/__init__.py 100.00% <ø> (ø)
api/admin/controller/base.py 79.51% <ø> (-0.95%) ⬇️
api/admin/controller/view.py 95.91% <100.00%> (-0.17%) ⬇️
api/admin/routes.py 95.01% <ø> (-0.12%) ⬇️
api/discovery/registration_script.py 90.62% <100.00%> (ø)
api/s3_analytics_provider.py 68.62% <100.00%> (+1.46%) ⬆️
core/analytics.py 100.00% <100.00%> (+2.43%) ⬆️
core/feed/annotator/circulation.py 90.84% <100.00%> (+0.06%) ⬆️
core/local_analytics_provider.py 100.00% <100.00%> (ø)
core/metadata_layer.py 87.62% <100.00%> (+0.02%) ⬆️
... and 6 more

... and 4 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@tdilauro tdilauro added the Deployment Changes Requires changes to deployment configuration. label Oct 30, 2023
@tdilauro
Copy link
Contributor

tdilauro commented Oct 30, 2023

I haven't started a code review here, but it looks there will be some deployment changes associated with this PR (I've added a label for that). Specifically, it looks like we add at least the following environment variables:

  • PALACE_LOCAL_ANALYTICS_ENABLED (default: False)
  • PALACE_S3_ANALYTICS_ENABLED (default: False)
  • PALACE_LOCATION_SOURCE (default: None, other values: ["neighborhood"])

It would be helpful to document these in the README.

api/admin/routes.py Outdated Show resolved Hide resolved
api/axis.py Outdated Show resolved Hide resolved
api/axis.py Show resolved Hide resolved
api/circulation.py Outdated Show resolved Hide resolved
api/controller.py Show resolved Hide resolved
core/service/analytics/configuration.py Outdated Show resolved Hide resolved
core/service/analytics/configuration.py Show resolved Hide resolved
tests/api/test_bibliotheca.py Outdated Show resolved Hide resolved
api/controller.py Outdated Show resolved Hide resolved
core/feed/annotator/circulation.py Outdated Show resolved Hide resolved
@jonathangreen jonathangreen added the UI Update This PR requires an admin UI update label Oct 30, 2023
@jonathangreen
Copy link
Member

I added the UI update label as well, since this will require an admin UI update.

Copy link
Member

@jonathangreen jonathangreen left a comment

Choose a reason for hiding this comment

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

Just a few more comments on this one. Its looking good otherwise!

We also need two additional PRs before this can get merged:

  • Add the new env var to the hosting-playbook
  • Remove the analytics configuration from the admin interface

Can you work on those as well?

@@ -484,22 +484,6 @@ def metadata_service_self_tests(identifier):
)


@app.route("/admin/analytics_services", methods=["GET", "POST"])
Copy link
Member

Choose a reason for hiding this comment

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

Can you make a PR to the admin interface to remove the analytics service component on that side as well?

README.md Outdated

For generating quicksight dashboard links the following environment variable is required
`QUICKSIGHT_AUTHORIZED_ARNS` - A dictionary of the format `"<dashboard name>": ["arn:aws:quicksight:...",...]`
where each quicksight dashboard gets treated with an arbitrary "name", and a list of "authorized arns".
The first the "authorized arns" is always considered as the `InitialDashboardID` when creating an embed URL
for the respective "dashboard name".

#### Analytics

To enabled S3 based analytics add `PALACE_S3_ANALYTICS_ENABLED=true` else do not add the environment variable at all.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested update:

Local analytics are enabled by default. S3 analytics can be enabled via the following environment variable:

  • PALACE_S3_ANALYTICS_ENABLED: A boolean value to disable or enable s3 analytics. The default is false.

core/local_analytics_provider.py Outdated Show resolved Hide resolved
core/metadata_layer.py Outdated Show resolved Hide resolved
core/service/configuration.py Outdated Show resolved Hide resolved
tests/api/test_bibliotheca.py Outdated Show resolved Hide resolved
@@ -1564,10 +1599,10 @@ def test_end_to_end(
# book, and one to the metadata endpoint for information about
# that book.
api = default_monitor.api
Copy link
Member

Choose a reason for hiding this comment

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

Minor: If you wanted to avoid the # type: ignore [attr-defined] comments here, you could do:

api = cast(MockBibliothecaAPI, default_monitor.api)

api/controller.py Outdated Show resolved Hide resolved
Since we inject the Analytics provider directly, this is unneeded
@RishiDiwanTT
Copy link
Contributor Author

Just a few more comments on this one. Its looking good otherwise!

We also need two additional PRs before this can get merged:

  • Add the new env var to the hosting-playbook
  • Remove the analytics configuration from the admin interface

Can you work on those as well?

Sure, I'll make tickets for them and get started.

Copy link
Member

@jonathangreen jonathangreen left a comment

Choose a reason for hiding this comment

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

This looks good!

Before this gets merged, we should make sure that:

  • PR for hosting playbook is merged and deployed
  • PR for admin UI is merged

So that everything stays in sync.

@RishiDiwanTT RishiDiwanTT merged commit 93928ee into main Nov 6, 2023
30 checks passed
@RishiDiwanTT RishiDiwanTT deleted the feature/analytics-service branch November 6, 2023 14:10
@jonathangreen jonathangreen added the incompatible changes Changes that require a new major version label Nov 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Deployment Changes Requires changes to deployment configuration. incompatible changes Changes that require a new major version UI Update This PR requires an admin UI update
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants