Skip to content

Commit c1db533

Browse files
committed
Merge remote-tracking branch 'origin/dev' into krivard/covid_hosp-facility-running-time
2 parents 158d8aa + 79cd6d6 commit c1db533

File tree

16 files changed

+136
-3101
lines changed

16 files changed

+136
-3101
lines changed
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
name: Performance testing
2+
3+
# Run when a PR comment is created (issues and PRs are considered the same entity in the GitHub API)
4+
on:
5+
issue_comment:
6+
types: [created]
7+
8+
# Add some extra perms to comment on a PR
9+
permissions:
10+
pull-requests: write
11+
contents: read
12+
13+
jobs:
14+
run-perftests:
15+
# Make sure 1. this is a PR, not an issue 2. it contains "/run performance test" anywhere in the body
16+
if: github.event.issue.pull_request && contains(github.event.comment.body, '/run performance test')
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: Set up WireGuard
20+
uses: egor-tensin/[email protected]
21+
with:
22+
endpoint: '${{ secrets.WG_PERF_ENDPOINT }}'
23+
endpoint_public_key: '${{ secrets.WG_PERF_ENDPOINT_PUBLIC_KEY }}'
24+
ips: '${{ secrets.WG_PERF_IPS }}'
25+
allowed_ips: '${{ secrets.WG_PERF_ALLOWED_IPS }}'
26+
private_key: '${{ secrets.WG_PERF_PRIVATE_KEY }}'
27+
- name: Check out repository
28+
uses: actions/checkout@v3
29+
# Previous step checks out default branch, so we check out the pull request's branch
30+
- name: Switch to PR branch
31+
run: |
32+
hub pr checkout ${{ github.event.issue.number }}
33+
env:
34+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
35+
- name: Set up repository # mimics install.sh in the README except that delphi is cloned from the PR rather than main
36+
run: |
37+
cd ..
38+
mkdir -p driver/repos/delphi
39+
cd driver/repos/delphi
40+
git clone https://github.com/cmu-delphi/operations
41+
git clone https://github.com/cmu-delphi/utils
42+
git clone https://github.com/cmu-delphi/flu-contest
43+
git clone https://github.com/cmu-delphi/nowcast
44+
cd ../../
45+
46+
cd ..
47+
cp -R delphi-epidata driver/repos/delphi/delphi-epidata
48+
cd -
49+
50+
ln -s repos/delphi/delphi-epidata/dev/local/Makefile
51+
- name: Build & run epidata
52+
run: |
53+
cd ../driver
54+
sudo make web sql="${{ secrets.DB_CONN_STRING }}"
55+
- name: Check out delphi-admin
56+
uses: actions/checkout@v3
57+
with:
58+
repository: cmu-delphi/delphi-admin
59+
token: ${{ secrets.CMU_DELPHI_DEPLOY_MACHINE_PAT }}
60+
path: delphi-admin
61+
- name: Build & run Locust
62+
continue-on-error: true # sometimes ~2-5 queries fail, we shouldn't end the run if that's the case
63+
run: |
64+
cd delphi-admin/load-testing/locust
65+
docker build -t locust .
66+
export CSV=v4-requests-small.csv
67+
touch output_stats.csv && chmod 666 output_stats.csv
68+
touch output_stats_history.csv && chmod 666 output_stats_history.csv
69+
touch output_failures.csv && chmod 666 output_failures.csv
70+
touch output_exceptions.csv && chmod 666 output_exceptions.csv
71+
docker run --net=host -v $PWD:/mnt/locust -e CSV="/mnt/locust/${CSV}" locust -f /mnt/locust/v4.py --host http://127.0.0.1:10080/ --users 10 --spawn-rate 1 --headless -i "$(cat ${CSV} | wc -l)" --csv=/mnt/locust/output
72+
- name: Archive results as artifacts
73+
uses: actions/upload-artifact@v3
74+
with:
75+
name: locust-output
76+
path: |
77+
delphi-admin/load-testing/locust/output_*.csv
78+
79+
comment-output:
80+
runs-on: ubuntu-latest
81+
if: success() || failure() # but not if skipped
82+
needs: run-perftests
83+
steps:
84+
- name: Comment run results
85+
# URL that links to run results
86+
env:
87+
GITHUB_WORKFLOW_URL: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
88+
uses: actions/github-script@v5
89+
with:
90+
github-token: ${{secrets.GITHUB_TOKEN}}
91+
script: |
92+
github.rest.issues.createComment({
93+
issue_number: context.issue.number,
94+
owner: context.repo.owner,
95+
repo: context.repo.repo,
96+
body: '✅ Performance tests complete! Click here to view results: ${{ env.GITHUB_WORKFLOW_URL }}'
97+
})

