feat: route Insights enrollment APIs through Snowflake - #212
Conversation
Coverage reportClick to see where and how coverage changed
This report was generated by python-coverage-comment-action |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
🔵 Needs a closer look
It changes the data source routing for multiple production API endpoints, so a final human review is needed to validate behavioral parity and operational readiness beyond the added unit tests.
Pull request overview
This PR migrates the Insights course enrollment API endpoints to support Snowflake-backed reads behind the global insights_snowflake_enabled waffle flag, while preserving existing URLs and response shapes and keeping Aurora as the default when the flag is off.
Changes:
- Added a reusable
SnowflakeCourseEnrollmentMixinto route eligible enrollment views to Snowflake (and set theX-Insights-Data-Sourceheader). - Implemented Snowflake enrollment query + mapping + service layers for daily, mode, education, gender, and location enrollment endpoints.
- Added targeted tests covering query construction, mapper behavior, service wiring, and view routing (including 404 behavior when Snowflake returns no data).
File summaries
| File | Description |
|---|---|
| analytics_data_api/v0/views/courses.py | Adds Snowflake routing mixin and applies it to migrated enrollment views (keeping birth year unchanged). |
| analytics_data_api/v0/tests/views/test_courses.py | Adds/updates view-level tests to validate Snowflake vs Aurora routing and response headers for enrollment endpoints. |
| analytics_data_api/tests/test_insights_snowflake.py | Adds unit tests for enrollment Snowflake queries, mappers, and service orchestration. |
| analytics_data_api/insights_snowflake/service.py | Adds Snowflake service functions for enrollment-related endpoints. |
| analytics_data_api/insights_snowflake/queries/enrollment.py | Introduces Snowflake SQL query builders for enrollment metrics (latest-date and date-range modes). |
| analytics_data_api/insights_snowflake/mappers/enrollment.py | Introduces enrollment row mappers/pivots to match existing API response shapes (including model-instance mapping for location). |
Review details
- Files reviewed: 6/6 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
There was a problem hiding this comment.
🔵 Needs a closer look
It changes production-facing read paths to a new Snowflake SQL/query+mapping stack, which warrants a final human review against real schema/data behavior despite the added tests.
Review details
- Files reviewed: 6/6 changed files
- Comments generated: 0 new
- Review effort level: Lite
There was a problem hiding this comment.
🔵 Needs a closer look
It introduces new Snowflake-backed query/mapping paths for multiple production endpoints, which warrants final human review for data correctness and rollout safety beyond what can be fully validated here.
Review details
- Files reviewed: 6/6 changed files
- Comments generated: 0 new
- Review effort level: Lite
There was a problem hiding this comment.
🔵 Needs a closer look
It changes production data-source routing for multiple enrollment endpoints and introduces new Snowflake query/mapping behavior that warrants final human verification.
Review details
Suppressed comments (1)
Previously missed (1) — in code that hasn't changed since the last review.
analytics_data_api/v0/views/courses.py:313
get_snowflake_querysetcalls the service function with positional date arguments and raises a bareNotImplementedError, which makes it easier to accidentally pass the wrong values (or get an unhelpful 500) if the service signature changes or a subclass forgets to set the function. Using keyword args here and adding a clearer error message keeps this routing safer and easier to debug.
- Files reviewed: 6/6 changed files
- Comments generated: 0 new
- Review effort level: Lite
This PR migrates the Insights enrollment API group to support Snowflake-backed reads behind the global Analytics API Waffle flag.
Changes included:
insights_snowflake_enabledis on.