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
80 changes: 80 additions & 0 deletions .github/workflows/storage-benchmark.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: GCS DirectPath Read Benchmark

on:
pull_request:
paths:
- 'packages/google-cloud-storage/**'
- '.github/workflows/storage-benchmark.yml'
workflow_dispatch:

permissions:
contents: read
pull-requests: write
checks: write

jobs:
run-benchmark:
name: "GCS Read Microbenchmark"
runs-on: ubuntu-latest

steps:
- name: Checkout Code
uses: actions/checkout@v4

Check failure on line 22 in .github/workflows/storage-benchmark.yml

View workflow job for this annotation

GitHub Actions / zizmor-output

zizmor/unpinned-uses

unpinned action reference: action is not pinned to a hash (required by blanket policy)

Check failure on line 22 in .github/workflows/storage-benchmark.yml

View workflow job for this annotation

GitHub Actions / zizmor-output

unpinned-uses

storage-benchmark.yml:22: unpinned action reference: action is not pinned to a hash (required by blanket policy)

- name: Set up Python
uses: actions/setup-python@v5

Check failure on line 25 in .github/workflows/storage-benchmark.yml

View workflow job for this annotation

GitHub Actions / zizmor-output

zizmor/unpinned-uses

unpinned action reference: action is not pinned to a hash (required by blanket policy)

Check failure on line 25 in .github/workflows/storage-benchmark.yml

View workflow job for this annotation

GitHub Actions / zizmor-output

unpinned-uses

storage-benchmark.yml:25: unpinned action reference: action is not pinned to a hash (required by blanket policy)
with:
python-version: "3.10"

- name: Authenticate to Google Cloud
uses: google-github-actions/auth@v2

Check failure on line 30 in .github/workflows/storage-benchmark.yml

View workflow job for this annotation

GitHub Actions / zizmor-output

zizmor/unpinned-uses

unpinned action reference: action is not pinned to a hash (required by blanket policy)

Check failure on line 30 in .github/workflows/storage-benchmark.yml

View workflow job for this annotation

GitHub Actions / zizmor-output

unpinned-uses

storage-benchmark.yml:30: unpinned action reference: action is not pinned to a hash (required by blanket policy)
if: env.HAS_GCP_SECRET == 'true'
env:
HAS_GCP_SECRET: ${{ secrets.GCP_SA_KEY != '' }}
with:
credentials_json: ${{ secrets.GCP_SA_KEY }}

- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@v2

Check failure on line 38 in .github/workflows/storage-benchmark.yml

View workflow job for this annotation

GitHub Actions / zizmor-output

zizmor/unpinned-uses

unpinned action reference: action is not pinned to a hash (required by blanket policy)

Check failure on line 38 in .github/workflows/storage-benchmark.yml

View workflow job for this annotation

GitHub Actions / zizmor-output

unpinned-uses

storage-benchmark.yml:38: unpinned action reference: action is not pinned to a hash (required by blanket policy)
if: env.HAS_GCP_SECRET == 'true'
env:
HAS_GCP_SECRET: ${{ secrets.GCP_SA_KEY != '' }}

- name: Package Source Archive
run: |
tar --exclude='.nox' --exclude='venv_*' --exclude='.pytest_cache' --exclude='__pycache__' --exclude='.git' \
-czf /tmp/source.tar.gz -C packages google-cloud-storage
ls -lh /tmp/source.tar.gz

- name: Run Cloud Build Benchmark on High-Bandwidth VM
if: env.HAS_GCP_SECRET == 'true'
env:
HAS_GCP_SECRET: ${{ secrets.GCP_SA_KEY != '' }}
run: |
BUILD_OUTPUT=$(gcloud builds submit /tmp/source.tar.gz \
--project="vaibhavpratap-sdk-test" \
--region="us-west4" \
--config="packages/google-cloud-storage/cloudbuild/benchmarks-cloudbuild.yaml" \
--substitutions=COMMIT_SHA="${{ github.event.pull_request.head.sha || github.sha }}",_PR_NUMBER="${{ github.event.pull_request.number }}",_REPO="${{ github.repository }}" \
--format="value(id)")
echo "BUILD_ID=$BUILD_OUTPUT" >> $GITHUB_ENV
echo "Successfully triggered Cloud Build $BUILD_OUTPUT"

