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

Adding async redis caching #811

Merged
merged 95 commits into from
Nov 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
95 commits
Select commit Hold shift + click to select a range
8f7b6ab
First set of API refactor changes
Aug 27, 2020
d4c65fa
added pins route and Gzip
Aug 28, 2020
63cc3b7
first draft of legacy endpoints
Sep 1, 2020
8886ca7
fixing lint issues from flake8
Sep 1, 2020
35628ff
added support for deploying new API in Docker
Sep 2, 2020
bd4ef1e
new date parsing and config changes
Sep 2, 2020
cc995e0
more docker and config changes plus README
Sep 3, 2020
58a340a
default LEGACY_MODE to True
Sep 3, 2020
d1b5daf
DB seed needs database URL
Sep 3, 2020
e53dbab
YAML fix
Sep 3, 2020
f32f628
compose networking
Sep 3, 2020
11b9441
set test default config
Sep 3, 2020
aef7f67
updated missing .env.example settings
Sep 3, 2020
a4cb368
postman tests accept either 400 or 422 for bad input
jmensch1 Sep 3, 2020
5b916f8
comparison set validation
jmensch1 Sep 4, 2020
a1f94c7
model models and added simple entity cache
Sep 8, 2020
986ba3e
added cache status check
Sep 8, 2020
6ed9777
fixing flake8
Sep 8, 2020
1dcf5f5
disabling cache build
Sep 8, 2020
3911501
first version of alembic
Sep 9, 2020
d7bc8f3
added testing
Sep 11, 2020
e4b4fc7
updating ENV and requirements
Sep 11, 2020
69fec6c
turned testing off
Sep 11, 2020
5316119
test tweaks
Sep 11, 2020
d8379dd
dockerignore changes
Sep 11, 2020
fa68515
adding cwd to pythonpath
Sep 11, 2020
05ac6ab
fixed db env settings
Sep 11, 2020
0c473fa
setting db to test in env
Sep 11, 2020
c6e7a79
don't add _test to db name if there
Sep 11, 2020
b8795b9
more reliable tests
Sep 11, 2020
6126a68
more test cleanup
Sep 11, 2020
e9db6da
always add map/vis views
Sep 12, 2020
52baa31
replacing db tests
Sep 12, 2020
370de62
setting testing
Sep 12, 2020
8fe0c22
more test cleanup
Sep 12, 2020
6e62c67
fix flake8
Sep 12, 2020
40dac4e
updated libraries
Sep 12, 2020
3d2d5f7
slimming docker image
Sep 12, 2020
8170c3c
removed lru decorator
Sep 12, 2020
e44b669
logging response text on postman test failure
jmensch1 Sep 12, 2020
d603132
Merge branch 'add-alembic' of https://github.com/hackforla/311-data i…
jmensch1 Sep 12, 2020
193b5ca
postman logging
jmensch1 Sep 13, 2020
155350f
running CI on push
jmensch1 Sep 13, 2020
a9c970a
more postman logging
jmensch1 Sep 13, 2020
a66ea53
commented build_cache
jmensch1 Sep 13, 2020
a066a0c
linting
jmensch1 Sep 13, 2020
1f0df0f
logging 500 errors for all positive postman tests
jmensch1 Sep 13, 2020
f40a7cd
revert to 2 databases
Sep 16, 2020
60702ed
Merge branch 'add-alembic' of https://github.com/hackforla/311-data i…
Sep 16, 2020
7c05209
testing to false
Sep 16, 2020
2205bc7
remove views from db_seed
Sep 16, 2020
d846040
removed db reset
Sep 16, 2020
9c09fd5
added data file
Sep 16, 2020
070d75e
removing TESTING env
Sep 16, 2020
65a5335
removing from api.env
Sep 16, 2020
fa7de52
fixing flake8
Sep 16, 2020
8dc6a0b
error improvement
Sep 16, 2020
711b39f
1 more change
Sep 16, 2020
60589b0
undo docker compose change
Sep 16, 2020
d649c45
test database logging
Sep 18, 2020
a89155b
keep test db and new db fixture
Sep 20, 2020
a2698cf
seed file and better alembic logging
Sep 20, 2020
fd0e99c
adding env for seed
Sep 20, 2020
af2135d
fix env
Sep 20, 2020
d53f499
weird cluster fix
Sep 20, 2020
a59fe2f
LAST_WEEK to YEAR_TO_DATE in cypress
Sep 20, 2020
87ffbd0
type selector change
Sep 20, 2020
ebd5b1b
direct request type all
Sep 20, 2020
6829636
handling 10K+
Sep 20, 2020
46cd64a
adding coverage
Sep 20, 2020
8fc30d1
added async redis caching
Sep 22, 2020
2eabea3
flake fix
Sep 22, 2020
8dd1c75
turning off legacy mode
Sep 22, 2020
ac21516
added map/pins placeholder
Sep 22, 2020
0a8a262
added cache retries, timeout + pool changes
Sep 23, 2020
39c2c9f
api status check and test
Sep 23, 2020
9c1caab
adding sentry
Sep 23, 2020
559366a
sentry tweaks
Sep 23, 2020
efce220
remove weirdness
Sep 23, 2020
e846e9e
fixing requirements
Sep 23, 2020
c29a8ba
works with new UI, pins, open-requests
Sep 25, 2020
edc8616
fixed date format problem
Sep 25, 2020
1ecdfd3
using gunicorn for API
Sep 25, 2020
7f60721
added caching to open-request and reset-cache tool
Sep 29, 2020
3a26baa
porting github and email services
Oct 6, 2020
b6a2aed
refactor status service
Oct 6, 2020
1143401
utilities refactor
Oct 6, 2020
d49b8b9
ported reports
Oct 6, 2020
41a4763
fixed bug in time reports
Oct 7, 2020
8479dfc
removed legacy service calls
Oct 7, 2020
05ea638
made SENTRY URL configurable
mattyweb Oct 19, 2020
decee73
adding SENTRY URL
mattyweb Oct 19, 2020
229e9b4
added feedback test w/201 code
mattyweb Oct 19, 2020
bcf930b
minor refactoring and new routes
mattyweb Oct 19, 2020
0027fa7
added TODOs
mattyweb Oct 19, 2020
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
12 changes: 6 additions & 6 deletions .github/workflows/Continuous_Integration_Backend.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: CI_Backend

