Skip to content
Draft
Show file tree
Hide file tree
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
11 changes: 9 additions & 2 deletions benchmarking/automation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Scheduled, repeatable benchmark runs of a substrate branch. A CronJob on an
**orchestration cluster** drives the full build/deploy/run/teardown cycle
against a separate **test cluster**, once per entry in [tests.yaml](tests.yaml).
Each run uploads results to GCS via `benchmarking/locust/runner.py`
Each run uploads results to object storage via `benchmarking/locust/runner.py`
(`type: locust`), `benchmarking/nighthawk-ingress/runner.py` (`type: nighthawk-ingress`,
the router capacity benchmark — see
[benchmarking/nighthawk-ingress/README.md](../nighthawk-ingress/README.md)), or
Expand All @@ -13,6 +13,12 @@ gateway capacity benchmark, see
To run the cold resume tests from your workstation instead, see
[ateapi-cold-resume.md](ateapi-cold-resume.md).

Pass `--dest s3://benchmark-results/substrate` (or a `gs://` or
`az://container/prefix` URL). See the
[storage configuration](../../docs/guides/benchmarking.md#headless-automation-only)
for credentials and local-path limitations. The cluster provisioning steps
below still describe GKE; result storage does not need to be GCS.

## How it works

1. CronJob fires on the orchestration cluster; pod starts (orchestrator +
Expand Down Expand Up @@ -191,7 +197,8 @@ gcloud container clusters create <ORCH_CLUSTER_NAME> \

## IAM prerequisites

This setup assumes both clusters and the destination GCS bucket already exist.
This GKE setup assumes both clusters already exist. Create a result bucket or
container in your chosen provider; the GCS grants below apply only to GCS destinations.
Two Workload Identity bindings are needed.

Both ServiceAccounts are created by the manifests (`cronjob.yaml` for the
Expand Down
13 changes: 10 additions & 3 deletions benchmarking/automation/ateapi-cold-resume.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,16 @@ mkdir -p $D

benchmarking/automation/venv/bin/python -u benchmarking/automation/orchestrator.py \
--substrate-dir . --env-file .ate-dev-env.sh \
--dest gs://<results-bucket>/<prefix> \
--dest s3://<results-bucket>/<prefix> \
--tests benchmarking/automation/tests.yaml \
--test-name ateapi_cold_resume_pause_fake_smoke \
--junit-output $D/junit.xml 2>&1 | tee $D/orchestrator.log
```

Configure storage credentials on the runner Job and on your workstation for
retrieval; see [result storage](../../docs/guides/benchmarking.md#headless-automation-only).
The example uses S3; GCS and Azure destinations work with the same commands.

Keep your workstation awake for the whole run. If it suspends, the
orchestrator pauses too, and the teardown and the next test wait for it. For
long ladders, run the command under `setsid nohup` or in a VM.
Expand All @@ -117,8 +121,11 @@ explains the per-step rows and where the run path is in the log.
lists the files. To copy them all down:

```bash
st=$(grep -o 'gs://[^ ]*/status.json' $D/orchestrator.log | head -1)
mkdir -p $D/results && gcloud storage cp "${st%/status.json}/*" $D/results/
python3 -m venv "$D/results-venv"
"$D/results-venv/bin/pip" install -r "$S/benchmarking/requirements.txt"
st=$(grep -Eo '(gs|s3|az)://[^ ]*/status.json' "$D/orchestrator.log" | head -1)
"$D/results-venv/bin/python" "$S/benchmarking/result_store.py" download \
"${st%/status.json}" "$D/results"
```

The capacity is the highest step whose `resume_rps` keeps up with its
Expand Down
2 changes: 1 addition & 1 deletion benchmarking/automation/manifests/cronjob.yaml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ spec:
- "--branch"
- "<FILL IN: main>"
- "--dest"
- "<FILL IN: gs://your-bucket/benchmark-results>"
- "<FILL IN: s3://your-bucket/benchmark-results>"
env:
- name: DOCKER_HOST
value: tcp://localhost:2375
Expand Down
7 changes: 5 additions & 2 deletions benchmarking/locust/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@
# Stage 1: Python dependency builder
FROM python:3.11-slim AS pydeps
WORKDIR /app
COPY benchmarking/locust/requirements.txt .
RUN pip install --no-cache-dir --target=/app/deps -r requirements.txt
COPY benchmarking/requirements.txt /requirements/requirements.txt
COPY benchmarking/locust/requirements.txt /requirements/locust/requirements.txt
RUN pip install --no-cache-dir --target=/app/deps -r /requirements/locust/requirements.txt

# Stage 2: Go build of the boomer-worker worker. Lives in the same image so
# runner.py can spawn it as a subprocess during headless runs of glutton.
Expand Down Expand Up @@ -56,5 +57,7 @@ COPY benchmarking/analysis/phase_report.py /app/phase_report.py
COPY benchmarking/evaluate/*.py /app/evaluate/
COPY benchmarking/evaluate/sources/ /app/evaluate/sources/

COPY benchmarking/result_store.py /app/result_store.py

ENV PYTHONPATH=/app:/app/deps
ENV PYTHONUNBUFFERED=1
2 changes: 1 addition & 1 deletion benchmarking/locust/codegen/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# Build-time dependencies for generate.sh and for the descriptor build of the
# nighthawk-ingress and nighthawk-egress images. Kept apart from the load test's runtime
# requirements.txt so that generating the protos does not pull in locust, the
# opentelemetry exporters and google-cloud-storage.
# opentelemetry exporters.
#
# grpcio-tools bundles protoc along with the Python and gRPC codegen plugins.
# It is pinned because the generated files stamp the version that produced
Expand Down
2 changes: 1 addition & 1 deletion benchmarking/locust/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ opentelemetry-sdk
protobuf>=7.35.1
grpcio>=1.84.1
opentelemetry-exporter-otlp
google-cloud-storage
-r ../requirements.txt
kubernetes
# Run evaluations (benchmarking/evaluate/requirements.txt).
cel-expr-python==0.1.3
Expand Down
33 changes: 6 additions & 27 deletions benchmarking/locust/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"""Headless locust runner that publishes results as JSONL + CSVs.

Runs locust with the given flags, converts the resulting stats CSV
to JSONL, and uploads everything to either GCS or local disk under
to JSONL, and uploads everything to object storage or local disk under
<dest>/runs/<tag>/<timestamp>/.

When the test target is glutton.py, also spawns the boomer-worker Go
Expand All @@ -37,7 +37,6 @@
import logging
import os
import re
import shutil
import signal
import subprocess
import sys
Expand All @@ -47,6 +46,10 @@
from pathlib import Path
from typing import IO, TYPE_CHECKING, Any, Callable, TextIO

# Also find the shared module when running directly from the source tree.
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
from result_store import upload

from cluster_facts import (
EMPTY_FACTS,
append_trial_summary,
Expand Down Expand Up @@ -112,7 +115,7 @@ def parse_args() -> argparse.Namespace:
p.add_argument(
"--dest",
required=True,
help="Root destination (gs://bucket/path or local path)",
help="Root destination (gs://bucket/path, s3://bucket/path, az://container/path, or local path)",
)
p.add_argument(
"--run-ts",
Expand Down Expand Up @@ -563,30 +566,6 @@ def stats_to_jsonl(stats_csv: Path, jsonl_path: Path, timestamp: str, tag: str,
return rows_written


@functools.lru_cache(maxsize=1)
def _gcs_client() -> Any:
# Imported here so non-GCS use doesn't require google-cloud-storage.
from google.cloud import storage

return storage.Client()


def upload_to_gcs(local_path: Path, gcs_uri: str) -> None:
bucket_name, _, blob_path = gcs_uri[len("gs://"):].partition("/")
_gcs_client().bucket(bucket_name).blob(blob_path).upload_from_filename(
str(local_path)
)


def upload(src: Path, dest: str) -> None:
if dest.startswith("gs://"):
upload_to_gcs(src, dest)
else:
dest_path = Path(dest)
dest_path.parent.mkdir(parents=True, exist_ok=True)
shutil.copy(src, dest_path)


def collect_cluster_facts(
args: argparse.Namespace, logs: TextIO
) -> dict[str, Any]:
Expand Down
28 changes: 0 additions & 28 deletions benchmarking/locust/unit_tests/test_runner_observers.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,34 +315,6 @@ def failing_core_upload(src: Path, dest: str) -> None:
):
self._run_main(Path(tmp), [])

def test_gcs_client_reused_across_uploads(self):
runner._gcs_client.cache_clear()
self.addCleanup(runner._gcs_client.cache_clear)

with (
tempfile.TemporaryDirectory() as tmp,
mock.patch("google.cloud.storage.Client") as mock_client,
):
f1 = Path(tmp) / "a.txt"
f2 = Path(tmp) / "b.txt"
f1.write_text("a", encoding="utf-8")
f2.write_text("b", encoding="utf-8")

runner.upload_to_gcs(f1, "gs://my-bucket/runs/a.txt")
runner.upload_to_gcs(f2, "gs://my-bucket/runs/b.txt")

mock_client.assert_called_once_with()
mock_client.return_value.bucket.assert_has_calls(
[
mock.call("my-bucket"),
mock.call().blob("runs/a.txt"),
mock.call().blob().upload_from_filename(str(f1)),
mock.call("my-bucket"),
mock.call().blob("runs/b.txt"),
mock.call().blob().upload_from_filename(str(f2)),
]
)

def test_exception_in_run_test_still_finishes_observers_once(self):
finish_calls = 0

Expand Down
10 changes: 10 additions & 0 deletions benchmarking/locust/unit_tests/test_server_telemetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -891,6 +891,16 @@ def test_telemetry_survives_a_missing_stats_csv(self, _run, _up, telemetry):
self.assertEqual(telemetry.call_args.kwargs["lag_s"], 70)
self.assertNotIn("worker_pod_count", telemetry.call_args.kwargs)

@mock.patch.object(runner, "extract_and_record_server_telemetry")
@mock.patch.object(runner, "upload", side_effect=OSError("storage unavailable"))
@mock.patch.object(runner, "run_test", return_value=0)
def test_upload_failure_is_not_success(self, _run, _upload, _telemetry):
with mock.patch.object(sys, "argv", ARGV + ["--no-cluster-facts", "--allow-empty-stats"]), \
contextlib.redirect_stdout(io.StringIO()):
# An uncaught upload error makes the runner process exit non-zero.
with self.assertRaisesRegex(OSError, "storage unavailable"):
runner.main()

# Ladder rows follow the telemetry harvest, whose wait covers their
# last samples, and a failure there still uploads the run.
@mock.patch.object(runner, "upload")
Expand Down
8 changes: 5 additions & 3 deletions benchmarking/nighthawk-egress/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,15 @@ RUN bash /gen.sh /out/nighthawk.desc
# --- Stage 2: runtime -------------------------------------------------------
FROM envoyproxy/nighthawk-dev@${NIGHTHAWK_IMAGE_DIGEST}

COPY benchmarking/nighthawk-egress/requirements.txt /tmp/requirements.txt
COPY benchmarking/requirements.txt /requirements/requirements.txt
COPY benchmarking/nighthawk-egress/requirements.txt /requirements/nighthawk-egress/requirements.txt
RUN apt-get update \
&& apt-get install -y --no-install-recommends python3 python3-pip ca-certificates \
&& python3 -m pip install --no-cache-dir --break-system-packages \
--target=/app/deps -r /tmp/requirements.txt \
--target=/app/deps -r /requirements/nighthawk-egress/requirements.txt \
&& apt-get purge -y python3-pip \
&& apt-get autoremove -y \
&& rm -rf /var/lib/apt/lists/* /tmp/requirements.txt
&& rm -rf /var/lib/apt/lists/* /requirements

WORKDIR /app
COPY --from=protogen /out/nighthawk.desc /app/nighthawk.desc
Expand All @@ -65,6 +66,7 @@ COPY benchmarking/nighthawk-egress/runner.py \
benchmarking/nighthawk-egress/spec.py \
/app/
COPY benchmarking/nighthawk-egress/tests/check_descriptor.py /app/tests/check_descriptor.py
COPY benchmarking/result_store.py /app/result_store.py

ENV PYTHONPATH=/app:/app/deps
ENV PYTHONUNBUFFERED=1
Expand Down
2 changes: 1 addition & 1 deletion benchmarking/nighthawk-egress/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
# limitations under the License.

protobuf>=7.35.1
google-cloud-storage>=2.10.0
-r ../requirements.txt
9 changes: 6 additions & 3 deletions benchmarking/nighthawk-ingress/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,15 @@ FROM envoyproxy/nighthawk-dev@${NIGHTHAWK_IMAGE_DIGEST}

# Deps must be installed with this image's own interpreter: grpcio/protobuf
# native extensions are python-version-specific.
COPY benchmarking/nighthawk-ingress/requirements.txt /tmp/requirements.txt
COPY benchmarking/requirements.txt /requirements/requirements.txt
COPY benchmarking/nighthawk-ingress/requirements.txt /requirements/nighthawk-ingress/requirements.txt
RUN apt-get update \
&& apt-get install -y --no-install-recommends python3 python3-pip ca-certificates \
&& python3 -m pip install --no-cache-dir --break-system-packages \
--target=/app/deps -r /tmp/requirements.txt \
--target=/app/deps -r /requirements/nighthawk-ingress/requirements.txt \
&& apt-get purge -y python3-pip \
&& apt-get autoremove -y \
&& rm -rf /var/lib/apt/lists/* /tmp/requirements.txt
&& rm -rf /var/lib/apt/lists/* /requirements

WORKDIR /app
COPY --from=protogen /out/nighthawk.desc /app/nighthawk.desc
Expand All @@ -98,6 +99,8 @@ COPY benchmarking/nighthawk-ingress/runner.py \
/app/
COPY benchmarking/nighthawk-ingress/tests /app/tests

COPY benchmarking/result_store.py /app/result_store.py

ENV PYTHONPATH=/app:/app/deps
ENV PYTHONUNBUFFERED=1
ENV NIGHTHAWK_DESC=/app/nighthawk.desc
Expand Down
2 changes: 1 addition & 1 deletion benchmarking/nighthawk-ingress/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
protobuf>=7.35.1
grpcio>=1.84.1
requests
google-cloud-storage
-r ../requirements.txt
15 changes: 10 additions & 5 deletions benchmarking/nighthawk-ingress/run-dev.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Usage: $0 [options]
--actors N actor fleet size; needs at least one worker Running (default: ${ACTORS})
--tail-latency-slo-ms N SLO bound; 0 disables (default: ${TAIL_LATENCY_SLO_MS})
--atespace NAME actor namespace (default: ${ATESPACE})
--dest gs://... results root (default: gs://\$BUCKET_NAME/nighthawk-ingress-results)
--dest URL results root (default: gs://\$BUCKET_NAME/nighthawk-ingress-results)
EOF
exit "${1:-1}"
}
Expand Down Expand Up @@ -68,10 +68,13 @@ source hack/util/venv.sh
}
# shellcheck disable=SC1091
source .ate-dev-env.sh
for var in PROJECT_ID CLUSTER_NAME CLUSTER_LOCATION KO_DOCKER_REPO BUCKET_NAME; do
for var in PROJECT_ID CLUSTER_NAME CLUSTER_LOCATION KO_DOCKER_REPO; do
[[ -n "${!var:-}" ]] || { echo "ERROR: ${var} not set by .ate-dev-env.sh" >&2; exit 1; }
done
DEST="${DEST:-gs://${BUCKET_NAME}/nighthawk-ingress-results}"
if [[ -z "${DEST}" ]]; then
: "${BUCKET_NAME:?Set BUCKET_NAME or pass --dest}"
DEST="gs://${BUCKET_NAME}/nighthawk-ingress-results"
fi

docker info >/dev/null 2>&1 || {
echo "ERROR: docker daemon not running (the runner image is built locally)" >&2
Expand Down Expand Up @@ -110,6 +113,7 @@ if ! "${VENV}/bin/python" -c 'import yaml' 2>/dev/null; then
"${VENV}/bin/pip" install --quiet pyyaml ||
"${VENV}/bin/pip" install --quiet --index-url https://pypi.org/simple/ pyyaml
fi
venv_sync_requirements "${VENV}" "benchmarking/requirements.txt"
PY="${VENV}/bin/python"

# --- pin the router if its current cpu differs --------------------------------
Expand Down Expand Up @@ -194,10 +198,11 @@ kill "${LOGS_PID}" 2>/dev/null || true

# --- verdict --------------------------------------------------------------------
if [[ "${STATUS}" == "complete" ]]; then
CAPACITY="$(gcloud storage ls "${DEST}/runs/${NAME}/**/run_tag=${TAG}/capacity.json" 2>/dev/null | tail -1)"
CAPACITY="$("${PY}" benchmarking/result_store.py list "${DEST}/runs/${NAME}" \
--match "*/run_tag=${TAG}/capacity.json" | tail -1)"
if [[ -n "${CAPACITY}" ]]; then
echo ">>> ${CAPACITY}"
gcloud storage cat "${CAPACITY}"
"${PY}" benchmarking/result_store.py cat "${CAPACITY}"
fi
kubectl delete job "${JOB}" -n "${NAMESPACE}" >/dev/null
echo ">>> ${NAME}: complete (tag ${TAG})"
Expand Down
7 changes: 5 additions & 2 deletions benchmarking/nighthawk-ingress/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
from pathlib import Path
from typing import IO, TextIO

# Also find the shared modules when running directly from the source tree.
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))

import actors
from nighthawk_common import output as output_mod
import spec as spec_mod
Expand All @@ -62,12 +65,12 @@ def parse_duration_seconds(s: str) -> int:

def parse_args() -> argparse.Namespace:
p = argparse.ArgumentParser(description=__doc__)
p.add_argument("--name", required=True, help="Test name (GCS path component)")
p.add_argument("--name", required=True, help="Test name (result path component)")
p.add_argument("--tag", required=True, help="Tag for this run (commit sha)")
p.add_argument(
"--dest",
required=True,
help="Root destination (gs://bucket/path or local path)",
help="Root destination (gs://bucket/path, s3://bucket/path, az://container/path, or local path)",
)
p.add_argument(
"--run-ts",
Expand Down
Loading