Skip to content

Commit 3355f87

Browse files
authored
[core][feat] Allow filtering benchmarks (#2069)
1 parent 71fe4be commit 3355f87

File tree

4 files changed

+29
-10
lines changed

4 files changed

+29
-10
lines changed

fixcore/fixcore/report/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,9 @@ class Inspector(ABC):
393393
"""
394394

395395
@abstractmethod
396-
async def list_benchmarks(self) -> List[Benchmark]:
396+
async def list_benchmarks(
397+
self, *, provider_ids: Optional[List[str]] = None, benchmark_ids: Optional[List[str]] = None
398+
) -> List[Benchmark]:
397399
pass
398400

399401
@abstractmethod

fixcore/fixcore/report/inspector_service.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,19 @@ async def report_config(self) -> ReportConfig:
121121
log.warning(f"Can not load report config: {e}")
122122
return ReportConfig() # safe default
123123

124-
async def list_benchmarks(self) -> List[Benchmark]:
125-
result = {b.id: b for b in benchmarks_from_file().values()}
124+
async def list_benchmarks(
125+
self, *, provider_ids: Optional[List[str]] = None, benchmark_ids: Optional[List[str]] = None
126+
) -> List[Benchmark]:
127+
128+
def filter_benchmark(benchmark: Benchmark) -> bool:
129+
in_p = provider_ids is None or benchmark.clouds is None or any(p in benchmark.clouds for p in provider_ids)
130+
in_b = benchmark_ids is None or benchmark.id in benchmark_ids
131+
return in_p and in_b
132+
133+
result = {b.id: b for b in benchmarks_from_file().values() if filter_benchmark(b)}
126134
async for b in self.benchmark_db.all():
127-
result[b.id] = b
135+
if filter_benchmark(b):
136+
result[b.id] = b
128137
return list(result.values())
129138

130139
async def benchmark(self, bid: str) -> Optional[Benchmark]:

fixcore/fixcore/static/api-doc.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2632,7 +2632,13 @@ paths:
26322632
tags:
26332633
- report
26342634
parameters:
2635-
- name: benchmark
2635+
- name: providers
2636+
in: query
2637+
description: "Comma separated list of cloud provides. All if not defined."
2638+
schema:
2639+
type: string
2640+
example: "aws"
2641+
- name: benchmarks
26362642
in: query
26372643
description: "Comma separated list of benchmarks. All if not defined."
26382644
schema:

fixcore/fixcore/web/api.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,10 @@ async def delete_check(self, request: Request, deps: TenantDependencies) -> Stre
709709
return HTTPNoContent()
710710

711711
async def benchmarks(self, request: Request, deps: TenantDependencies) -> StreamResponse:
712-
benchmark_filter = [b.strip() for b in request.query.get("benchmarks", "").split(",") if b.strip()]
712+
benchmarks = request.query.get("benchmarks")
713+
providers = request.query.get("providers")
714+
benchmark_ids = [b.strip() for b in benchmarks.split(",") if b.strip()] if benchmarks else None
715+
provider_ids = [p.strip() for p in providers.split(",") if p.strip()] if providers else None
713716
short = request.query.get("short", "false").lower() == "true"
714717
ids_only = request.query.get("ids_only", "false").lower() == "true"
715718
with_checks = request.query.get("with_checks", "false").lower() == "true"
@@ -729,12 +732,11 @@ def to_js_benchmark(b: Benchmark) -> JsonElement:
729732
bj["report_checks"] = [to_js_check(lookup[c]) for c in b.nested_checks()]
730733
return bj
731734

732-
benchmarks = [
735+
benchmark_results = [
733736
to_js_benchmark(b)
734-
for b in await deps.inspector.list_benchmarks()
735-
if (b.id in benchmark_filter or not benchmark_filter)
737+
for b in await deps.inspector.list_benchmarks(provider_ids=provider_ids, benchmark_ids=benchmark_ids)
736738
]
737-
return await single_result(request, benchmarks)
739+
return await single_result(request, benchmark_results)
738740

739741
async def get_benchmark(self, request: Request, deps: TenantDependencies) -> StreamResponse:
740742
if result := await deps.inspector.benchmark(request.match_info["benchmark"]):

0 commit comments

Comments
 (0)