Skip to content

Conversation

@emyller
Copy link
Contributor

@emyller emyller commented Aug 29, 2025

Contributes to Flagsmith/flagsmith#5814.

This is meant to replace the PrimaryReplicaRouter functionality in the core API.

Changes

Introduces a utility using_database_replica that wraps any Django model manager binding it to a database replica according to settings.REPLICA_READ_STRATEGY.

Tests

Unit tests.

- Prevents conflicts with other systems
- Less unused code, yay
@emyller emyller force-pushed the feat/new-database-replica-router branch from 18e8d28 to e72f1e5 Compare August 29, 2025 01:41
@emyller emyller self-assigned this Aug 29, 2025
@codecov-commenter
Copy link

codecov-commenter commented Aug 29, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.51%. Comparing base (269aea1) to head (e880860).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #95      +/-   ##
==========================================
+ Coverage   94.08%   94.51%   +0.43%     
==========================================
  Files          73       75       +2     
  Lines        2232     2408     +176     
==========================================
+ Hits         2100     2276     +176     
  Misses        132      132              

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@emyller emyller force-pushed the feat/new-database-replica-router branch from e72f1e5 to 3e4ec91 Compare August 29, 2025 18:30
@emyller emyller force-pushed the feat/new-database-replica-router branch from 0713456 to c4d1583 Compare August 29, 2025 18:33
@emyller emyller marked this pull request as ready for review August 29, 2025 18:35
@emyller emyller requested a review from a team as a code owner August 29, 2025 18:35
@emyller emyller requested review from gagantrivedi, khvn26 and matthewelwell and removed request for a team August 29, 2025 18:35
@emyller emyller changed the title feat(core): Allow for explicit use of database replicas feat(utils): Allow for explicit use of database replicas Aug 29, 2025
Copy link
Member

@khvn26 khvn26 left a comment

Choose a reason for hiding this comment

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

Overall, looks great. Added a couple questions of moderate to low impact. Would like to see this tested in threaded Gunicorn to understand whether we need to use thread-local storage for the sequential replica cache. Besides that, interested to see if there's a performance effect on high-volume queries.

Copy link
Member

@khvn26 khvn26 left a comment

Choose a reason for hiding this comment

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

Do we want to export Prometheus metrics for this?

e.g. flagsmith_db_chosen_replica_count labeled by status and replica_connection_name.

@emyller
Copy link
Contributor Author

emyller commented Sep 1, 2025

Do we want to export Prometheus metrics for this?

I'd be happy to do it given an example, and if it doesn't extend much of the scope here.

@emyller emyller requested a review from khvn26 September 1, 2025 17:54
Copy link
Member

@khvn26 khvn26 left a comment

Choose a reason for hiding this comment

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

LGTM 👍 Looking forward to seeing this used in Core.

@emyller emyller merged commit 617861b into main Sep 2, 2025
4 of 7 checks passed
@emyller emyller deleted the feat/new-database-replica-router branch September 2, 2025 15:17
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.

5 participants