Skip to content

Commit

Permalink
add a load testing script for process-zip
Browse files Browse the repository at this point in the history
  • Loading branch information
alismx committed Dec 10, 2024
1 parent f414c65 commit eecc604
Show file tree
Hide file tree
Showing 2 changed files with 125 additions and 0 deletions.
32 changes: 32 additions & 0 deletions containers/ecr-viewer/seed-scripts/docker-compose-load.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
services:
# The Locust engine is used for load testing purposes.
locust-brain:
image: locustio/locust
ports:
- "8089:8089"
volumes:
- ./locustfile.py:/home/locust/locustfile.py
- ./requirements.txt:/home/locust/requirements.txt
- ./baseECR/LA:/home/locust/baseECR/LA
command: -f /home/locust/locustfile.py --master -H $LOAD_TESTING_URL
locust-worker-1:
image: locustio/locust
volumes:
- ./locustfile.py:/home/locust/locustfile.py
- ./requirements.txt:/home/locust/requirements.txt
- ./baseECR/LA:/home/locust/baseECR/LA
command: -f /home/locust/locustfile.py --worker --master-host locust-brain
locust-worker-2:
image: locustio/locust
volumes:
- ./locustfile.py:/home/locust/locustfile.py
- ./requirements.txt:/home/locust/requirements.txt
- ./baseECR/LA:/home/locust/baseECR/LA
command: -f /home/locust/locustfile.py --worker --master-host locust-brain
locust-worker-3:
image: locustio/locust
volumes:
- ./locustfile.py:/home/locust/locustfile.py
- ./requirements.txt:/home/locust/requirements.txt
- ./baseECR/LA:/home/locust/baseECR/LA
command: -f /home/locust/locustfile.py --worker --master-host locust-brain
93 changes: 93 additions & 0 deletions containers/ecr-viewer/seed-scripts/locustfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
from locust import HttpUser, task, between
import subprocess
import os
import shutil
import random
import json

Check failure on line 6 in containers/ecr-viewer/seed-scripts/locustfile.py

View workflow job for this annotation

GitHub Actions / orchestration-python-linting

Ruff (F401)

containers/ecr-viewer/seed-scripts/locustfile.py:6:8: F401 `json` imported but unused

class EcrViewer(HttpUser):

Check failure on line 8 in containers/ecr-viewer/seed-scripts/locustfile.py

View workflow job for this annotation

GitHub Actions / orchestration-python-linting

Ruff (I001)

containers/ecr-viewer/seed-scripts/locustfile.py:1:1: I001 Import block is un-sorted or un-formatted
wait_time = between(1, 5)

@task
def ecr_viewer(self):

Check failure on line 12 in containers/ecr-viewer/seed-scripts/locustfile.py

View workflow job for this annotation

GitHub Actions / orchestration-python-linting

Ruff (D102)

containers/ecr-viewer/seed-scripts/locustfile.py:12:9: D102 Missing docstring in public method
self.client.get(f"/ecr-viewer")

Check failure on line 13 in containers/ecr-viewer/seed-scripts/locustfile.py

View workflow job for this annotation

GitHub Actions / orchestration-python-linting

Ruff (F541)

containers/ecr-viewer/seed-scripts/locustfile.py:13:25: F541 f-string without any placeholders

@task
def orchestration(self):

Check failure on line 16 in containers/ecr-viewer/seed-scripts/locustfile.py

View workflow job for this annotation

GitHub Actions / orchestration-python-linting

Ruff (D102)

containers/ecr-viewer/seed-scripts/locustfile.py:16:9: D102 Missing docstring in public method
self.client.get(f"/orchestration")

Check failure on line 17 in containers/ecr-viewer/seed-scripts/locustfile.py

View workflow job for this annotation

GitHub Actions / orchestration-python-linting

Ruff (F541)

containers/ecr-viewer/seed-scripts/locustfile.py:17:25: F541 f-string without any placeholders