- name: Fetch Benchmark JSON Result
if: env.HAS_GCP_SECRET == 'true'
env:
HAS_GCP_SECRET: ${{ secrets.GCP_SA_KEY != '' }}
run: |
mkdir -p /tmp/report
gcloud storage cp "gs://vaibhavpratap-sdk-test_cloudbuild/build_results/result_${{ env.BUILD_ID }}.json" /tmp/report/bench_result.json 2>/dev/null || true

Check failure on line 69 in .github/workflows/storage-benchmark.yml

View workflow job for this annotation

GitHub Actions / zizmor-output

zizmor/template-injection

code injection via template expansion: may expand into attacker-controllable code

Check failure on line 69 in .github/workflows/storage-benchmark.yml

View workflow job for this annotation

GitHub Actions / zizmor-output

template-injection

storage-benchmark.yml:69: code injection via template expansion: may expand into attacker-controllable code

- name: Publish Benchmark Results to PR and Checks Tab
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
python3 packages/google-cloud-storage/cloudbuild/publish_check_run.py \
--result-file="/tmp/report/bench_result.json" \
--repo="${{ github.repository }}" \
--pr-number="${{ github.event.pull_request.number }}" \
--commit-sha="${{ github.event.pull_request.head.sha || github.sha }}" \
--output-markdown="$GITHUB_STEP_SUMMARY"
138 changes: 138 additions & 0 deletions packages/google-cloud-storage/cloudbuild/benchmarks-cloudbuild.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
substitutions:
_ZONE: "us-west4-a"
_VM_NAME: "gcs-benchmark-runner-us-west4-a"
_ULIMIT: "65536"
_PROCESSES: "48"
_COROS: "1"
_FILE_SIZE_MIB: "10240"
_CHUNK_SIZE_KIB: "102400"
_ROUNDS: "2"
_ZONAL_BUCKET: "gcs-read-bench-zb-us-west4-a"
_PR_NUMBER: ""
_REPO: "shradhakatyal/google-cloud-python"

steps:
# Step 0: Generate a temporary SSH key for this build run and register with OS Login
- name: "gcr.io/google.com/cloudsdktool/cloud-sdk"
id: "generate-ssh-key"
entrypoint: "bash"
args:
- "-c"
- |
mkdir -p /workspace/.ssh
ssh-keygen -t rsa -f /workspace/.ssh/google_compute_engine -N '' -C gcb
cat /workspace/.ssh/google_compute_engine.pub > /workspace/gcb_ssh_key.pub
gcloud compute os-login ssh-keys add \
--key-file=/workspace/.ssh/google_compute_engine.pub \
--ttl=1h
waitFor: ["-"]

# Step 1: Package google-cloud-storage directory for direct transfer to VM
- name: "gcr.io/google.com/cloudsdktool/cloud-sdk"
id: "package-code"
entrypoint: "bash"
args:
- "-c"
- |
tar --exclude='.nox' --exclude='venv_*' --exclude='.pytest_cache' --exclude='__pycache__' --exclude='.git' \
-czf /workspace/google-cloud-storage.tar.gz -C /workspace/packages google-cloud-storage
waitFor: ["-"]

# Step 2: Start the standing high-bandwidth VM
- name: "gcr.io/google.com/cloudsdktool/cloud-sdk"
id: "start-vm"
entrypoint: "bash"
args:
- "-c"
- |
echo "Starting standing VM ${_VM_NAME} in zone ${_ZONE}..."
gcloud compute instances start "${_VM_NAME}" --zone="${_ZONE}"
waitFor: ["-"]