deploy.json

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@
2525
"match": "^.*\\.(py)$",
2626
"add-header-comment": true
2727
},
28+
{
29+
"type": "move",
30+
"src": "src/server/utils",
31+
"dst": "[[package]]/server/utils/",
32+
"match": "^.*\\.(py)$",
33+
"add-header-comment": true
34+
},
2835
{
2936
"type": "move",
3037
"src": "src/server/endpoints",
@@ -74,11 +81,6 @@
7481
"dst": "[[package]]/acquisition/cdcp/",
7582
"match": "^.*\\.(py)$",
7683
"add-header-comment": true
77-
},{
78-
"type": "move",
79-
"src": "src/acquisition/cdcp/cdc_upload.php",
80-
"dst": "[[auto_web]]/cdc_upload/index.php",
81-
"add-header-comment": true
8284
},
8385

8486
"// acquisition - ght",
@@ -116,16 +118,6 @@
116118
"dst": "[[package]]/acquisition/wiki/",
117119
"match": "^.*\\.(py)$",
118120
"add-header-comment": true
119-
},{
120-
"type": "move",
121-
"src": "src/acquisition/wiki/master.php",
122-
"dst": "[[auto_web]]/wiki/master.php",
123-
"add-header-comment": true
124-
},{
125-
"type": "move",
126-
"src": "src/acquisition/wiki/dashboard.php",
127-
"dst": "[[auto_web]]/wiki/index.php",
128-
"add-header-comment": true
129121
},
130122

131123
"// acquisition - flusurv",

dev/docker/web/epidata/Dockerfile

Lines changed: 0 additions & 11 deletions
This file was deleted.

dev/docker/web/epidata/README.md

Lines changed: 0 additions & 22 deletions
This file was deleted.

dev/docker/web/epidata/assets/database_config.php

Lines changed: 0 additions & 7 deletions
This file was deleted.

dev/local/Makefile

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ LOG_DB:=delphi_database_epidata_$(NOW).log
6767
WEB_CONTAINER_ID:=$(shell docker ps -q --filter 'name=delphi_web_epidata')
6868
DATABASE_CONTAINER_ID:=$(shell docker ps -q --filter 'name=delphi_database_epidata')
6969

70+
M1=
71+
ifeq ($(shell uname -smp), Darwin arm64 arm)
72+
$(info M1 system detected, changing docker platform to linux/amd64.)
73+
override M1 =--platform linux/amd64
74+
endif
7075

7176
.PHONY=web
7277
web:
@@ -80,11 +85,14 @@ web:
8085

8186
@# Build the web_epidata image
8287
@cd repos/delphi/delphi-epidata;\
83-
docker build -t delphi_web_epidata -f ./devops/Dockerfile .;\
88+
docker build -t delphi_web_epidata\
89+
$(M1) \
90+
-f ./devops/Dockerfile .;\
8491
cd -
8592

8693
@# Run the web server
8794
@docker run --rm -p 127.0.0.1:10080:80 \
95+
$(M1) \
8896
--env "SQLALCHEMY_DATABASE_URI=$(sqlalchemy_uri)" \
8997
--env "FLASK_SECRET=abc" --env "FLASK_PREFIX=/epidata" --env "LOG_DEBUG" \
9098
--network delphi-net --name delphi_web_epidata \
@@ -102,10 +110,12 @@ db:
102110

