This repository was archived by the owner on Mar 31, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 173
Expand file tree
/
Copy pathmicro_benchmarks.yaml
More file actions
111 lines (100 loc) · 4.64 KB
/
micro_benchmarks.yaml
File metadata and controls
111 lines (100 loc) · 4.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
substitutions:
_REGION: "us-central1"
_ZONE: "us-central1-a"
_SHORT_BUILD_ID: ${BUILD_ID:0:8}
_VM_NAME: "py-sdk-micro-benchmarks-ci-${_SHORT_BUILD_ID}"
_ULIMIT: "10000" # 10k, for gRPC bidi streams
_BENCHMARK_SCRIPT: "run_micro_benchmarks.sh"
steps:
# Step 0: Generate a persistent SSH key for this build run.
# This prevents gcloud from adding a new key to the OS Login profile on every ssh/scp command.
- name: "gcr.io/google.com/cloudsdktool/cloud-sdk"
id: "generate-ssh-key"
entrypoint: "bash"
args:
- "-c"
- |
mkdir -p /workspace/.ssh
# Generate the SSH key
ssh-keygen -t rsa -f /workspace/.ssh/google_compute_engine -N '' -C gcb
# Save the public key content to a file for the cleanup step
cat /workspace/.ssh/google_compute_engine.pub > /workspace/gcb_ssh_key.pub
waitFor: ["-"]
# Step 1 Create a GCE VM to run the tests.
# The VM is created in the same zone as the buckets to test rapid storage features.
# It's given the 'cloud-platform' scope to allow it to access GCS and other services.
- name: "gcr.io/google.com/cloudsdktool/cloud-sdk"
id: "create-vm"
entrypoint: "gcloud"
args:
- "compute"
- "instances"
- "create"
- "${_VM_NAME}"
- "--project=${PROJECT_ID}"
- "--zone=${_ZONE}"
- "--machine-type=c4-standard-192"
- "--network-interface=network-tier=PREMIUM,nic-type=GVNIC,stack-type=IPV4_ONLY,subnet=default"
- "--metadata=enable-osconfig=TRUE,enable-oslogin=TRUE"
- "--maintenance-policy=MIGRATE"
- "--provisioning-model=STANDARD"
- "--service-account=${_ZONAL_VM_SERVICE_ACCOUNT}"
- "--scopes=https://www.googleapis.com/auth/cloud-platform,https://www.googleapis.com/auth/devstorage.read_write"
- "--tags=allow-ssh,http-server,https-server,lb-health-check"
- "--create-disk=auto-delete=yes,boot=yes,device-name=${_VM_NAME},disk-resource-policy=projects/${PROJECT_ID}/regions/${_REGION}/resourcePolicies/default-schedule-1,image=projects/ubuntu-os-cloud/global/images/ubuntu-2204-jammy-v20251120,mode=rw,provisioned-iops=3600,provisioned-throughput=290,size=100,type=hyperdisk-balanced"
- "--no-shielded-secure-boot"
- "--shielded-vtpm"
- "--shielded-integrity-monitoring"
- "--labels=goog-ops-agent-policy=v2-x86-template-1-4-0,goog-ec-src=vm_add-gcloud"
- "--reservation-affinity=any"
- "--network-performance-configs=total-egress-bandwidth-tier=TIER_1"
waitFor: ["-"]
# Step 2: Run the integration tests inside the newly created VM and cleanup.
# This step uses 'gcloud compute ssh' to execute a remote script.
# The VM is deleted after tests are run, regardless of success.
- name: "gcr.io/google.com/cloudsdktool/cloud-sdk"
id: "run-tests-and-delete-vm"
entrypoint: "bash"
args:
- "-c"
- |
set -e
# Wait for the VM to be fully initialized and SSH to be ready.
for i in {1..10}; do
if gcloud compute ssh ${_VM_NAME} --zone=${_ZONE} --internal-ip --ssh-key-file=/workspace/.ssh/google_compute_engine --command="echo VM is ready"; then
break
fi
echo "Waiting for VM to become available... (attempt $i/10)"
sleep 15
done
# copy the script to the VM
gcloud compute scp cloudbuild/${_BENCHMARK_SCRIPT} ${_VM_NAME}:~ --zone=${_ZONE} --internal-ip --ssh-key-file=/workspace/.ssh/google_compute_engine
# Execute the script on the VM via SSH.
# Capture the exit code to ensure cleanup happens before the build fails.
set +e
gcloud compute ssh ${_VM_NAME} --zone=${_ZONE} --internal-ip --ssh-key-file=/workspace/.ssh/google_compute_engine --command="ulimit -n {_ULIMIT}; COMMIT_SHA=${COMMIT_SHA} _ZONAL_BUCKET=${_ZONAL_BUCKET} _PR_NUMBER=${_PR_NUMBER} bash ${_BENCHMARK_SCRIPT}"
EXIT_CODE=$?
set -e
echo "--- Deleting GCE VM ---"
gcloud compute instances delete "${_VM_NAME}" --zone=${_ZONE} --quiet
# Exit with the original exit code from the test script.
exit $$EXIT_CODE
waitFor:
- "create-vm"
- "generate-ssh-key"
- name: "gcr.io/google.com/cloudsdktool/cloud-sdk"
id: "cleanup-ssh-key"
entrypoint: "bash"
args:
- "-c"
- |
echo "--- Removing SSH key from OS Login profile to prevent accumulation ---"
gcloud compute os-login ssh-keys remove \
--key-file=/workspace/gcb_ssh_key.pub || true
waitFor:
- "run-tests-and-delete-vm"
timeout: "3600s" # 60 minutes
options:
logging: CLOUD_LOGGING_ONLY
pool:
name: "projects/${PROJECT_ID}/locations/us-central1/workerPools/cloud-build-worker-pool"