# Step 3: Run the benchmark directly on the VM via private internal IP SSH, fetch results, and stop the VM
- name: "gcr.io/google.com/cloudsdktool/cloud-sdk"
id: "run-benchmark-on-vm"
entrypoint: "bash"
args:
- "-c"
- |
set -e
echo "Waiting for VM ${_VM_NAME} to become accessible over internal SSH..."
for i in $(seq 1 20); do
if gcloud compute ssh "${_VM_NAME}" --zone="${_ZONE}" --internal-ip --ssh-key-file=/workspace/.ssh/google_compute_engine --command="echo VM is ready" 2>/dev/null; then
echo "VM internal SSH connection established successfully."
break
fi
echo "Waiting for VM internal SSH availability... (attempt $$i/20)"
sleep 10
done

echo "Copying package archive and runner script to VM over internal IP..."
gcloud compute scp /workspace/google-cloud-storage.tar.gz \
packages/google-cloud-storage/cloudbuild/run_benchmark_tests.sh \
packages/google-cloud-storage/cloudbuild/seed_benchmark_objects.py \
"${_VM_NAME}":~ --zone="${_ZONE}" --internal-ip --ssh-key-file=/workspace/.ssh/google_compute_engine

echo "Executing benchmark test suite directly on VM via SSH..."
set +e
gcloud compute ssh "${_VM_NAME}" --zone="${_ZONE}" --internal-ip --ssh-key-file=/workspace/.ssh/google_compute_engine \
--command="tar -xzf google-cloud-storage.tar.gz && cd google-cloud-storage && ulimit -n ${_ULIMIT}; PROCESSES=${_PROCESSES} COROS=${_COROS} FILE_SIZE_MIB=${_FILE_SIZE_MIB} CHUNK_SIZE_KIB=${_CHUNK_SIZE_KIB} ROUNDS=${_ROUNDS} TARGET_BUCKET=${_ZONAL_BUCKET} bash cloudbuild/run_benchmark_tests.sh"
TEST_EXIT_CODE=$?
set -e

# Copy JSON report back from VM to Cloud Build workspace
mkdir -p /workspace/report
echo "Fetching benchmark result JSON from VM..."
gcloud compute scp "${_VM_NAME}":~/bench_result.json /workspace/report/bench_result.json \
--zone="${_ZONE}" --internal-ip --ssh-key-file=/workspace/.ssh/google_compute_engine 2>/dev/null || true

# Turn off the standing VM to save quota and cost
echo "Stopping VM ${_VM_NAME}..."
gcloud compute instances stop "${_VM_NAME}" --zone="${_ZONE}" --quiet || true

exit $$TEST_EXIT_CODE
waitFor:
- "start-vm"
- "generate-ssh-key"
- "package-code"

# Step 4: Format and publish benchmark performance report
- name: "gcr.io/google.com/cloudsdktool/cloud-sdk"
id: "publish-benchmark-results"
entrypoint: "bash"
args:
- "-c"
- |
python3 packages/google-cloud-storage/cloudbuild/publish_check_run.py \
--result-file="/workspace/report/bench_result.json" \
--repo="${_REPO}" \
--commit-sha="${COMMIT_SHA}" \
--pr-number="${_PR_NUMBER}" \
--build-id="${BUILD_ID}" \
--project-id="${PROJECT_ID}" \
--region="${LOCATION}" \
--vm-name="${_VM_NAME}" \
--zonal-bucket="${_ZONAL_BUCKET}"
waitFor:
- "run-benchmark-on-vm"

# Step 5: Clean up SSH key from OS Login profile
- name: "gcr.io/google.com/cloudsdktool/cloud-sdk"
id: "cleanup-ssh-key"
entrypoint: "bash"
args:
- "-c"
- |
echo "Removing temporary build SSH key from OS Login profile..."
gcloud compute os-login ssh-keys remove \
--key-file=/workspace/gcb_ssh_key.pub || true
waitFor:
- "publish-benchmark-results"

timeout: "3600s"

options:
logging: CLOUD_LOGGING_ONLY
dynamicSubstitutions: true
pool:
name: "projects/${PROJECT_ID}/locations/us-west4/workerPools/benchmark-worker-pool"
Loading
Loading