103111
@# Build the database_epidata image
104112
@docker build -t delphi_database_epidata \
113+
$(M1) \
105114
-f repos/delphi/delphi-epidata/dev/docker/database/epidata/Dockerfile .
106115

107116
@# Run the database
108117
@docker run --rm -p 127.0.0.1:13306:3306 \
118+
$(M1) \
109119
--network delphi-net --name delphi_database_epidata \
110120
--cap-add=sys_nice \
111121
delphi_database_epidata >$(LOG_DB) 2>&1 &
@@ -120,6 +130,7 @@ db:
120130
.PHONY=py
121131
py:
122132
@docker build -t delphi_web_python \
133+
$(M1) \
123134
-f repos/delphi/delphi-epidata/dev/docker/python/Dockerfile .
124135

125136
.PHONY=all
@@ -128,6 +139,7 @@ all: db web py
128139
.PHONY=test
129140
test:
130141
@docker run -i --rm --network delphi-net \
142+
$(M1) \
131143
--mount type=bind,source=$(CWD)repos/delphi/delphi-epidata,target=/usr/src/app/repos/delphi/delphi-epidata,readonly \
132144
--mount type=bind,source=$(CWD)repos/delphi/delphi-epidata/src,target=/usr/src/app/delphi/epidata,readonly \
133145
--env "SQLALCHEMY_DATABASE_URI=$(sqlalchemy_uri)" \
@@ -137,6 +149,7 @@ test:
137149
.PHONY=bash
138150
bash:
139151
@docker run -it --rm --network delphi-net \
152+
$(M1) \
140153
--mount type=bind,source=$(CWD)repos/delphi/delphi-epidata,target=/usr/src/app/repos/delphi/delphi-epidata,readonly \
141154
--mount type=bind,source=$(CWD)repos/delphi/delphi-epidata/src,target=/usr/src/app/delphi/epidata,readonly \
142155
--env "SQLALCHEMY_DATABASE_URI=$(sqlalchemy_uri)" \

docs/epidata_development.md

Lines changed: 3 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ above. The base images are built first, followed by the derived
116116
`epidata`-specific images.
117117

