Skip to content

Commit 3fa2b60

Browse files
NRL-1666 Ran tests against perftest env, yay 🎉
1 parent 320475b commit 3fa2b60

File tree

4 files changed

+67
-20
lines changed

4 files changed

+67
-20
lines changed

‎Makefile‎

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,13 @@ TF_WORKSPACE_NAME ?= $(shell terraform -chdir=terraform/infrastructure workspace
1313
ENV ?= dev
1414
ACCOUNT ?= dev
1515
APP_ALIAS ?= default
16-
HOST ?= $(TF_WORKSPACE_NAME).api.record-locator.$(ENV).national.nhs.uk
16+
# HOST ?= $(TF_WORKSPACE_NAME).api.record-locator.$(ENV).national.nhs.uk
17+
# HOST ?= dev.api.record-locator.$(ENV).national.nhs.uk
18+
# HOST ?= perftest.record-locator.national.nhs.uk
19+
HOST ?= api.perftest.record-locator.national.nhs.uk
1720
ENV_TYPE ?= $(ENV)
18-
PERFTEST_TABLE_NAME ?= nhsd-nrlf--xaxel-deleteme-pointers-table
21+
# PERFTEST_TABLE_NAME ?= nhsd-nrlf--xaxel-deleteme-pointers-table
22+
PERFTEST_TABLE_NAME ?= perftest
1923

2024
export PATH := $(PATH):$(PWD)/.venv/bin
2125
export USE_SHARED_RESOURCES := $(shell poetry run python scripts/are_resources_shared_for_stack.py $(TF_WORKSPACE_NAME))
@@ -253,18 +257,30 @@ generate-perftest-permissions: ## Generate perftest permissions and add to nrlf_
253257

254258
# Run producer performance tests with configurable HOST and ENV_TYPE
255259
perftest-producer:
256-
@echo "Running producer performance tests with HOST=$(HOST) and ENV_TYPE=$(ENV_TYPE)"
257-
k6 run tests/performance/producer/perftest.js -e HOST=$(HOST) -e ENV_TYPE=$(ENV_TYPE) -e PERFTEST_TABLE_NAME=$(PERFTEST_TABLE_NAME)
260+
@echo "Running producer performance tests with HOST=$(HOST) and ENV_TYPE=$(ENV_TYPE) and DIST_PATH=$(DIST_PATH)"
261+
k6 run tests/performance/producer/perftest.js -e HOST=$(HOST) -e ENV_TYPE=$(ENV_TYPE) -e DIST_PATH=$(DIST_PATH)
258262

263+
264+
# perftest-consumer: perftest-prep-generate-pointer-table-extract generate-perftest-permissions
259265
perftest-consumer:
260-
@echo "Running consumer performance tests with HOST=$(HOST) and ENV_TYPE=$(ENV_TYPE)"
261-
k6 run tests/performance/consumer/perftest.js -e HOST=$(HOST) -e ENV_TYPE=$(ENV_TYPE)
266+
@echo "Running consumer performance tests with HOST=$(HOST) and ENV_TYPE=$(ENV_TYPE) and DIST_PATH=$(DIST_PATH)"
267+
k6 run tests/performance/consumer/perftest.js -e ENV_TYPE=$(ENV_TYPE) -e DIST_PATH=$(DIST_PATH) -e HOST=$(HOST)
268+
269+
perftest-prep-generate-producer-data:
270+
mkdir -p $(DIST_PATH)
271+
PYTHONPATH=. poetry run python tests/performance/perftest_environment.py generate_producer_data --output_dir="$(DIST_PATH)"
262272

263-
# Generates input csv for a given table
264-
perftest-prepare:
273+
perftest-prep-extract-consumer-data:
265274
mkdir -p $(DIST_PATH)
266-
PYTHONPATH=. poetry run python tests/performance/perftest_environment.py generate_pointer_table_extract $(PERFTEST_TABLE_NAME)
275+
PYTHONPATH=. poetry run python tests/performance/perftest_environment.py extract_consumer_data --output_dir="$(DIST_PATH)"
276+
277+
perftest-prep-generate-pointer-table-extract:
278+
mkdir -p $(DIST_PATH)
279+
PYTHONPATH=. poetry run python tests/performance/perftest_environment.py generate_pointer_table_extract --output_dir="$(DIST_PATH)"
280+
281+
perftest-prepare: perftest-prep-generate-producer-data perftest-prep-extract-consumer-data perftest-prep-generate-pointer-table-extract
282+
@echo "Prepared performance tests with PERFTEST_TABLE_NAME=$(PERFTEST_TABLE_NAME) and DIST_PATH=$(DIST_PATH)"
267283

268-
perftest-seed-data: perftest-prepare
269-
@echo "Seeding dynamo with data for performance tests with HOST=$(HOST) and ENV_TYPE=$(ENV_TYPE)"
270-
poetry run python tests/performance/consumer/perftest.js --table_name="" --px_with_pointers="" --pointers_per_px="" --type_dists="" --custodian_dists=""
284+
# perftest-seed-data: perftest-prepare
285+
# @echo "Seeding dynamo with data for performance tests with table_name=$(PERFTEST_TABLE_NAME) and ENV_TYPE=$(ENV_TYPE)"
286+
# poetry run python tests/performance/consumer/perftest.js --table_name="$(PERFTEST_TABLE_NAME)" --px_with_pointers="" --pointers_per_px="" --type_dists="" --custodian_dists=""

‎tests/performance/consumer/client_perftest.js‎

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,23 @@ import { check } from "k6";
33
import exec from "k6/execution";
44
import { CATEGORY_TYPE_GROUPS } from "../type-category-mappings.js";
55

6-
const csv = open("../producer_reference_data.csv");
6+
const csvPath = __ENV.DIST_PATH
7+
? `../../../${__ENV.DIST_PATH}/producer_reference_data.csv`
8+
: "../producer_reference_data.csv";
9+
const csv = open(csvPath);
710
const lines = csv.trim().split("\n");
811
// Skip header
912
const dataLines = lines.slice(1);
1013

14+
// console.log("__ENV", JSON.stringify(__ENV, null, 2));
15+
console.log("__ENV.HOST", JSON.stringify(__ENV.HOST, null, 2));
16+
1117
function getNextPointer() {
12-
// pick the next line accoording to iteration in scenario
18+
// pick the next line according to iteration in scenario
1319
const iter = exec.vu.iterationInScenario;
1420
const index = iter % dataLines.length;
1521
const line = dataLines[index];
22+
console.log("🚀 ~ getNextPointer ~ line:", line);
1623
const [count, pointer_id, pointer_type, custodian, nhs_number] = line
1724
.split(",")
1825
.map((field) => field.trim());
@@ -43,6 +50,7 @@ function getCustodianFromPointerId(pointer_id) {
4350
function checkResponse(res) {
4451
const is_success = check(res, { "status is 200": (r) => r.status === 200 });
4552
if (!is_success) {
53+
console.log("🚀 ~ checkResponse ~ res.status:", res.status);
4654
console.warn(res.json());
4755
}
4856
}
@@ -60,6 +68,11 @@ export function countDocumentReference() {
6068
const identifier = encodeURIComponent(
6169
`https://fhir.nhs.uk/Id/nhs-number|${nhs_number}`
6270
);
71+
72+
console.log(
73+
"🚀 ~ countDocumentReference ~ `https://${__ENV.HOST}/consumer/DocumentReference?_summary=count&subject:identifier=${identifier}`:",
74+
`https://${__ENV.HOST}/consumer/DocumentReference?_summary=count&subject:identifier=${identifier}`
75+
);
6376
const res = http.get(
6477
`https://${__ENV.HOST}/consumer/DocumentReference?_summary=count&subject:identifier=${identifier}`,
6578
{
@@ -73,6 +86,8 @@ export function readDocumentReference() {
7386
const { pointer_id } = getNextPointer();
7487
const custodian = getCustodianFromPointerId(pointer_id);
7588

89+
console.log("🚀 ~ countDocumentReference ~ __ENV.HOST:", __ENV.HOST);
90+
7691
const res = http.get(
7792
`https://${__ENV.HOST}/consumer/DocumentReference/${pointer_id}`,
7893
{
@@ -92,6 +107,8 @@ export function searchDocumentReference() {
92107
);
93108
const type = encodeURIComponent(`http://snomed.info/sct|${pointer_type}`);
94109

110+
console.log("🚀 ~ countDocumentReference ~ __ENV.HOST:", __ENV.HOST);
111+
95112
const res = http.get(
96113
`https://${__ENV.HOST}/consumer/DocumentReference?subject:identifier=${identifier}&type=${type}`,
97114
{
@@ -113,6 +130,8 @@ export function searchDocumentReferenceByCategory() {
113130
`http://snomed.info/sct|${category_code}`
114131
);
115132

133+
console.log("🚀 ~ countDocumentReference ~ __ENV.HOST:", __ENV.HOST);
134+
116135
const res = http.get(
117136
`https://${__ENV.HOST}/consumer/DocumentReference?subject:identifier=${identifier}&category=${category}`,
118137
{
@@ -131,6 +150,8 @@ export function searchPostDocumentReference() {
131150
type: `http://snomed.info/sct|${pointer_type}`,
132151
});
133152

153+
console.log("🚀 ~ countDocumentReference ~ __ENV.HOST:", __ENV.HOST);
154+
134155
const res = http.post(
135156
`https://${__ENV.HOST}/consumer/DocumentReference/_search`,
136157
body,
@@ -151,6 +172,8 @@ export function searchPostDocumentReferenceByCategory() {
151172
category: `http://snomed.info/sct|${category_code}`,
152173
});
153174

175+
console.log("🚀 ~ countDocumentReference ~ __ENV.HOST:", __ENV.HOST);
176+
154177
const res = http.post(
155178
`https://${__ENV.HOST}/consumer/DocumentReference/_search`,
156179
body,
@@ -168,6 +191,8 @@ export function countPostDocumentReference() {
168191
const body = JSON.stringify({
169192
"subject:identifier": `https://fhir.nhs.uk/Id/nhs-number|${nhs_number}`,
170193
});
194+
195+
console.log("🚀 ~ countDocumentReference ~ __ENV.HOST:", __ENV.HOST);
171196
const res = http.post(
172197
`https://${__ENV.HOST}/consumer/DocumentReference/_search?_summary=count`,
173198
body,
@@ -193,6 +218,9 @@ export function searchPostDocumentReferenceAccessDenied() {
193218
"nrl.ods-code": deniedCustodian,
194219
"nrl.app-id": "K6PerformanceTest",
195220
});
221+
222+
console.log("🚀 ~ countDocumentReference ~ __ENV.HOST:", __ENV.HOST);
223+
196224
const res = http.post(
197225
`https://${__ENV.HOST}/consumer/DocumentReference/_search`,
198226
body,

‎tests/performance/perftest_environment.py‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ def _get_pointers_table_name():
2424
return f"nhsd-nrlf--{perftest_table_name}-pointers-table"
2525

2626

27-
def extract_consumer_data(out="consumer_reference_data.json"):
27+
def extract_consumer_data(output_dir="."):
28+
out = output_dir + "/consumer_reference_data.json"
2829
table_name = _get_pointers_table_name()
2930
table = DYNAMODB.Table(table_name)
3031
scan_kwargs = {}
@@ -87,9 +88,9 @@ def __next__(self):
8788

8889

8990
def generate_producer_data(
91+
output_dir=".",
9092
proportion_existing=0.8, # Proportion of output that should be existing NHS numbers
9193
total_count=1000, # Total number of NHS numbers to output
92-
out="producer_reference_data.json",
9394
last_existing_nhs_number=None, # Optionally specify the last NHS number in the table
9495
):
9596
"""
@@ -98,12 +99,14 @@ def generate_producer_data(
9899
- total_count: total number of NHS numbers in output
99100
NHS numbers are generated in a semi-deterministic way, similar to the NFT seeding script.
100101
"""
102+
out = output_dir + "/producer_reference_data.json"
101103
table_name = _get_pointers_table_name()
102104
table = DYNAMODB.Table(table_name)
103105
scan_kwargs = {}
104106
done = False
105107
start_key = None
106108
existing_nhs_numbers = set()
109+
107110
# Scan DynamoDB table for all existing NHS numbers
108111
while not done:
109112
if start_key:
@@ -178,11 +181,12 @@ def __next__(self):
178181

179182

180183
def generate_pointer_table_extract(
181-
out="producer_reference_data.csv",
184+
output_dir=".",
182185
):
183186
"""
184187
Generate a CSV file containing all pointer IDs, pointer type, custodian, and nhs_number (patient).
185188
"""
189+
out = output_dir + "/producer_reference_data.csv"
186190
table_name = _get_pointers_table_name()
187191
table = DYNAMODB.Table(table_name)
188192
scan_kwargs = {}
@@ -192,8 +196,8 @@ def generate_pointer_table_extract(
192196
buffer_size = 1_000_000 # 10k rows needs ~3MB of RAM, so 1M rows needs ~300MB
193197
count = 1
194198

195-
with open(out, "w", newline="") as csvfile:
196-
writer = csv.writer(csvfile)
199+
with open(out, "w", newline="") as csv_file:
200+
writer = csv.writer(csv_file)
197201
writer.writerow(
198202
["count", "pointer_id", "pointer_type", "custodian", "nhs_number"]
199203
)

‎tests/performance/producer/seed_nft_tables.py‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
dynamodb = boto3.client("dynamodb")
44
resource = boto3.resource("dynamodb")
55

6-
logger.setLevel("ERROR")
76

87
# DOC_REF_TEMPLATE = load_document_reference("NFT-template")
98

0 commit comments

Comments
 (0)