Skip to content

Commit 5cd1939

Browse files
NRL-1884 Fix tests to use default location for input files rather than relying on prepare step to copy around. Include table name in info file rather than input file name
1 parent 16bda8d commit 5cd1939

File tree

7 files changed

+36
-16
lines changed

7 files changed

+36
-16
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ perftest-prepare: ## Prepare input files for producer & consumer perf tests
270270
mkdir -p "${DIST_PATH}/nft"
271271
aws s3 cp "s3://nhsd-nrlf--${ENV}-metadata/performance/seed-pointers-extract-${PERFTEST_TABLE_NAME}.zip" "${DIST_PATH}/pointer_extract-${PERFTEST_TABLE_NAME}.zip"
272272
unzip "${DIST_PATH}/pointer_extract-${PERFTEST_TABLE_NAME}.zip"
273-
cp "${DIST_PATH}/nft/seed-pointers-extract-${PERFTEST_TABLE_NAME}.csv" "${DIST_PATH}/seed-pointers-extract.csv"
273+
# cp "${DIST_PATH}/nft/seed-pointers-extract-${PERFTEST_TABLE_NAME}.csv" "${DIST_PATH}/seed-pointers-extract.csv"
274274
PYTHONPATH=. poetry run python ./tests/performance/generate_producer_distributions.py
275275

276276
perftest-producer: ## Run producer perf tests

scripts/seed_nft_tables.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88

99
import boto3
1010
import fire
11-
12-
# import json
1311
import numpy as np
1412

