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

Create job to recycle dashboards every night #1023

Merged
merged 2 commits into from
Mar 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions server/locust/Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ verify_ssl = true
locust = "*"

[packages]
locust = "*"

[requires]
python_version = "3.6"
828 changes: 680 additions & 148 deletions server/locust/Pipfile.lock

Large diffs are not rendered by default.

20 changes: 17 additions & 3 deletions server/locust/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
# Run this with Docker
# Locust Performance Testing

The project is set up to use Locust for performance testing. Having a python-based tool should make programmatic testing easier, but for now there is just a single test to replicate a user first visiting the site as most of the data gets cached in the React client on initial load.

## Running the Locust tests

Tests are set up to be run locally from the shell using the headless config. To run, set up a virtual environment for the locust directory and run pip install (or pipenv install or sync).

Once the locust dependency is installed you can just run the locust command from this directory and it will pick up setting from the locust.conf and run the test in locustfile.py.

```bash
docker run -p 8089:8089 -v $PWD:/mnt/locust locustio/locust -f /mnt/locust/locustfile.py
locust
```

http://dev-api.311-data.org/
## Run the Locust test with Docker

Alternatively you can run this as a docker image.

```bash
docker run -p 8089:8089 -v $PWD:/mnt/locust locustio/locust -f /mnt/locust/locustfile.py
```
16 changes: 14 additions & 2 deletions server/locust/locustfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,20 @@ def status_api(self):
self.client.get("/status/api")

@task
def open_requests(self):
self.client.get("/requests/pins/open")
def councils(self):
self.client.get("/councils")

@task
def types(self):
self.client.get("/types")

@task
def geojson(self):
self.client.get("/geojson")

# @task
# def open_requests(self):
# self.client.get("/requests/pins/open")

@task
def open_requests_counts(self):
Expand Down
2 changes: 2 additions & 0 deletions server/prefect/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ reset_db = false
temp_folder = ""
# set to local API instance or override with PREFECT__API_URL
api_url = "http://localhost:5000"
# set to local API instance or override with PREFECT__API_URL
report_server_url = "https://dash-reporting.tofn9kh9mlm7g.us-east-1.cs.amazonlightsail.com"
# whether the data update is being run in a testing, development or production environment
stage = "Testing"
# whether to vacuum database and reset stats after load
Expand Down
11 changes: 8 additions & 3 deletions server/prefect/flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,19 @@
complete = postgres.complete_load()

# clear the API cache
cache = cache.clear_cache()
clear = cache.clear_cache()

# clear the API cache
reload = cache.reload_reports()

# make sure prep runs before load
flow.add_edge(upstream_task=prep, downstream_task=load)
# make sure load runs before complete
flow.add_edge(upstream_task=load, downstream_task=complete)
# make sure load runs before complete
flow.add_edge(upstream_task=complete, downstream_task=cache)
# make sure complete runs before cache is cleared
flow.add_edge(upstream_task=complete, downstream_task=clear)
# make sure load runs before complete
flow.add_edge(upstream_task=clear, downstream_task=reload)

if __name__ == "__main__":
logger = prefect.context.get("logger")
Expand Down
17 changes: 17 additions & 0 deletions server/prefect/tasks/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from prefect.utilities.tasks import task

CACHE_PATH = "/status/reset-cache"
RELOAD_PATH = "/reload"


@task
Expand All @@ -20,3 +21,19 @@ def clear_cache():
logger.info(f"Cache clearing successful: {reset_path}")
else:
logger.info("Cache clearing failed")


@task
def reload_reports():
"""
clears the server cache once new data is done loading
"""
logger = prefect.context.get("logger")
report_server_url = prefect.config.report_server_url
reload_path = f"{report_server_url}{RELOAD_PATH}"
response = requests.get(reload_path)

if response.status_code == 200:
logger.info(f"Report reloading successful: {reload_path}")
else:
logger.info("Report reloading failed")