-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor, prettify, lints, docstings.
- Loading branch information
1 parent
1c1f8b8
commit d1cad35
Showing
8 changed files
with
106 additions
and
51 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
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,31 +1,76 @@ | ||
from locust import HttpUser | ||
from dataclasses import dataclass | ||
|
||
import flexitest | ||
|
||
from load.job import StrataLoadJob | ||
|
||
|
||
@dataclass(frozen=True) | ||
class LoadConfig: | ||
""" | ||
A data class holding host and job classes that describe load requests. | ||
Config for the load service. | ||
""" | ||
|
||
user_classes: list[HttpUser] | ||
host: str | ||
spawn_rate: int | ||
jobs: list[StrataLoadJob] | ||
"""A set of jobs that emit the load towards the host.""" | ||
|
||
def __init__(self, user_classes: list[HttpUser], host: str, spawn_rate: int): | ||
# "Patch" user_classes with a given host | ||
for user_cls in user_classes: | ||
user_cls.host = host | ||
host: str | ||
"""The host that will accept load requests.""" | ||
|
||
self.user_classes = user_classes | ||
self.host = host | ||
self.spawn_rate = spawn_rate | ||
spawn_rate: int | ||
"""The rate at which all the jobs will emit the load.""" | ||
|
||
|
||
class LoadConfigBuilder: | ||
""" | ||
A builder for the load config. | ||
An abstract builder of the `LoadConfig`. | ||
""" | ||
|
||
jobs: list[StrataLoadJob] = [] | ||
"""A set of jobs that emit the load towards the host.""" | ||
|
||
spawn_rate: int = 10 | ||
"""The rate at which all the jobs will emit the load.""" | ||
|
||
service_name: str | None = None | ||
"""The name of the service to emit the load.""" | ||
|
||
def __init__(self): | ||
pass | ||
if not self.service_name: | ||
raise Exception("LoadConfigBuilder: missing service_name attribute.") | ||
|
||
def with_jobs(self, jobs: list[StrataLoadJob]): | ||
self.jobs.extend(jobs) | ||
return self | ||
|
||
def with_rate(self, rate: int): | ||
self.spawn_rate = rate | ||
return self | ||
|
||
def __call__(self, svcs) -> LoadConfig: | ||
if not self.jobs: | ||
raise Exception("LoadConfigBuilder: load jobs list is empty") | ||
|
||
host = self.host_url(svcs) | ||
# Patch jobs by the host. | ||
for job in self.jobs: | ||
job.host = host | ||
|
||
return LoadConfig(self.jobs, host, self.spawn_rate) | ||
|
||
def host_url(self, _svcs: dict[str, flexitest.Service]) -> str: | ||
raise NotImplementedError() | ||
|
||
@property | ||
def name(self): | ||
return self.service_name | ||
|
||
|
||
class RethLoadConfigBuilder(LoadConfigBuilder): | ||
service_name: str = "reth" | ||
spawn_rate: int = 20 | ||
|
||
def __call__(self, ) | ||
def host_url(self, svcs: dict[str, flexitest.Service]) -> str: | ||
reth = svcs["reth"] | ||
web3_port = reth.get_prop("eth_rpc_http_port") | ||
return f"http://localhost:{web3_port}" |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
from .reth import * |
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