on:
pull_request:
paths:
- 'server/**'
on: [push]
# pull_request:
# paths:
# - 'server/**'

defaults:
run:
Expand All @@ -23,8 +23,8 @@ jobs:
docker-compose up --no-start api

- name: Seed DB and Run Api
run: |
docker-compose run api python bin/db_seed.py --file data/requests.csv.gz
run: |
docker-compose run -e TESTING=True api alembic upgrade head
docker-compose up -d api

- name: Linting
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,6 @@ yarn-error.log*
# config
config.js
.env

# builds
dist
14 changes: 7 additions & 7 deletions e2e/cypress/integration/e2e_tests.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ describe('311 Data', () => {
const {_} = Cypress

context('Explore My Council\'s 311 Data', () => {
it('Map: Last Week, Dead Animal [DAN]', () => {
it('Map: Year-to-date, Dead Animal [DAN]', () => {

cy.server()
cy.route({
Expand All @@ -19,9 +19,9 @@ describe('311 Data', () => {
cy.get('.menu-tabs > :nth-child(1)').click()
cy.get('.active').click()
cy.get('.dropdown-trigger > .button').click()
cy.get('[value="LAST_WEEK"]').click()
cy.get('[value="YEAR_TO_DATE"]').click()
cy.get(':nth-child(2) > .select-group-content > .select-item > .select-item-box').click()
cy.get('#type-selector-container > div.columns.is-0 > div:nth-child(1) > div:nth-child(2) > span > input').click({force: true})
cy.get('#checkbox-request-checkbox-all').click({force: true})
cy.get('#btn-sidebar-submit-button').click()

cy.wait('@getFilterList').should((xhr) => {
Expand All @@ -41,7 +41,7 @@ describe('311 Data', () => {
})
})

it('Data Visualization: Last Week, Dead Animal [DAN]', () => {
it('Data Visualization: Year-to-date, Dead Animal [DAN]', () => {

cy.server()
cy.route({
Expand All @@ -56,9 +56,9 @@ describe('311 Data', () => {
cy.get('.navbar-end > :nth-child(1)').click()
cy.get('.menu-tabs > :nth-child(2)').click()
cy.get('.dropdown-trigger > .button').click()
cy.get('[value="LAST_WEEK"]').click()
cy.get('[value="YEAR_TO_DATE"]').click()
cy.get(':nth-child(2) > .select-group-content > .select-item > .select-item-box').click()
cy.get('#type-selector-container > div.columns.is-0 > div:nth-child(1) > div:nth-child(2) > span > input').click({force: true})
cy.get('#checkbox-request-checkbox-all').click({force: true})
cy.get('#btn-sidebar-submit-button').click()

cy.wait('@getFilterList').should((xhr) => {
Expand All @@ -81,7 +81,7 @@ describe('311 Data', () => {
cy.visit('/')
cy.get('#navbar > div > div:nth-child(2)').click()
cy.get('#date-selector-dropdown > .dropdown-trigger > .button').click()
cy.get('[value="LAST_WEEK"]').click()
cy.get('[value="YEAR_TO_DATE"]').click()
cy.get('.district-selector > :nth-child(1)').click()
cy.get('#district-selector-dropdown > .dropdown-trigger > .button').click()
cy.get('[value="nc"]').click()
Expand Down
6 changes: 5 additions & 1 deletion e2e/cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ import '@testing-library/cypress/add-commands'
//import 'cypress-mailosaur'

Cypress.Commands.add('format_number_with_K', (value) => {
return ((value / 1000).toFixed(1)) + "K"
if (value > 9999) {
return ((value / 1000).toFixed(0)) + "K"
} else {
return ((value / 1000).toFixed(1)) + "K"
}
})

Cypress.Commands.add('format_number_with_comma', (value) => {
Expand Down
79 changes: 30 additions & 49 deletions server/.env.example
Original file line number Diff line number Diff line change
@@ -1,58 +1,39 @@

############################### API SETTINGS #############################

# Server
HOST=0.0.0.0
PORT=5000
DEBUG=0
ACCESS_LOG=1
AUTO_RELOAD=1
WORKERS=1
TMP_DIR=./__tmp__
UPDATE_ON_START=0

# Database
DATABASE_URL=postgresql://311_user:311_pass@db:5432/311_db
DATABASE_LOG_QUERIES=0

# Redis
REDIS_ENABLED=1
REDIS_URL=redis://redis:6379
REDIS_TTL_SECONDS=3600

# Picklebase
PICKLEBASE_ENABLED=0
PICKLEBASE_BATCH_SIZE=400000

# Picklecache
PICKLECACHE_ENABLED=0
PICKLECACHE_TTL_SECONDS=3600

# Socrata
SOCRATA_TOKEN=
SOCRATA_BATCH_SIZE=50000

# Github
######################### DOCKER-COMPOSE SETTINGS ########################

COMPOSE_PROJECT_NAME=311_data

# host/public configs
API_HOST_PORT=5000
DB_HOST_PORT=5433

# api config
DEBUG=True
API_RESTART_POLICY=no
APP_PORT=5000
API_LEGACY_MODE=False

# db connection config
DB_HOST=db
DB_PORT=5432
DB_USER=311_user
DB_PASS=311_pass
DB_NAME=311_db_test
DB_ECHO=False

############################ 3RD PARTY TOOLS ##############################

# GitHub
GITHUB_TOKEN=
GITHUB_ISSUES_URL=https://api.github.com/repos/hackforla/311-data-support/issues
GITHUB_PROJECT_URL=
GITHUB_SHA=DEVELOPMENT

# Slack
SLACK_WEBHOOK_URL=
SLACK_ERROR_CODES=[400, 500]
GITHUB_CODE_VERSION=0.1.1

# Sendgrid
SENDGRID_API_KEY=
SENDGRID_API_KEY=33333333

######################### DOCKER-COMPOSE SETTINGS ########################

COMPOSE_PROJECT_NAME=311_data
DB_USER=311_user
DB_PASS=311_pass
DB_NAME=311_db
DB_HOST_PORT=5433
API_HOST_PORT=5000
API_RESTART_POLICY=no
# Sentry
SENTRY_URL="https://[email protected]/5439266"

################################# OVERRIDES ##############################
############################################################################
4 changes: 3 additions & 1 deletion server/.gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
*.env
.env

/api/__tmp__
/jmeter/out

__pycache__
.pytest_cache

__working__
Binary file added server/api/.coverage
Binary file not shown.
15 changes: 15 additions & 0 deletions server/api/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Ignore
*

# Don't ignore
!requirements.txt

!Dockerfile
!README.md
!alembic
!alembic.ini
!bin
!code
!setup.cfg
!src
!tests
32 changes: 16 additions & 16 deletions server/api/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
FROM python:3.7-slim
FROM python:3.7-slim-buster

RUN apt-get update && \
apt-get install -yq \
python3 \
python3-dev \
gcc \
g++ \
gfortran \
musl-dev && \
pip install --upgrade pip
RUN apt-get update \
&& apt-get install -y \
gcc \
g++ \
&& apt-get clean

COPY requirements.txt /home/api/
WORKDIR /home/api

COPY requirements.txt .

RUN pip install --no-cache-dir -r /home/api/requirements.txt

COPY setup.cfg /home/api/
COPY /bin /home/api/bin/
COPY .env* /src /home/api/src/
ENV APP_HOST=0.0.0.0
# need add the src folder to sys.path for compatibility
ENV PYTHONPATH=.:/home/api/code:/home/api/src

WORKDIR /home/api
EXPOSE 5000

COPY . .

CMD python bin/api_check.py && python bin/api_start.py
CMD gunicorn lacity_data_api.asgi:app -w 4 -k uvicorn.workers.UvicornWorker -b 0.0.0.0:5000
16 changes: 11 additions & 5 deletions server/api/Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,29 @@ verify_ssl = true
pytest-asyncio = "*"
pytest = "*"
flake8 = "*"
requests = "*"
pytest-cov = "*"

[packages]
numpy = "*"
pandas = "*"
psycopg2-binary = "*"
pysupercluster = "*"
python-dotenv = "*"
redis = "*"
requests-async = "*"
sanic = "*"
sanic-plugins-framework = "*"
sanic-cors = "*"
sanic-compress = "*"
sendgrid = "*"
sodapy = "*"
SQLAlchemy = "*"
tabulate = "*"
gino = {extras = ["starlette"], version = "*"}
fastapi = "*"
uvicorn = "*"
alembic = "*"
geopandas = "*"
ujson = "*"
sentry-sdk = "*"
aiocache = {extras = ["redis"], version = "*"}
gunicorn = "*"

[requires]
python_version = "3.7"
Loading