mirror of
https://github.com/logos-storage/bittorrent-benchmarks.git
synced 2026-01-06 23:13:08 +00:00
feat: add parameter expansion script
This commit is contained in:
parent
469ae82009
commit
983ea0e2c7
0
benchmarks/k8s/__init__.py
Normal file
0
benchmarks/k8s/__init__.py
Normal file
39
benchmarks/k8s/parameter_matrix.py
Normal file
39
benchmarks/k8s/parameter_matrix.py
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
import itertools
|
||||||
|
import json
|
||||||
|
import sys
|
||||||
|
from json import JSONDecodeError
|
||||||
|
from typing import Dict, Any, List
|
||||||
|
|
||||||
|
|
||||||
|
class ParameterMatrix:
|
||||||
|
def __init__(self, parameters: Dict[str, Any]):
|
||||||
|
self.parameters = parameters
|
||||||
|
|
||||||
|
def expand(self, run_id: bool = False) -> List[Dict[str, Any]]:
|
||||||
|
expandable = {k: v for k, v in self.parameters.items() if isinstance(v, list)}
|
||||||
|
fixed = {k: v for k, v in self.parameters.items() if k not in expandable}
|
||||||
|
expansion = [
|
||||||
|
dict(zip(expandable.keys(), values), **fixed)
|
||||||
|
for values in itertools.product(*expandable.values())
|
||||||
|
]
|
||||||
|
|
||||||
|
if run_id:
|
||||||
|
for i, item in enumerate(expansion, start=1):
|
||||||
|
item["runId"] = i
|
||||||
|
|
||||||
|
return expansion
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
|
||||||
|
if len(sys.argv) < 2:
|
||||||
|
print(f"Usage: {sys.argv[0]} '<json_string>'")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
try:
|
||||||
|
matrix_str = json.loads(sys.argv[1])
|
||||||
|
except JSONDecodeError as err:
|
||||||
|
print(f"Error decoding JSON: {err}")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
print(json.dumps(ParameterMatrix(matrix_str).expand()))
|
||||||
0
benchmarks/k8s/tests/__init__.py
Normal file
0
benchmarks/k8s/tests/__init__.py
Normal file
36
benchmarks/k8s/tests/test_parameter_matrix.py
Normal file
36
benchmarks/k8s/tests/test_parameter_matrix.py
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
from benchmarks.k8s.parameter_matrix import ParameterMatrix
|
||||||
|
|
||||||
|
|
||||||
|
def test_should_expand_simple_parameter_lists():
|
||||||
|
matrix = ParameterMatrix(
|
||||||
|
{
|
||||||
|
"a": [1, 2],
|
||||||
|
"b": [3, 4],
|
||||||
|
"c": "foo",
|
||||||
|
"d": 5
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
assert matrix.expand() == [
|
||||||
|
{"a": 1, "b": 3, "c": "foo", "d": 5},
|
||||||
|
{"a": 1, "b": 4, "c": "foo", "d": 5},
|
||||||
|
{"a": 2, "b": 3, "c": "foo", "d": 5},
|
||||||
|
{"a": 2, "b": 4, "c": "foo", "d": 5},
|
||||||
|
]
|
||||||
|
|
||||||
|
def test_should_add_run_id_when_requested():
|
||||||
|
matrix = ParameterMatrix(
|
||||||
|
{
|
||||||
|
"a": [1, 2],
|
||||||
|
"b": [3, 4],
|
||||||
|
"c": "foo",
|
||||||
|
"d": 5
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
assert matrix.expand(run_id=True) == [
|
||||||
|
{"a": 1, "b": 3, "c": "foo", "d": 5, "runId": 1},
|
||||||
|
{"a": 1, "b": 4, "c": "foo", "d": 5, "runId": 2},
|
||||||
|
{"a": 2, "b": 3, "c": "foo", "d": 5, "runId": 3},
|
||||||
|
{"a": 2, "b": 4, "c": "foo", "d": 5, "runId": 4},
|
||||||
|
]
|
||||||
@ -1,16 +1,20 @@
|
|||||||
FROM bitnami/kubectl:1.31.1 as kubectl
|
FROM bitnami/kubectl:1.31.1 AS kubectl
|
||||||
|
|
||||||
FROM debian:bookworm-slim
|
FROM python:3.12-slim
|
||||||
|
|
||||||
COPY --from=kubectl /opt/bitnami/kubectl/bin/kubectl /usr/local/bin/kubectl
|
COPY --from=kubectl /opt/bitnami/kubectl/bin/kubectl /usr/local/bin/kubectl
|
||||||
|
|
||||||
RUN apt-get update && apt-get install -y curl
|
RUN apt-get update && apt-get install -y curl
|
||||||
|
|
||||||
|
RUN curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3
|
||||||
|
RUN curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3
|
||||||
RUN curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3
|
RUN curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3
|
||||||
RUN chmod 700 get_helm.sh
|
RUN chmod 700 get_helm.sh
|
||||||
RUN ./get_helm.sh
|
RUN ./get_helm.sh
|
||||||
|
|
||||||
RUN mkdir /opt/bittorrent-benchmarks
|
RUN mkdir /opt/bittorrent-benchmarks
|
||||||
WORKDIR /opt/bittorrent-benchmarks
|
WORKDIR /opt/bittorrent-benchmarks
|
||||||
|
|
||||||
COPY ./k8s ./k8s
|
COPY ./k8s ./k8s
|
||||||
COPY ./docker ./docker
|
COPY ./docker ./docker
|
||||||
|
COPY ./benchmarks/k8s/parameter_matrix.py .
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user