Skip to content

Commit 63993ee

Browse files
committed
Merge branch 'feature/PI-365-load_test_sds' into release/2024-10-16
2 parents f61797c + 3a06d20 commit 63993ee

File tree

3 files changed

+4831
-105
lines changed

3 files changed

+4831
-105
lines changed

infrastructure/terraform/locust/ec2_instances.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ resource "aws_instance" "locust_master" {
4444
sudo apt-get update
4545
sudo apt-get install -y python3-pip
4646
sudo apt-get install -y awscli
47+
aws s3 cp s3://nhse-cpm--mgmt--locust-file/speed_test_queries.py .
4748
aws s3 cp s3://nhse-cpm--mgmt--locust-file/locustfile.py .
4849
pip3 install locust
4950
EOF
@@ -68,6 +69,7 @@ resource "aws_instance" "locust_worker" {
6869
sudo apt-get update
6970
sudo apt-get install -y python3-pip
7071
sudo apt-get install -y awscli
72+
aws s3 cp s3://nhse-cpm--mgmt--locust-file/speed_test_queries.py .
7173
aws s3 cp s3://nhse-cpm--mgmt--locust-file/locustfile.py .
7274
pip3 install locust
7375
EOF

load_test/locustfile.py

Lines changed: 33 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,16 @@
1-
import random
2-
31
from locust import HttpUser, events, task
42

5-
6-
class QueryParams:
7-
LDAP_UNIQUE_IDENTIFIER = "ldap_unique_identifier"
8-
DEVICE_ID = "device_id"
9-
DEVICE_KEY = "device_key"
10-
PARTY_KEY = "party_key"
11-
INTERACTION_ID = "interaction_id"
12-
ODS_CODE = "ods_code"
13-
14-
15-
unique_identifiers = ["1234567", "7654321"]
16-
17-
device_keys = ["D81631:200000035358"]
18-
19-
device_ids = ["3b9ced88-e2c2-4496-8ade-7fc3d5a8aba5"]
20-
21-
interaction_ids = [
22-
"https://fhir.nhs.uk/Id/nhsServiceInteractionId|urn:nhs:names:services:lrs:REPC_IN010000UK01"
23-
]
24-
25-
party_keys = ["https://fhir.nhs.uk/Id/nhsMhsPartyKey|5NR-801831"]
26-
27-
ods_codes = ["https://fhir.nhs.uk/Id/ods-organization-code|5NR"]
28-
29-
30-
sds_accredited_system_query_combinations = [
31-
{QueryParams.INTERACTION_ID, QueryParams.ODS_CODE, QueryParams.PARTY_KEY},
32-
{QueryParams.INTERACTION_ID, QueryParams.ODS_CODE},
33-
]
34-
35-
sds_mhs_query_combinations = [
36-
{QueryParams.INTERACTION_ID, QueryParams.ODS_CODE, QueryParams.PARTY_KEY},
37-
{QueryParams.INTERACTION_ID, QueryParams.PARTY_KEY},
38-
{QueryParams.INTERACTION_ID, QueryParams.ODS_CODE},
39-
{QueryParams.PARTY_KEY, QueryParams.ODS_CODE},
3+
queries = [
4+
{
5+
"params": {
6+
"organization": ["https://fhir.nhs.uk/Id/ods-organization-code|E82652"],
7+
"identifier": [
8+
"https://fhir.nhs.uk/Id/nhsServiceInteractionId|urn:nhs:names:services:gpconnect:fhir:operation:gpc.getcarerecord",
9+
"https://fhir.nhs.uk/Id/nhsMhsPartyKey|E82652-826971",
10+
],
11+
},
12+
"path": "/Device",
13+
}
4014
]
4115

4216

@@ -57,6 +31,14 @@ def _(parser):
5731
required=True,
5832
help="apikey for hitting desired host",
5933
)
34+
parser.add_argument(
35+
"--usecpm",
36+
choices=["TRUE", "FALSE"],
37+
default="FALSE",
38+
env_var="USE_CPM",
39+
required=False,
40+
help="use_cpm for hitting cpm",
41+
)
6042

6143

6244
def _get_headers(version: str, apikey: str):
@@ -67,72 +49,18 @@ def _get_headers(version: str, apikey: str):
6749

6850
class CPMUser(HttpUser):
6951
@task
70-
def read_device_by_id(self):
71-
device_id = random.choice(device_ids)
72-
url_path = f"/Device/{device_id}"
73-
APIKEY = self.environment.parsed_options.apikey
52+
def search(self):
53+
apikey = self.environment.parsed_options.apikey
7454
API_VERSION = self.environment.parsed_options.api_version
75-
76-
self.client.get(
77-
url=url_path, headers=_get_headers(version=API_VERSION, apikey=APIKEY)
78-
)
79-
80-
# @task
81-
# def search_cpm_for_unique_identifier(self):
82-
# unique_identifier = random.choice(unique_identifiers)
83-
# url_path = f"/Device?{QueryParams.LDAP_UNIQUE_IDENTIFIER}={unique_identifier}"
84-
# apikey = self.environment.parsed_options.apikey
85-
# API_VERSION = self.environment.parsed_options.api_version
86-
87-
# self.client.get(
88-
# url=url_path,
89-
# headers=_get_headers(version=API_VERSION, apikey=apikey)
90-
# )
91-
92-
# @task
93-
# def search_cpm_for_accredited_system(self):
94-
# selected_combination = random.choice(sds_accredited_system_query_combinations)
95-
# selected_values = {}
96-
# if QueryParams.INTERACTION_ID in selected_combination:
97-
# selected_values['interaction'] = random.choice(interaction_ids)
98-
99-
# if QueryParams.ODS_CODE in selected_combination:
100-
# selected_values['code'] = random.choice(ods_codes)
101-
102-
# if QueryParams.PARTY_KEY in selected_combination:
103-
# selected_values['key'] = random.choice(party_keys)
104-
105-
# query_params = urlencode(selected_values)
106-
# url_path = f"/Device?{query_params}"
107-
108-
# apikey = self.environment.parsed_options.apikey
109-
# API_VERSION = self.environment.parsed_options.api_version
110-
111-
# self.client.get(
112-
# url=url_path,
113-
# headers=_get_headers(version=API_VERSION, apikey=apikey)
114-
# )
115-
116-
# @task
117-
# def search_cpm_for_mhs(self):
118-
# selected_combination = random.choice(sds_mhs_query_combinations)
119-
# selected_values = {}
120-
# if QueryParams.INTERACTION_ID in selected_combination:
121-
# selected_values['interaction'] = random.choice(interaction_ids)
122-
123-
# if QueryParams.ODS_CODE in selected_combination:
124-
# selected_values['code'] = random.choice(ods_codes)
125-
126-
# if QueryParams.PARTY_KEY in selected_combination:
127-
# selected_values['key'] = random.choice(party_keys)
128-
129-
# query_params = urlencode(selected_values)
130-
# url_path = f"/Device?{query_params}"
131-
132-
# apikey = self.environment.parsed_options.apikey
133-
# API_VERSION = self.environment.parsed_options.api_version
134-
135-
# self.client.get(
136-
# url=url_path,
137-
# headers=_get_headers(version=API_VERSION, apikey=apikey)
138-
# )
55+
USE_CPM = self.environment.parsed_options.usecpm
56+
for query in queries:
57+
params = query["params"].copy()
58+
if USE_CPM == "TRUE":
59+
params["use_cpm"] = "iwanttogetdatafromcpm"
60+
61+
url_path = f"{query['path']}"
62+
self.client.get(
63+
url=url_path,
64+
params=params,
65+
headers=_get_headers(version=API_VERSION, apikey=apikey),
66+
)

0 commit comments

Comments
 (0)