@task
def upload_zip(self):

Check failure on line 20 in containers/ecr-viewer/seed-scripts/locustfile.py

View workflow job for this annotation

GitHub Actions / orchestration-python-linting

Ruff (D102)

containers/ecr-viewer/seed-scripts/locustfile.py:20:9: D102 Missing docstring in public method
for file in get_zipped_files():
with open(file, "rb") as opened_file:
data = {
"content_type": "application/zip",
"config_file_name": "sample-orchestration-s3-config.json",
"data_type": "zip",
"message_type": "ecr",
}
# print(f"Uploading {file}")
file_tuple = { "upload_file": ( file, opened_file.read(), "application/zip") }
response = self.client.post(f"/orchestration/process-zip", data=data, files=file_tuple)

Check failure on line 31 in containers/ecr-viewer/seed-scripts/locustfile.py

View workflow job for this annotation

GitHub Actions / orchestration-python-linting

Ruff (F541)

containers/ecr-viewer/seed-scripts/locustfile.py:31:45: F541 f-string without any placeholders
self.tasks.append(check_ecr(self, file, response.json()))

# Runs at the start of each test. Useful for authentication and setup actions.
def on_start(self):

Check failure on line 35 in containers/ecr-viewer/seed-scripts/locustfile.py

View workflow job for this annotation

GitHub Actions / orchestration-python-linting

Ruff (D102)

containers/ecr-viewer/seed-scripts/locustfile.py:35:9: D102 Missing docstring in public method
subprocess.run(["pip", "install", "-r", "requirements.txt"])
pass

# Check the ecr viewer response for eicr_id and view the ecr
def check_ecr(self, file, response):

Check failure on line 40 in containers/ecr-viewer/seed-scripts/locustfile.py

View workflow job for this annotation

GitHub Actions / orchestration-python-linting

Ruff (D103)

containers/ecr-viewer/seed-scripts/locustfile.py:40:5: D103 Missing docstring in public function
if "detail" in response:
print(f"{file}", response['detail'])
if "message" in response:
print(f"{file}", response['message'])
if "processed_values" not in response:
print("No processed_values found in response")
return
if "parsed_values" not in response["processed_values"]:
print("No parsed_values found in response")
return
if "eicr_id" in response["processed_values"]["parsed_values"]:
print(response["processed_values"]["parsed_values"]["eicr_id"])
eicr_id = response["processed_values"]["parsed_values"]["eicr_id"]
print(f"/ecr-viewer/view-data?id={eicr_id}")
response = self.client.get(f"/ecr-viewer/view-data?id={eicr_id}")
print(response)
else:
print("No eicr_id found in response")

# Get all the zipped files in the baseECR folder
def get_zipped_files():
files = []
BASEDIR = os.path.dirname(os.path.abspath(__file__))
subfolders = ["LA"]
for subfolder in subfolders:
subfolder_path = os.path.join(BASEDIR, "baseECR", subfolder)

# Check if the subfolder exists and is a directory
if not os.path.isdir(subfolder_path):
print(f"{subfolder_path} is not a valid directory.")
continue

# Now iterate through the folders inside each subfolder
for folder in os.listdir(subfolder_path):
folder_path = os.path.join(subfolder_path, folder)

# Check if it's a directory
if not os.path.isdir(folder_path):
continue

if os.path.exists(os.path.join(folder_path, "CDA_eICR.xml")):
random_number = random.randint(1, 30)
zipped_file = shutil.make_archive(f"{random_number}", 'zip', folder_path)
print(f"Zipped {folder_path} to {zipped_file}")
files.append(zipped_file)
# If neither `bundle.json` nor `CDA_eICR.xml` exists, skip processing
else:
print(
f"Neither `bundle.json` nor `CDA_eICR.xml` found in {folder_path}. Skipping."
)
continue

return files

0 comments on commit eecc604

Please sign in to comment.