118118
- The [`delphi_web_epidata` image](https://github.com/cmu-delphi/delphi-epidata/blob/main/dev/docker/web/epidata/README.md) adds
119-
the Epidata API to the `delphi_web` image.
119+
the Epidata API to the `delphi_web_epidata` image.
120120
- The
121121
[`delphi_database_epidata` image](https://github.com/cmu-delphi/delphi-epidata/blob/main/dev/docker/database/epidata/README.md)
122122
adds user accounts, `epidata` & other appropriate databases, and relevant tables
@@ -125,14 +125,8 @@ above. The base images are built first, followed by the derived
125125
From the root of your workspace, all of the images can be built as follows:
126126

127127
```bash
128-
docker build -t delphi_web \
129-
-f repos/delphi/operations/dev/docker/web/Dockerfile .
130-
131-
docker build -t delphi_web_epidata \
132-
-f repos/delphi/delphi-epidata/dev/docker/web/epidata/Dockerfile .
133-
134-
docker build -t delphi_database \
135-
-f repos/delphi/operations/dev/docker/database/Dockerfile .
128+
docker build -t delphi_web_epidata\
129+
-f ./devops/Dockerfile .;\
136130

137131
docker build -t delphi_database_epidata \
138132
-f repos/delphi/delphi-epidata/dev/docker/database/epidata/Dockerfile .
@@ -394,33 +388,3 @@ The command above maps two local directories into the container:
394388
- `/repos/delphi/delphi-epidata/src`: Just the source code, which forms the
395389
container's `delphi.epidata` python package.
396390

397-
### server code
398-
399-
Local web sources (e.g. PHP files) can be bind-mounted into a
400-
`delphi_web_epidata` container as follows:
401-
402-
```bash
403-
docker run --rm -p 127.0.0.1:10080:80 \
404-
--mount type=bind,source="$(pwd)"/repos/delphi/delphi-epidata/src/server/api.php,target=/var/www/html/epidata/api.php,readonly \
405-
--mount type=bind,source="$(pwd)"/repos/delphi/delphi-epidata/src/server/api_helpers.php,target=/var/www/html/epidata/api_helpers.php,readonly \
406-
--network delphi-net --name delphi_web_epidata \
407-
delphi_web_epidata
408-
```
409-
410-
The command above mounts two specific files into the image. It may be tempting
411-
to bind mount the `src/server` directory rather than specific files, however
412-
that is currently problematic for a couple of reasons:
413-
414-
1. `server/.htaccess` [from the local repository](https://github.com/cmu-delphi/delphi-epidata/blob/main/src/server/.htaccess) uses
415-
the `Header` directive. However, the webserver in the container doesn't have
416-
the corresponding module enabled. This causes the server to deny access to
417-
the API.
418-
2. `server/database_config.php`
419-
[in the image](https://github.com/cmu-delphi/delphi-epidata/blob/main/dev/docker/web/epidata/assets/database_config.php) contains
420-
database credentials for use in conjunction with the
421-
`delphi_database_epidata` container during development. However, the same
422-
file from [the local repository](https://github.com/cmu-delphi/delphi-epidata/blob/main/src/server/database_config.php) only
423-
contains placeholder values. This prevents communication with the database.
424-
425-
There is currently no benefit to bind-mounting sources into the database
426-
container because schema changes require restarting the container anyway.

docs/new_endpoint_tutorial.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -273,10 +273,8 @@ already built the `delphi_python` image above:
273273

274274
```bash
275275
# build web and database images for epidata
276-
docker build -t delphi_web \
277-
-f repos/delphi/operations/dev/docker/web/Dockerfile .
278-
docker build -t delphi_web_epidata \
279-
-f repos/delphi/delphi-epidata/dev/docker/web/epidata/Dockerfile .
276+
docker build -t delphi_web_epidata\
277+
-f ./devops/Dockerfile .;\
280278
docker build -t delphi_database_epidata \
281279
-f repos/delphi/delphi-epidata/dev/docker/database/epidata/Dockerfile .
282280

integrations/server/test_covidcast.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
# first party
1212
from delphi_utils import Nans
1313
from delphi.epidata.acquisition.covidcast.test_utils import CovidcastBase, CovidcastTestRow
14+
from delphi.epidata.client.delphi_epidata import Epidata
1415

1516
# use the local instance of the Epidata API
1617
BASE_URL = 'http://delphi_web_epidata/epidata/api.php'
@@ -22,11 +23,10 @@ def localSetUp(self):
2223
"""Perform per-test setup."""
2324
self._db._cursor.execute('update covidcast_meta_cache set timestamp = 0, epidata = "[]"')
2425

25-
def request_based_on_row(self, row: CovidcastTestRow, extract_response: Callable = lambda x: x.json(), **kwargs):
26+
def request_based_on_row(self, row: CovidcastTestRow, **kwargs):
2627
params = self.params_from_row(row, endpoint='covidcast', **kwargs)
27-
response = requests.get(BASE_URL, params=params)
28-
response.raise_for_status()
29-
response = extract_response(response)
28+
Epidata.BASE_URL = BASE_URL
29+
response = Epidata.covidcast(**params)
3030

3131
return response
3232

@@ -155,7 +155,6 @@ def test_csv_format(self):
155155
# NB 'format' is a Python reserved word
156156
response = self.request_based_on_row(
157157
row,
158-
extract_response=lambda resp: resp.text,
159158
**{'format':'csv'}
160159
)
161160

@@ -194,7 +193,7 @@ def test_fields(self):
194193
row = self._insert_placeholder_set_one()
195194

196195
# limit fields
197-
response = self.request_based_on_row(row, fields='time_value,geo_value')
196+
response = self.request_based_on_row(row, **{"fields":"time_value,geo_value"})
198197

199198
expected = row.as_api_compatibility_row_dict()
200199
expected_all = {

0 commit comments

Comments
 (0)