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

Enable DB replica #1104

Merged
merged 3 commits into from
Nov 22, 2023
Merged

Enable DB replica #1104

merged 3 commits into from
Nov 22, 2023

Conversation

pylipp
Copy link
Contributor

@pylipp pylipp commented Nov 7, 2023

I implemented a custom class derived from peewee's FlaskDB to glue together Flask and the databases (the primary one and, for select-queries, the replica).

Further changes are about cleaning up env variables related to configure the DB connection locally and in CircleCI.

@pylipp pylipp force-pushed the statviz-enable-db-replica branch 2 times, most recently from 99ebf44 to bcf41d9 Compare November 9, 2023 16:59
Copy link

codecov bot commented Nov 9, 2023

Codecov Report

Merging #1104 (72fabb2) into master (6d479ad) will decrease coverage by 0.08%.
Report is 49 commits behind head on master.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master    #1104      +/-   ##
==========================================
- Coverage   73.02%   72.94%   -0.08%     
==========================================
  Files         290      290              
  Lines        7439     7499      +60     
  Branches     1567     1580      +13     
==========================================
+ Hits         5432     5470      +38     
- Misses       1963     1985      +22     
  Partials       44       44              
Flag Coverage Δ
backend 96.35% <100.00%> (-0.60%) ⬇️
frontend 53.83% <ø> (ø)

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

Files Coverage Δ
back/boxtribute_server/app.py 69.69% <100.00%> (-30.31%) ⬇️
back/boxtribute_server/db.py 100.00% <100.00%> (ø)

... and 1 file with indirect coverage changes

@pylipp pylipp force-pushed the statviz-enable-db-replica branch 3 times, most recently from 5e30cfa to 10a84fa Compare November 11, 2023 10:45
The deployed env does not need host nor port since it uses a socket
connection
Affects (integration) testing only, and simplifies local development
@pylipp pylipp marked this pull request as ready for review November 13, 2023 13:07
@pylipp pylipp linked an issue Nov 13, 2023 that may be closed by this pull request
@HaGuesto
Copy link
Member

@HaGuesto priority

Copy link
Member

@HaGuesto HaGuesto left a comment

Choose a reason for hiding this comment

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

I like your solution, feels elegant. @pylipp

Just one comment: we started actually that we do not want the statviz queries to have an effect or block behavior in Boxtribute. Since now the replica is used for ALL querys, we just ensured that the statviz queries will not have an effect on the mutations in Boxtribute.

However, we also started at the point that we want to make these queries public and that is not happening at least for now. Therefore, I'm fine with this PR and it will be a nice test.

@@ -193,7 +193,8 @@ jobs:
name: Run pytest
command: |
source $(pyenv root)/versions/3.10.4/envs/env/bin/activate
ENVIRONMENT=test pytest --cov-report xml:test-results/coverage.xml --cov=boxtribute_server
# overwrite environment variable because it must not depend on the CircleCI context
ENVIRONMENT=development MYSQL_PORT=3306 pytest --cov-report xml:test-results/coverage.xml --cov=boxtribute_server
Copy link
Member

Choose a reason for hiding this comment

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

weird that the socket is needed here if you are using a socket

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What do you mean? weird that the port is needed? It's because the connection to the DB for integration tests is via TCP. Socket will only be effective in deployed environments.

unix_socket=os.getenv("MYSQL_SOCKET"),
replica_socket=os.getenv("MYSQL_REPLICA_SOCKET"),
Copy link
Member

Choose a reason for hiding this comment

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

We need to remember to set this variable in the contexts in circleci

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 already set it as a project-wide variable


class BaseModel(self.base_model_class):
@classmethod
def select(cls, *args, **kwargs):
Copy link
Member

Choose a reason for hiding this comment

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

elegant

@HaGuesto
Copy link
Member

@pylipp we are tracking the latency of the server, right? We should have an alert or track it in order to compare before and after. Would love to see the difference.

@pylipp pylipp merged commit 0fd2394 into master Nov 22, 2023
10 of 11 checks passed
@pylipp pylipp deleted the statviz-enable-db-replica branch November 22, 2023 13:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Status: Merged to staging
Development

Successfully merging this pull request may close these issues.

[B] MySQL DB replica: Investigate in setup and access
2 participants