-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into repo-sync/site-reliability-engineering/default
- Loading branch information
Showing
8 changed files
with
102 additions
and
14 deletions.
There are no files selected for viewing
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
users=1 | ||
stop-timeout=10 | ||
host=https://api.staging.notification.cdssandbox.xyz | ||
host=https://staging.notification.cdssandbox.xyz |
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,60 @@ | ||
from dotenv import load_dotenv | ||
from locust import HttpUser, TaskSet, constant_pacing, task | ||
from locust.clients import HttpSession | ||
from soak_utils import url_with_prefix | ||
|
||
load_dotenv() | ||
|
||
|
||
class MultipleHostsUser(HttpUser): | ||
abstract = True | ||
|
||
def __init__(self, *args, **kwargs): | ||
super().__init__(*args, **kwargs) | ||
|
||
self.admin_client = HttpSession( | ||
base_url=self.host, request_event=self.client.request_event, user=self | ||
) | ||
|
||
self.api_client = HttpSession( | ||
base_url=url_with_prefix(self.host, "api"), request_event=self.client.request_event, user=self | ||
) | ||
|
||
self.api_k8s_client = HttpSession( | ||
base_url=url_with_prefix(self.host, "api-k8s"), request_event=self.client.request_event, user=self | ||
) | ||
|
||
self.dd_api_client = HttpSession( | ||
base_url=url_with_prefix(self.host, "api.document"), request_event=self.client.request_event, user=self | ||
) | ||
|
||
self.documentation_client = HttpSession( | ||
base_url=url_with_prefix(self.host, "documentation"), request_event=self.client.request_event, user=self | ||
) | ||
|
||
|
||
class UserTasks(TaskSet): | ||
@task | ||
def test_admin(self): | ||
self.user.admin_client.get("/_status?simple=true", name=f"{self.user.admin_client.base_url}/_status?simple=true") | ||
|
||
@task | ||
def test_api(self): | ||
self.user.api_client.get("/_status?status=true", name=f"{self.user.api_client.base_url}/_status?simple=true") | ||
|
||
@task | ||
def test_api_k8s(self): | ||
self.user.api_k8s_client.get("/_status?status=true", name=f"{self.user.api_k8s_client.base_url}/_status?simple=true") | ||
|
||
@task | ||
def test_dd_api(self): | ||
self.user.dd_api_client.get("/_status?simple=true", name=f"{self.user.dd_api_client.base_url}/_status?simple=true") | ||
|
||
@task | ||
def test_documentation(self): | ||
self.user.documentation_client.get("/", name=f"{self.user.documentation_client.base_url}/") | ||
|
||
|
||
class WebsiteUser(MultipleHostsUser): | ||
wait_time = constant_pacing(0.2) # 5 GETs a second, so each server every second on average | ||
tasks = [UserTasks] |
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 |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
|
||
from dotenv import load_dotenv | ||
from locust import HttpUser, constant_pacing, events, task | ||
from soak_utils import url_with_prefix | ||
|
||
load_dotenv() | ||
|
||
|
@@ -15,6 +16,8 @@ class NotifyApiUser(HttpUser): | |
wait_time = constant_pacing(1) # each user makes one post per second | ||
|
||
def __init__(self, *args, **kwargs): | ||
self.host = url_with_prefix(self.host, "api") | ||
|
||
super(NotifyApiUser, self).__init__(*args, **kwargs) | ||
self.headers = {"Authorization": f"apikey-v1 {os.getenv('API_KEY')}"} | ||
self.email_address = "[email protected]" | ||
|
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,6 @@ | ||
from urllib.parse import urlparse | ||
|
||
|
||
def url_with_prefix(url: str, prefix: str) -> str: | ||
parsed_url = urlparse(url) | ||
return parsed_url._replace(netloc=f"{prefix}.{parsed_url.netloc}").geturl() |