1513
from nrlf.core.boto import get_s3_client
@@ -22,6 +20,7 @@
2220
from nrlf.core.dynamodb.model import DocumentPointer
2321
from nrlf.core.logger import logger
2422
from nrlf.tests.data import load_document_reference
23+
from tests.performance.perftest_environment import create_extract_metadata_file
2524
from tests.performance.seed_data_constants import ( # DEFAULT_COUNT_DISTRIBUTIONS,
2625
CHECKSUM_WEIGHTS,
2726
CUSTODIAN_DISTRIBUTION_PROFILES,
@@ -89,7 +88,7 @@ def _make_seed_pointer(
8988

9089

9190
def _write_pointer_extract_to_file(table_name, pointer_data):
92-
local_csv_out = f"{nft_dist_path}/seed-pointers-extract-{table_name}.csv"
91+
local_csv_out = f"{nft_dist_path}/seed-pointers-extract.csv"
9392
local_meta_out = f"{nft_dist_path}/info.json"
9493

9594
print(f"writing pointer extract to files {local_csv_out} {local_meta_out}")
@@ -100,8 +99,7 @@ def _write_pointer_extract_to_file(table_name, pointer_data):
10099
writer.writerows(pointer_data)
101100
print(f"Pointer data saved to {local_csv_out}")
102101

103-
os.system(f"./scripts/get-current-info.sh > {local_meta_out}")
104-
print(f"Pointer extract metadata saved to {local_meta_out}")
102+
create_extract_metadata_file(table_name, nft_dist_path)
105103

106104

107105
def _populate_seed_table(

tests/performance/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Currently, this requires tearing down the existing environment and restoring fro
3636
2. once backed up, delete your table. In the AWS console: dynamodb > tables > your perftest table > actions > delete table
3737
3. Rerun the Deploy Account-wide infrastructure action.
3838
4. Terraform will create an empty table with the correct name & (most importantly!) read/write IAM policies.
39-
5. Delete the empty table created by terraform and restore from the backup, specifying the same table name you've defined in code.
39+
5. Delete the empty table created by terraform and restore from the backup, specifying the same table name you've defined in code & selecting the matching customer managed encryption key.
4040
6. Run the [Persistent Environment Deploy](https://github.com/NHSDigital/NRLF/actions/workflows/persistent-environment.yml) workflow against your branch & `perftest` to restore the environment with lambdas pointed at your chosen table.
4141
7. You can check this has been successful by checking the table name in the lambdas.
4242
- In the AWS console: Lambda > functions > pick any perftest-1 lambda > Configuration > Environment variables > `TABLE_NAME` should be your desired pointer table e.g. `nhsd-nrlf--perftest-baseline-pointers-table`

tests/performance/consumer/client_perftest.js

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

6-
const csvPath = __ENV.DIST_PATH
7-
? `../../../${__ENV.DIST_PATH}/seed-pointers-extract.csv`
8-
: "../seed-pointers-extract.csv";
6+
const distPath = __ENV.DIST_PATH || "./dist";
7+
const csvPath = `../../../${distPath}/nft/seed-pointers-extract.csv`;
98
const csv = open(csvPath);
109
const lines = csv.trim().split("\n");
1110
// Skip header

tests/performance/generate_producer_distributions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import json
22
from pathlib import Path
33

4-
from seed_data_constants import (
4+
from tests.performance.seed_data_constants import (
55
DEFAULT_CUSTODIAN_DISTRIBUTIONS,
66
DEFAULT_TYPE_DISTRIBUTIONS,
77
)

tests/performance/perftest_environment.py

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import csv
2+
import json
23
import os
34
import re
45

56
import boto3
6-
from seed_data_constants import CHECKSUM_WEIGHTS
7+
8+
from tests.performance.seed_data_constants import CHECKSUM_WEIGHTS
79

810
DYNAMODB = boto3.resource("dynamodb", region_name="eu-west-2")
911

@@ -19,6 +21,26 @@ def _get_pointers_table_name():
1921
return f"nhsd-nrlf--{perftest_table_name}-pointers-table"
2022

2123

24+
def create_extract_metadata_file(
25+
table_name: str,
26+
output_dir=".",
27+
):
28+
meta_out = output_dir + f"/info.json"
29+
30+
os.system(f"./scripts/get-current-info.sh > {meta_out}.temp")
31+
32+
with open(f"{meta_out}.temp", "r") as temp_f:
33+
metadata = json.load(temp_f)
34+
# Set any additional metadata fields (e.g. table name) as needed
35+
metadata["table_name"] = table_name
36+
with open(f"{meta_out}", "w+") as f:
37+
json.dump(metadata, f, indent=2)
38+
39+
os.system(f"rm {meta_out}.temp")
40+
41+
print(f"Pointer extract metadata saved to {meta_out}") # noqa: T201
42+
43+
2244
class TestNhsNumbersIterator:
2345
def __iter__(self):
2446
self.first9 = 900000000
@@ -50,7 +72,7 @@ def generate_pointer_table_extract(
5072
Generate a CSV file containing all pointer IDs, pointer type, custodian, and nhs_number (patient).
5173
"""
5274
table_name = _get_pointers_table_name()
53-
out = output_dir + f"/seed-pointers-extract-{table_name}.csv"
75+
out = output_dir + f"/seed-pointers-extract.csv"
5476
table = DYNAMODB.Table(table_name)
5577
scan_kwargs = {}
5678
done = False
@@ -95,6 +117,8 @@ def generate_pointer_table_extract(
95117
writer.writerows(buffer)
96118
print(f"Pointer extract CSV data written to {out}") # noqa: T201
97119

120+
create_extract_metadata_file(table_name, output_dir)
121+
98122

99123
if __name__ == "__main__":
100124
import fire

tests/performance/producer/client_perftest.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ import { crypto } from "k6/experimental/webcrypto";
66
import { createRecord } from "../setup.js";
77
import exec from "k6/execution";
88

9-
const csvPath = __ENV.DIST_PATH
10-
? `../../../${__ENV.DIST_PATH}/seed-pointers-extract.csv`
11-
: "../seed-pointers-extract.csv";
9+
const distPath = __ENV.DIST_PATH || "./dist";
10+
const csvPath = `../../../${distPath}/nft/seed-pointers-extract.csv`;
1211
const csv = open(csvPath);
1312
const lines = csv.trim().split("\n");
1413
// Skip header

0 commit comments

Comments
 (0)