-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Load testing script for process-zip 🤐 #3032
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
containers/ecr-viewer/seed-scripts/docker-compose-load.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
@@ -0,0 +1,107 @@ | ||||
import os | ||||
import random | ||||
import shutil | ||||
import subprocess | ||||
|
||||
from locust import between | ||||
from locust import HttpUser | ||||
from locust import task | ||||
|
||||
|
||||
class EcrViewer(HttpUser): | ||||
wait_time = between(1, 5) | ||||
|
||||
@task | ||||
def ecr_viewer(self): | ||||
"""get the ecr viewer library page""" | ||||
self.client.get("/ecr-viewer") | ||||
|
||||
@task | ||||
def orchestration(self): | ||||
"""get the orchestration endpoint""" | ||||
self.client.get("/orchestration") | ||||
|
||||
@task | ||||
def upload_zip(self): | ||||
"""upload a zip file to the orchestration endpoint""" | ||||
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", | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we change this config name to be possibly |
||||
"data_type": "zip", | ||||
"message_type": "ecr", | ||||
} | ||||
# print(f"Uploading {file}") | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
file_tuple = { | ||||
"upload_file": (file, opened_file.read(), "application/zip") | ||||
} | ||||
response = self.client.post( | ||||
"/orchestration/process-zip", data=data, files=file_tuple | ||||
) | ||||
self.tasks.append(check_ecr(self, file, response.json())) | ||||
|
||||
def on_start(self): | ||||
"""install the requirements""" | ||||
subprocess.run(["pip", "install", "-r", "requirements.txt"]) | ||||
pass | ||||
|
||||
|
||||
def check_ecr(self, file, response): | ||||
"""Check the ecr viewer response for eicr_id and view the ecr""" | ||||
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") | ||||
|
||||
|
||||
def get_zipped_files(): | ||||
"""Get all the zipped files in the baseECR folder""" | ||||
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 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Locust spins up. I think it might be related to https://streamline.dibbs.cloud/ not being available.