Skip to content
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

WIP: ✅ testing metrics endpoint #2417

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 103 additions & 0 deletions tests/performance/locust_files/webserver_metrics_entrypoint_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
#
# SEE https://docs.locust.io/en/stable/quickstart.html
#

import logging
import os
from json.decoder import JSONDecodeError
from typing import Any, Dict
from uuid import uuid4

import faker
from dotenv import load_dotenv

from locust import task
from locust.contrib.fasthttp import FastHttpUser

logging.basicConfig(level=logging.INFO)

fake = faker.Faker()

load_dotenv() # take environment variables from .env

_TEMPLATE_PROJECT_ID = "c2032f18-ddb9-11eb-a06f-02420a0000c1"


class WebApiUser(FastHttpUser):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

self.email = fake.email()
self.count = 0

@task(weight=1)
def health_check(self):
self.client.get("/v0/health")

@task(weight=1)
def get_metrics(self):
self.client.get(
"/metrics",
)

@task(weight=5)
def create_project_from_template_open_and_close(self):
self.count += 1

# WARNING: this template needs to be created and shared with everybody
project: Dict[str, Any] = {}
with self.client.post(
f"/v0/projects?from_template={_TEMPLATE_PROJECT_ID}",
json={
"name": f"TEST #{self.count}",
"description": f"{__name__}-{self.email}",
"prjOwner": self.email,
},
catch_response=True,
name="/projects/FROM_TEMPLATE",
) as response:
try:
project = response.json()["data"]
except (JSONDecodeError, KeyError):
response.failure("invalid response after creating project")

if not project:
raise ValueError("project not found???")
# open the project
client_session_id = str(uuid4())
with self.client.post(
f"/v0/projects/{project['uuid']}:open",
json=client_session_id,
catch_response=True,
name="/projects/OPEN",
) as response:
try:
project = response.json()["data"]
except (JSONDecodeError, KeyError):
response.failure("invalid response after opening project")

# close the project
self.client.post(
f"/v0/projects/{project['uuid']}:close",
json=client_session_id,
catch_response=True,
name="/projects/CLOSE",
)

def on_start(self):
print("Created User ", self.email)
self.client.post(
"/v0/auth/register",
json={
"email": self.email,
"password": "my secret",
"confirm": "my secret",
},
)
self.client.post(
"/v0/auth/login", json={"email": self.email, "password": "my secret"}
)

def on_stop(self):
self.client.post("/v0/auth/logout")
print("Stopping", self.email)