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

DRAFT Read replication and moving the API to a second database #4427

Draft
wants to merge 96 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
96 commits
Select commit Hold shift + click to select a range
f1e4a70
Updating with new layout
jadudm Sep 27, 2024
40158bb
Updating/cleaning up for testing
jadudm Sep 27, 2024
660b98e
Merge branch 'main' into jadudm/api-perf
jadudm Sep 27, 2024
b2263e7
In-progress.
jadudm Sep 29, 2024
d54e8fa
Updating ignores...
jadudm Sep 29, 2024
7e54577
Runs a ffull sequence
jadudm Sep 30, 2024
6e4470e
Cleaining up
jadudm Sep 30, 2024
70e2a13
Updating .profile to match run.sh
jadudm Sep 30, 2024
a31eea0
Bringup for the Admin API
jadudm Oct 2, 2024
b3e8523
Cleanup, missed files.
jadudm Oct 2, 2024
e4fa18f
These are important...
jadudm Oct 2, 2024
de6c7ea
Adding GH action, script
jadudm Oct 2, 2024
b30ba03
Expand the admin API to increase visibility
jadudm Oct 2, 2024
1337097
Full-up, with performance testing
jadudm Oct 3, 2024
65f7365
Updates for live test.
jadudm Oct 4, 2024
1be0b83
Improving/simplifying
jadudm Oct 5, 2024
a809bea
Ready for testing in preview
jadudm Oct 9, 2024
88bc8a5
Source the script...
jadudm Oct 9, 2024
0e4f240
Fix path to sling
jadudm Oct 9, 2024
a94598c
Making the checks noisy.
jadudm Oct 9, 2024
2006d8a
Noisyer.
jadudm Oct 9, 2024
b95cb61
Don't exit so quickly...
jadudm Oct 9, 2024
6f1d153
Try to catch the error and continue if found
asteel-gsa Oct 9, 2024
8c2a047
Before further renaming.
jadudm Oct 10, 2024
e3cc950
Simplified.
jadudm Oct 10, 2024
eb12bad
Forgot to delete a bunch of things...
jadudm Oct 10, 2024
d5d4915
Set +/-e around check...
jadudm Oct 10, 2024
6b45c49
Trying to get past error...
jadudm Oct 10, 2024
328e9b9
Fixing SQL checks
jadudm Oct 10, 2024
3539ffc
Still... fixing return values...
jadudm Oct 10, 2024
1093b0f
Make the sources the same
jadudm Oct 10, 2024
cd525cb
Fix echo statements
jadudm Oct 10, 2024
cbadf2c
Try set -e?
jadudm Oct 10, 2024
2b33286
What about set +e...
jadudm Oct 10, 2024
cf6b5c9
Working around bash...
jadudm Oct 10, 2024
a511d9c
Incremental on removal of Tribal/admin API.
jadudm Oct 22, 2024
a58ebb2
Big update...
jadudm Oct 24, 2024
d1238ec
Merge branch 'main' into jadudm/api-perf
jadudm Oct 24, 2024
2ea604a
Simulating pre-deploy backup
jadudm Oct 24, 2024
8b5d43a
Fixes Minio, copies data
jadudm Oct 25, 2024
1656bad
Using a VCAP_SERVICES locally
jadudm Oct 25, 2024
6f5b205
Minor change, move to /tmp
jadudm Oct 25, 2024
9ea4a29
Move curation tracking init
jadudm Oct 25, 2024
cb0fa77
Removing unnecessary CREATE SCHEMA
jadudm Oct 25, 2024
03a4e6d
Fixed my partial rename
jadudm Oct 25, 2024
1747897
This points advanced search at pd.combined
jadudm Oct 25, 2024
7315cf9
Admin Panel and touch-ups
rnovak338 Oct 25, 2024
0ff0629
Remove Sling README
rnovak338 Oct 25, 2024
551f85e
Moves general back into the public_100 tables.
jadudm Oct 25, 2024
5f300a2
Merge branch 'jadudm/api-perf' of github.com:GSA-TTS/FAC into jadudm/…
jadudm Oct 25, 2024
affe2b7
Simplified run.sh
jadudm Oct 25, 2024
3aa6266
Updated the sling script for bulk data
jadudm Oct 25, 2024
d329f27
Simplified local data load
jadudm Oct 25, 2024
c2149f1
Updating to reflect new startup sequence
jadudm Oct 28, 2024
e1a3bb8
And, forgot the sourcing...
jadudm Oct 28, 2024
edf2c1f
Fake audit, test if migrations will go through
asteel-gsa Oct 28, 2024
5dd7e92
Add replaces to Django
asteel-gsa Oct 28, 2024
db1927b
Undo
asteel-gsa Oct 28, 2024
3ec3e81
Should fix local standup/build
jadudm Oct 28, 2024
ffad20f
Removing orderby on combined
jadudm Oct 29, 2024
409792b
Splits things away from startup
jadudm Oct 29, 2024
7abe12a
Prep API Standup Test
asteel-gsa Oct 29, 2024
decc89a
Fixes run.sh
jadudm Oct 29, 2024
dcb3581
Merge branch 'jadudm/api-perf' of github.com:GSA-TTS/FAC into jadudm/…
jadudm Oct 29, 2024
337ea0d
Update Cypress E2E API checks
rnovak338 Oct 29, 2024
f2ae9de
Changing apparent error to warning
jadudm Oct 29, 2024
df8236d
Fixing email, whitespace
jadudm Oct 29, 2024
f2055c5
Test api refresh
asteel-gsa Oct 29, 2024
825a3e0
Api chmod +x
asteel-gsa Oct 29, 2024
814a5a7
Remove historical data load
asteel-gsa Oct 29, 2024
72a86a0
Push to run api_refresh
asteel-gsa Oct 29, 2024
04970aa
Use pushd & popd to put us where we need to be for source & other utils
asteel-gsa Oct 29, 2024
d2d910d
API Refresh test
asteel-gsa Oct 29, 2024
53ede5a
Overthinking bash pathing
asteel-gsa Oct 29, 2024
5f8a7ec
Debugging typo removal
asteel-gsa Oct 29, 2024
9b361e9
Version bump backup-util to v0.1.9
asteel-gsa Oct 29, 2024
bdbbe31
TF, sequencing
jadudm Oct 29, 2024
cf769b9
API Refresh Test - Final?
asteel-gsa Oct 29, 2024
8977b6d
disable api refresh on push
asteel-gsa Oct 29, 2024
209c26a
Testing with data
jadudm Oct 30, 2024
38ac254
Allows for configuration of the DB
jadudm Oct 31, 2024
8033d3d
Merge branch 'main' into jadudm/api-perf
jadudm Oct 31, 2024
ec602d5
Adding documentation
jadudm Oct 31, 2024
2d009d6
Update api refresh workflow
asteel-gsa Nov 1, 2024
e569dc6
Fix workflows
asteel-gsa Nov 1, 2024
fc614dd
Fixing two missing tables...
jadudm Nov 1, 2024
ab68fa0
Updating tests.
jadudm Nov 1, 2024
24c2c5c
Linting
rnovak338 Nov 7, 2024
8815dd2
Document django admin access
rnovak338 Nov 7, 2024
04a85b8
Merge branch 'main' into jadudm/api-perf
rnovak338 Nov 7, 2024
f2084e9
Linting
rnovak338 Nov 7, 2024
b04e944
More linting - bandit
rnovak338 Nov 8, 2024
0256047
Reformat local python API tests to rest of the testing suite
rnovak338 Nov 8, 2024
015af34
FE Linting
rnovak338 Nov 8, 2024
d1a17ae
Merge branch 'main' into jadudm/api-perf
rnovak338 Nov 14, 2024
04e19e4
Linting
rnovak338 Nov 14, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .github/ISSUE_TEMPLATE/onboarding.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ Note: If you're not able to do any of these yourself, you're still responsible f
- [ ] [Add as a form manager to the touchpoints recruitment intercept](https://touchpoints.app.cloud.gov/admin/forms/9412c559/permissions)

**For engineers, also...**
- [ ] Make sure you have a `login.gov` account and have logged into the FAC application at least once.
- [ ] Then, add your email to the `readonly` list in [staffusers.json](../../backend/config/staffusers.json).
- [ ] [Add as a member of the FAC group in New Relic](https://one.newrelic.com/admin-portal/organizations/users-list) (@GSA-TTS/fac-admins can do this)

**For product leads/owners, also...**
Expand All @@ -88,5 +90,6 @@ Note: If you're not able to do any of these yourself, you're still responsible f
- [ ] Also give them the `Maintainer` role in [the FAC-team team in GitHub](https://github.com/orgs/GSA-TTS/teams/fac-team/members).

**For helpdesk, also...**
- [ ] Add them to the list of staff users for [Django Admin](https://app.fac.gov/admin/users/staffuser/).
- [ ] Make sure you have a `login.gov` account and have logged into the FAC application at least once.
- [ ] Then, add your email to the `helpdesk` list in [staffusers.json](../../backend/config/staffusers.json).
- [ ] Give them access to the [Help Desk](https://fac-gov.zendesk.com/admin/people/team/members) as a team member.
13 changes: 2 additions & 11 deletions .github/workflows/deploy-application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ jobs:
cf_password: ${{ secrets.CF_PASSWORD }}
cf_org: gsa-tts-oros-fac
cf_space: ${{ env.space }}
command: cf run-task gsa-fac -k 7G -m 3G --name deploy_backup --command "./fac-backup-util.sh v0.1.5 deploy_backup"
command: cf run-task gsa-fac -k 7G -m 3G --name deploy_backup --command "./fac-backup-util.sh v0.1.9 deploy_backup"

- name: Deploy Preview to cloud.gov
if: ${{ inputs.environment == 'preview' }}
Expand All @@ -103,15 +103,6 @@ jobs:
cf_vars_file: backend/manifests/vars/vars-${{ env.space }}.yml
command: bin/ops/deploy.sh

- name: Load historical data
uses: cloud-gov/cg-cli-tools@main
with:
cf_username: ${{ secrets.CF_USERNAME }}
cf_password: ${{ secrets.CF_PASSWORD }}
cf_org: gsa-tts-oros-fac
cf_space: ${{ env.space }}
command: cf run-task gsa-fac -k 6G -m 1G --name load_data --command "./load_data.sh"

# This has to happen after an application deployment because the manifest (currently) is responsible
# for binding the "logdrain service" to the "gsa-fac application". This also needs to be done
# based on the suspicion that fluentbit cannot register the incoming logs when it is initially
Expand All @@ -132,5 +123,5 @@ jobs:
secrets: inherit
with:
environment: ${{ inputs.environment }}
util_version: "v0.1.8"
util_version: "v0.1.9"
backup_operation: "check_tables"
24 changes: 24 additions & 0 deletions .github/workflows/fac-api-scheduler.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
name: API Refresh Schedule
on:
schedule:
# Invoke at 12:30 EST
- cron: '30 4 * * *'
workflow_dispatch: null

jobs:
scheduled-api-standup:
strategy:
fail-fast: false
matrix:
environment:
- name: dev
- name: staging
- name: production
- name: preview
uses: ./.github/workflows/fac-api-standup.yml
secrets: inherit
with:
environment: ${{ matrix.environment.name }}
util_version: "v0.1.9"
backup_operation: "rds_backup"
54 changes: 54 additions & 0 deletions .github/workflows/fac-api-standup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
---
name: Standup the API
on:
workflow_call:
inputs:
environment:
required: true
type: string
util_version:
description: Version for fac backup utility to use (ex. vX.Y.Z)
required: true
type: string
backup_operation:
description: Operation for fac-backup-utility
required: true
type: string
workflow_dispatch:
inputs:
environment:
required: true
type: choice
options:
- 'dev'
- 'preview'
- 'staging'
- 'production'
util_version:
description: Version for fac backup utility to use (ex. vX.Y.Z)
required: true
type: string
default: "v0.1.9"
backup_operation:
description: Operation for fac-backup-utility
required: true
type: choice
options:
- 'rds_backup'
jobs:
api-standup:
name: Standup API
runs-on: ubuntu-latest
environment: ${{ inputs.environment }}
env:
space: ${{ inputs.environment }}
steps:
- name: Backup FAC Database and refresh the api
uses: cloud-gov/cg-cli-tools@main
with:
cf_username: ${{ secrets.CF_USERNAME }}
cf_password: ${{ secrets.CF_PASSWORD }}
cf_org: gsa-tts-oros-fac
cf_space: ${{ env.space }}
command: cf run-task gsa-fac -k 2G -m 2G --name standup_api --command "./util/nightly_api_refresh.sh ${{ inputs.util_version }} ${{ inputs.backup_operation }}"
# command: cf run-task gsa-fac -k 2G -m 2G --name api_refresh --command "./util/nightly_api_refresh.sh v0.1.9 rds_backup"
3 changes: 1 addition & 2 deletions .github/workflows/fac-backup-scheduler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,5 @@ jobs:
secrets: inherit
with:
environment: ${{ matrix.environment.name }}
util_version: "v0.1.8"
util_version: "v0.1.9"
backup_operation: "scheduled_backup"

4 changes: 2 additions & 2 deletions .github/workflows/fac-backup-util-scheduled.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
name: Backup the database with fac-backup-utility
### Common Commands:
# ./fac-backup-util.sh v0.1.8 scheduled_backup
# ./fac-backup-util.sh v0.1.8 daily_backup
# ./fac-backup-util.sh v0.1.9 scheduled_backup
# ./fac-backup-util.sh v0.1.9 daily_backup
on:
workflow_call:
inputs:
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/fac-backup-util.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
name: Backup the database with fac-backup-utility
### Common Commands:
# ./fac-backup-util.sh v0.1.8 initial_backup
# ./fac-backup-util.sh v0.1.8 deploy_backup
# ./fac-backup-util.sh v0.1.9 initial_backup
# ./fac-backup-util.sh v0.1.9 deploy_backup
on:
workflow_dispatch:
inputs:
Expand All @@ -18,6 +18,7 @@ on:
description: Version for fac backup utility to use (ex. vX.Y.Z)
required: true
type: string
default: "v0.1.9"
backup_operation:
description: Operation for fac-backup-utility
required: true
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/fac-check-tables-scheduler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ jobs:
secrets: inherit
with:
environment: ${{ matrix.environment.name }}
util_version: "v0.1.8"
util_version: "v0.1.9"
backup_operation: "check_tables"
2 changes: 1 addition & 1 deletion .github/workflows/fac-check-tables.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
name: Check existing tables in an environment
### Common Commands:
# ./fac-backup-util.sh v0.1.8 check_tables
# ./fac-backup-util.sh v0.1.9 check_tables
on:
workflow_dispatch:
inputs:
Expand Down
2 changes: 2 additions & 0 deletions backend/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.tar.gz
config.json
50 changes: 22 additions & 28 deletions backend/.profile
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
#!/bin/bash

# Source everything; everything is now a function.
# Remember: bash has no idea if a function exists,
# so a typo in a function name will fail silently. Similarly,
# bash has horrible scoping, so use of `local` in functions is
# critical for cleanliness in the startup script.
set +e

source tools/util_startup.sh
# This will choose the correct environment
# for local envs (LOCAL or TESTING) and cloud.gov
source tools/setup_env.sh
source tools/api_teardown.sh
source tools/curation_audit_tracking_disable.sh
source tools/sling_bulk_export.sh
source tools/migrate_app_tables.sh
source tools/api_standup.sh
source tools/run_collectstatic.sh
source tools/seed_cog_baseline.sh
source tools/materialized_views.sh
source tools/sql_pre_post.sh

#####
# SETUP THE CGOV ENVIRONMENT
Expand All @@ -24,37 +18,37 @@ gonogo "setup_env"
if [[ "$CF_INSTANCE_INDEX" == 0 ]]; then

#####
# API TEARDOWN
# API has to be deprecated/removed before migration, because
# of tight coupling between schema/views and the dissemination tables
api_teardown
gonogo "api_teardown"
# SQL PRE
# We have SQL that we want to run before the migrations and sling are run.
# This tears down things that would conflict with migrations, etc.
sql_pre_fac_db
gonogo "sql_pre_fac_db"
curation_audit_tracking_disable
gonogo "curation_audit_tracking_disable"

#####
# MIGRATE APP TABLES
migrate_app_tables
gonogo "migrate_app_tables"

#####
# API STANDUP
# Standup the API, which may depend on migration changes
api_standup
gonogo "api_standup"

#####
# COLLECT STATIC
# Do Django things with static files.
# run_collectstatic
# gonogo "run_collectstatic"
# SQL POST
# Rebuild the API and prepare the system for execution.
# Runs after migrations.
sql_post_fac_db
gonogo "sql_post_fac_db"

#####
# SEED COG/OVER TABLES
# Setup tables for cog/over assignments
seed_cog_baseline
gonogo "seed_cog_baseline"

# materialized_views
# gonogo "materialized_views"
#####
# CREATE STAFF USERS
# Prepares staff users for Django admin
python manage.py create_staffusers
gonogo "create_staffusers"
fi

# Make psql usable by scripts, for debugging, etc.
Expand Down
1 change: 1 addition & 0 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ RUN apt-get -yq update && \
gcc \
gnupg \
gnupg2 \
jq \
postgresql-client \
wget

Expand Down
38 changes: 28 additions & 10 deletions backend/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ docker-lint:
docker compose run web bash -c 'flake8 && black --check . && bandit -c pyproject.toml -r . && mypy . && djlint .'

ghcr-first-run:
docker compose -f docker-compose-web.yml run web python manage.py makemigrations
docker compose -f docker-compose-web.yml run web python manage.py migrate
docker compose -f docker-compose-web.yml run web python manage.py loaddata
-docker compose -f docker-compose-web.yml run web python manage.py makemigrations
-docker compose -f docker-compose-web.yml run web python manage.py migrate
-docker compose -f docker-compose-web.yml run web python manage.py loaddata

# Run Django tests with docker
ghcr-test:
Expand All @@ -109,15 +109,33 @@ ghcr-nctest:
ghcr-lint:
docker compose -f docker-compose-web.yml run web bash -c 'flake8 && black --check . && bandit -c pyproject.toml -r . && python -m pip install types-pytz && mypy . && djlint .'

remove-coverage:
-rm -f .coverage.*

compose-down:
docker compose down

remove-processes:
docker rm -f $$(docker ps -a -q)

remove-volumes:
-docker volume rm $$(docker volume ls -q)

remove-dangling-volumes: remove-volumes
-docker volume rm $$(docker volume ls -q --filter dangling=true)

system-prune:
-docker system prune -f

volume-prune:
-docker volume prune -f

docker-clean:
docker compose down
docker rm -f $(shell docker ps -a -q)
docker volume rm $(shell docker volume ls -q)

docker-full-clean:
rm -f .coverage.*
docker compose down
docker rm -f $(docker ps -a -q)
docker volume rm $(docker volume ls -q)
docker system prune -f
docker volume prune -f
# Proceed past errors.
# We want all of these commands to run, even if one fails.
# make -i docker-full-clean
docker-full-clean: remove-coverage compose-down remove-processes remove-dangling-volumes system-prune volume-prune
8 changes: 4 additions & 4 deletions backend/census_historical_migration/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ This is implemented as a Django app to leverage existing management commands and
- fac_s3.py - Uploads folders or files to an S3 bucket.

```bash
python manage.py fac_s3 gsa-fac-private-s3 --upload --src census_historical_migration/data
python manage.py fac_s3 fac-private-s3 --upload --src census_historical_migration/data
```

- csv_to_postgres.py - Inserts data into Postgres tables using the contents of the CSV files in the S3 bucket. The first row of each file is assumed to have the column names (we convert to lowercase). The name of the table is determined by examining the name of the file. The sample source files do not have delimters for empty fields at the end of a line - so we assume these are nulls.
Expand All @@ -44,16 +44,16 @@ python manage.py csv_to_postgres --clean True
1. Download test Census data from https://drive.google.com/drive/folders/1TY-7yWsMd8DsVEXvwrEe_oWW1iR2sGoy into census_historical_migration/data folder.
NOTE: Never check in the census_historical_migration/data folder into GitHub.

2. In the FAC/backend folder, run the following to load CSV files from census_historical_migration/data folder into gsa-fac-private-s3 bucket.
2. In the FAC/backend folder, run the following to load CSV files from census_historical_migration/data folder into fac-private-s3 bucket.

```bash
docker compose run --rm web python manage.py fac_s3 \
gsa-fac-private-s3 \
fac-private-s3 \
--upload \
--src census_historical_migration/data
```

3. In the FAC/backend folder, run the following to read the CSV files from gsa-fac-private-s3 bucket and load into Postgres.
3. In the FAC/backend folder, run the following to read the CSV files from fac-private-s3 bucket and load into Postgres.

```bash
docker compose run --rm web python manage.py \
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import argparse
import time

from util import (
from census_historical_migration.throwaway_scripts.util import (
trigger_migration_workflow,
)
import subprocess # nosec
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
import subprocess # nosec
import time

from util import trigger_migration_workflow
from census_historical_migration.throwaway_scripts.util import (
trigger_migration_workflow,
)

# This throwaway script spits out code that can be
# copy-pasted into a bash script, or directly into the command line.
Expand Down
6 changes: 2 additions & 4 deletions backend/config/db_url.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
from django.core.exceptions import ImproperlyConfigured


def get_db_url_from_vcap_services(
vcap,
):
def get_db_url_from_vcap_services(vcap, db_instance_name="fac-db"):
database_url = None
for db_service in vcap.get("aws-rds", []):
if db_service.get("instance_name") == "fac-db":
if db_service.get("instance_name") == db_instance_name:
database_url = db_service["credentials"]["uri"]
break

Expand Down
Loading
Loading