Skip to content

Commit

Permalink
fix: Limit to one backend
Browse files Browse the repository at this point in the history
  • Loading branch information
bmtcril committed Mar 12, 2024
1 parent 056e3cc commit 396a22c
Showing 1 changed file with 17 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@


class Monitor:
def __init__(self, sleep_time: float):
def __init__(self, sleep_time: float, backend: str):
self.run_id = str(uuid.uuid4())[:6]
self.ch_url = settings.EVENT_SINK_CLICKHOUSE_BACKEND_CONFIG["url"]
self.ch_auth = ClickHouseAuth(

Check warning on line 30 in platform_plugin_aspects/management/commands/monitor_load_test_tracking.py

View check run for this annotation

Codecov / codecov/patch

platform_plugin_aspects/management/commands/monitor_load_test_tracking.py#L26-L30

Added lines #L26 - L30 were not covered by tests
Expand All @@ -39,13 +39,17 @@ def __init__(self, sleep_time: float):
"timeout_secs"
]
self.sleep_time = sleep_time
self.backend = backend

Check warning on line 42 in platform_plugin_aspects/management/commands/monitor_load_test_tracking.py

View check run for this annotation

Codecov / codecov/patch

platform_plugin_aspects/management/commands/monitor_load_test_tracking.py#L41-L42

Added lines #L41 - L42 were not covered by tests

def run(self) -> None:
collect_redis_bus = True
collect_celery = True
collect_kafka_bus = False
collect_redis_bus = True if self.backend == "redis_bus" else False
collect_celery = True if self.backend == "celery" else False
collect_kafka_bus = True if self.backend == "kafka_bus" else False
collect_vector = True if self.backend == "vector" else False

Check warning on line 48 in platform_plugin_aspects/management/commands/monitor_load_test_tracking.py

View check run for this annotation

Codecov / codecov/patch

platform_plugin_aspects/management/commands/monitor_load_test_tracking.py#L44-L48

Added lines #L44 - L48 were not covered by tests

while True:
print(f"----------- {datetime.datetime.now()} --------")

Check warning on line 51 in platform_plugin_aspects/management/commands/monitor_load_test_tracking.py

View check run for this annotation

Codecov / codecov/patch

platform_plugin_aspects/management/commands/monitor_load_test_tracking.py#L51

Added line #L51 was not covered by tests

# TODO: Need to pass in which stats to collect, or infer them from config
current_stats = {"clickhouse": self.get_clickhouse_stats()}

Check warning on line 54 in platform_plugin_aspects/management/commands/monitor_load_test_tracking.py

View check run for this annotation

Codecov / codecov/patch

platform_plugin_aspects/management/commands/monitor_load_test_tracking.py#L54

Added line #L54 was not covered by tests
if collect_redis_bus:
Expand All @@ -54,6 +58,8 @@ def run(self) -> None:
current_stats["celery"] = self.get_celery_stats()

Check warning on line 58 in platform_plugin_aspects/management/commands/monitor_load_test_tracking.py

View check run for this annotation

Codecov / codecov/patch

platform_plugin_aspects/management/commands/monitor_load_test_tracking.py#L58

Added line #L58 was not covered by tests
# if collect_kafka_bus:
# current_stats["kafka_bus"] = self.get_kafka_stats()
# if collect_vector:
# current_stats["vector"] = self.get_vector_stats()

self.store_stats(current_stats)

Check warning on line 64 in platform_plugin_aspects/management/commands/monitor_load_test_tracking.py

View check run for this annotation

Codecov / codecov/patch

platform_plugin_aspects/management/commands/monitor_load_test_tracking.py#L64

Added line #L64 was not covered by tests

Expand Down Expand Up @@ -84,7 +90,6 @@ def store_stats(self, current_stats: dict) -> None:
)

response.raise_for_status()

Check warning on line 92 in platform_plugin_aspects/management/commands/monitor_load_test_tracking.py

View check run for this annotation

Codecov / codecov/patch

platform_plugin_aspects/management/commands/monitor_load_test_tracking.py#L92

Added line #L92 was not covered by tests
print(datetime.datetime.now())

def get_clickhouse_stats(self):
select = f"""

Check warning on line 95 in platform_plugin_aspects/management/commands/monitor_load_test_tracking.py

View check run for this annotation

Codecov / codecov/patch

platform_plugin_aspects/management/commands/monitor_load_test_tracking.py#L94-L95

Added lines #L94 - L95 were not covered by tests
Expand Down Expand Up @@ -192,13 +197,19 @@ def add_arguments(self, parser: Any) -> None:
default=10,
help="Fractional number of seconds to sleep between gathering data.",
)
parser.add_argument(

Check warning on line 200 in platform_plugin_aspects/management/commands/monitor_load_test_tracking.py

View check run for this annotation

Codecov / codecov/patch

platform_plugin_aspects/management/commands/monitor_load_test_tracking.py#L200

Added line #L200 was not covered by tests
"--backend",
choices=["redis_bus", "kafka_bus", "celery", "vector"],
default="celery",
help="Backend used to send events to ClickHouse",
)

def handle(self, *args, **options):

Check warning on line 207 in platform_plugin_aspects/management/commands/monitor_load_test_tracking.py

View check run for this annotation

Codecov / codecov/patch

platform_plugin_aspects/management/commands/monitor_load_test_tracking.py#L207

Added line #L207 was not covered by tests
"""
Creates users and triggers events for them as configured above.
"""
start = datetime.datetime.now()
monitor = Monitor(options["sleep_time"])
monitor = Monitor(options["sleep_time"], options["backend"])

Check warning on line 212 in platform_plugin_aspects/management/commands/monitor_load_test_tracking.py

View check run for this annotation

Codecov / codecov/patch

platform_plugin_aspects/management/commands/monitor_load_test_tracking.py#L211-L212

Added lines #L211 - L212 were not covered by tests

try:
monitor.run()
Expand Down

0 comments on commit 396a22c

Please sign in to comment.