Skip to content

Commit 5495ed9

Browse files
author
KadenZhang3321
committed
Add OBS HK cross-region stability test workflow
Uploads a payload to ascend-ci-cache-hk, fans out concurrent readers across CN12/Guiyang/HK runners to measure bandwidth, latency and success rate, then aggregates a markdown report. Signed-off-by: KadenZhang3321 <1075567213@gmail.com>
1 parent 0a90f99 commit 5495ed9

4 files changed

Lines changed: 479 additions & 0 deletions

File tree

Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
name: obs-hk-stability-test
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
payload_mb:
7+
description: Payload object size in MB
8+
type: number
9+
default: 50
10+
readers:
11+
description: Number of concurrent reader jobs
12+
type: number
13+
default: 20
14+
downloads_per_reader:
15+
description: Repeated downloads per reader job
16+
type: number
17+
default: 5
18+
runner_pool:
19+
description: JSON array of {tag, region} objects or plain tags, readers spread round-robin
20+
type: string
21+
default: '[{"tag": "linux-aarch64-a3-2-cn12-001", "region": "cn12"}, {"tag": "linux-aarch64-a3-test-2", "region": "gy005"}, {"tag": "linux-aarch64-a3-test-4", "region": "gy005"}, {"tag": "linux-amd64-cpu-test-8-hk", "region": "hk"}]'
22+
delete_payload:
23+
description: Delete the test object from OBS when finished
24+
type: boolean
25+
default: true
26+
27+
concurrency:
28+
group: obs-hk-stability-test
29+
cancel-in-progress: false
30+
31+
env:
32+
OBS_ENDPOINT: https://obs.ap-southeast-1.myhuaweicloud.com
33+
OBS_BUCKET: ascend-ci-cache-hk
34+
PIP_INDEX_URL_FALLBACK: http://cache-service.nginx-pypi-cache.svc.cluster.local/pypi/simple
35+
36+
jobs:
37+
prepare:
38+
name: upload payload & plan readers
39+
runs-on: linux-amd64-cpu-test-8-hk
40+
timeout-minutes: 15
41+
env:
42+
HW_OBS_AK: ${{ secrets.HW_OBS_AK_HK }}
43+
HW_OBS_SK: ${{ secrets.HW_OBS_SK_HK }}
44+
outputs:
45+
object_key: ${{ steps.upload.outputs.object_key }}
46+
sha256: ${{ steps.upload.outputs.sha256 }}
47+
upload_mbps: ${{ steps.upload.outputs.upload_mbps }}
48+
matrix: ${{ steps.upload.outputs.matrix }}
49+
steps:
50+
- uses: actions/checkout@v4
51+
52+
- name: Bootstrap python tooling
53+
run: |
54+
set -e
55+
if ! command -v python3 >/dev/null 2>&1; then
56+
apt-get update -qq && apt-get install -y -qq python3 python3-pip \
57+
|| yum install -y -q python3 python3-pip
58+
fi
59+
python3 -V
60+
python3 -m pip --version >/dev/null 2>&1 \
61+
|| python3 -m ensurepip --upgrade \
62+
|| { apt-get install -y -qq python3-pip || yum install -y -q python3-pip; }
63+
python3 -m pip install --quiet esdk-obs-python \
64+
|| python3 -m pip install --quiet --index-url "$PIP_INDEX_URL_FALLBACK" \
65+
--trusted-host cache-service.nginx-pypi-cache.svc.cluster.local esdk-obs-python
66+
67+
- name: Upload payload and build matrix
68+
id: upload
69+
run: |
70+
python3 .github/workflows/scripts/obs_stability/prepare.py \
71+
--endpoint "$OBS_ENDPOINT" \
72+
--bucket "$OBS_BUCKET" \
73+
--key "obs-stability/${GITHUB_RUN_ID}-${GITHUB_RUN_ATTEMPT}/payload-${{ inputs.payload_mb }}mb.bin" \
74+
--size-mb "${{ inputs.payload_mb }}" \
75+
--readers "${{ inputs.readers }}" \
76+
--runner-pool '${{ inputs.runner_pool }}' \
77+
--output-file "$GITHUB_OUTPUT"
78+
79+
read:
80+
name: read-${{ matrix.reader_id }} (${{ matrix.region }})
81+
needs: prepare
82+
runs-on: ${{ matrix.runner }}
83+
timeout-minutes: 30
84+
strategy:
85+
fail-fast: false
86+
matrix:
87+
include: ${{ fromJSON(needs.prepare.outputs.matrix) }}
88+
env:
89+
HW_OBS_AK: ${{ secrets.HW_OBS_AK_HK }}
90+
HW_OBS_SK: ${{ secrets.HW_OBS_SK_HK }}
91+
steps:
92+
- uses: actions/checkout@v4
93+
94+
- name: Bootstrap python tooling
95+
run: |
96+
set -e
97+
if ! command -v python3 >/dev/null 2>&1; then
98+
apt-get update -qq && apt-get install -y -qq python3 python3-pip \
99+
|| yum install -y -q python3 python3-pip
100+
fi
101+
python3 -V
102+
python3 -m pip --version >/dev/null 2>&1 \
103+
|| python3 -m ensurepip --upgrade \
104+
|| { apt-get install -y -qq python3-pip || yum install -y -q python3-pip; }
105+
python3 -m pip install --quiet esdk-obs-python \
106+
|| python3 -m pip install --quiet --index-url "$PIP_INDEX_URL_FALLBACK" \
107+
--trusted-host cache-service.nginx-pypi-cache.svc.cluster.local esdk-obs-python
108+
109+
- name: Raw curl timing probes
110+
run: |
111+
mkdir -p /tmp/obs-test
112+
BASE="https://${OBS_BUCKET}.${OBS_ENDPOINT#https://}/"
113+
for i in $(seq 1 5); do
114+
curl -o /dev/null -s --max-time 30 \
115+
-w '%{http_code} %{time_namelookup} %{time_connect} %{time_appconnect} %{time_starttransfer} %{time_total}\n' \
116+
"$BASE" >> /tmp/obs-test/curl.txt || echo "000 0 0 0 0 -1" >> /tmp/obs-test/curl.txt
117+
done
118+
cat /tmp/obs-test/curl.txt
119+
120+
- name: Download payload ${{ inputs.downloads_per_reader }}x
121+
run: |
122+
python3 .github/workflows/scripts/obs_stability/read.py \
123+
--endpoint "$OBS_ENDPOINT" \
124+
--bucket "$OBS_BUCKET" \
125+
--key "${{ needs.prepare.outputs.object_key }}" \
126+
--sha256 "${{ needs.prepare.outputs.sha256 }}" \
127+
--downloads "${{ inputs.downloads_per_reader }}" \
128+
--region "${{ matrix.region }}" \
129+
--runner-id "${{ matrix.reader_id }}" \
130+
--runner-tag "${{ matrix.runner }}" \
131+
--out /tmp/obs-test/result.json
132+
133+
- uses: actions/upload-artifact@v4
134+
if: always()
135+
with:
136+
name: result-${{ matrix.reader_id }}
137+
path: /tmp/obs-test/
138+
139+
report:
140+
name: aggregate report
141+
needs: [prepare, read]
142+
if: always() && needs.prepare.result == 'success'
143+
runs-on: linux-amd64-cpu-test-8-hk
144+
timeout-minutes: 10
145+
steps:
146+
- uses: actions/checkout@v4
147+
148+
- uses: actions/download-artifact@v4
149+
with:
150+
pattern: result-*
151+
path: results
152+
153+
- name: Summary
154+
run: |
155+
python3 .github/workflows/scripts/obs_stability/report.py results \
156+
"${{ needs.prepare.outputs.object_key }}" \
157+
"${{ needs.prepare.outputs.upload_mbps }}" | tee /tmp/obs-report.md
158+
cat /tmp/obs-report.md >> "$GITHUB_STEP_SUMMARY"
159+
160+
cleanup:
161+
name: delete test object
162+
needs: [prepare, read]
163+
if: always() && inputs.delete_payload && needs.prepare.result == 'success'
164+
runs-on: linux-amd64-cpu-test-8-hk
165+
timeout-minutes: 10
166+
env:
167+
HW_OBS_AK: ${{ secrets.HW_OBS_AK_HK }}
168+
HW_OBS_SK: ${{ secrets.HW_OBS_SK_HK }}
169+
steps:
170+
- name: Delete payload
171+
run: |
172+
python3 -m pip install --quiet esdk-obs-python
173+
python3 - <<'EOF'
174+
import os
175+
from obs import ObsClient
176+
client = ObsClient(
177+
access_key_id=os.environ["HW_OBS_AK"],
178+
secret_access_key=os.environ["HW_OBS_SK"],
179+
server=os.environ["OBS_ENDPOINT"],
180+
)
181+
resp = client.deleteFile(os.environ["OBS_BUCKET"], "${{ needs.prepare.outputs.object_key }}")
182+
print("delete status:", resp.status)
183+
client.close()
184+
EOF
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
#!/usr/bin/env python3
2+
"""Upload a random payload to the HK OBS bucket and build the reader matrix."""
3+
4+
import argparse
5+
import hashlib
6+
import json
7+
import os
8+
import sys
9+
import time
10+
11+
from obs import ObsClient
12+
13+
CHUNK = 4 * 1024 * 1024
14+
15+
16+
def region_of(tag: str) -> str:
17+
if "cn12" in tag:
18+
return "cn12"
19+
if "gy0" in tag:
20+
return "guiyang"
21+
if "-hk" in tag:
22+
return "hongkong"
23+
return "other"
24+
25+
26+
def make_payload(size_mb: int, path: str) -> str:
27+
digest = hashlib.sha256()
28+
remaining = size_mb * 1024 * 1024
29+
with open(path, "wb") as f:
30+
while remaining > 0:
31+
block = os.urandom(min(CHUNK, remaining))
32+
digest.update(block)
33+
f.write(block)
34+
remaining -= len(block)
35+
return digest.hexdigest()
36+
37+
38+
def main() -> int:
39+
parser = argparse.ArgumentParser()
40+
parser.add_argument("--endpoint", required=True)
41+
parser.add_argument("--bucket", required=True)
42+
parser.add_argument("--key", required=True)
43+
parser.add_argument("--size-mb", type=int, required=True)
44+
parser.add_argument("--readers", type=int, required=True)
45+
parser.add_argument("--runner-pool", required=True)
46+
parser.add_argument("--output-file", default="")
47+
args = parser.parse_args()
48+
49+
pool = json.loads(args.runner_pool)
50+
if not pool:
51+
print("runner pool is empty", file=sys.stderr)
52+
return 1
53+
normalized = []
54+
for entry in pool:
55+
if isinstance(entry, str):
56+
normalized.append({"tag": entry, "region": region_of(entry)})
57+
else:
58+
tag = entry["tag"]
59+
normalized.append({"tag": tag, "region": entry.get("region", region_of(tag))})
60+
61+
payload = "/tmp/obs-stability-payload.bin"
62+
sha256 = make_payload(args.size_mb, payload)
63+
size_bytes = os.path.getsize(payload)
64+
print(f"payload: {args.size_mb} MB sha256={sha256}")
65+
66+
client = ObsClient(
67+
access_key_id=os.environ["HW_OBS_AK"],
68+
secret_access_key=os.environ["HW_OBS_SK"],
69+
server=args.endpoint,
70+
)
71+
start = time.perf_counter()
72+
resp = client.putFile(args.bucket, args.key, payload)
73+
elapsed = time.perf_counter() - start
74+
if resp.status >= 300:
75+
print(f"upload failed: status={resp.status} error={resp.errorMessage}", file=sys.stderr)
76+
return 1
77+
mbps = size_bytes * 8 / elapsed / 1e6
78+
print(f"uploaded {args.key} in {elapsed:.2f}s ({mbps:.1f} Mbps)")
79+
client.close()
80+
81+
matrix = [
82+
{
83+
"reader_id": i,
84+
"runner": normalized[i % len(normalized)]["tag"],
85+
"region": normalized[i % len(normalized)]["region"],
86+
}
87+
for i in range(args.readers)
88+
]
89+
90+
if args.output_file:
91+
with open(args.output_file, "a") as f:
92+
f.write(f"object_key={args.key}\n")
93+
f.write(f"sha256={sha256}\n")
94+
f.write(f"upload_mbps={mbps:.1f}\n")
95+
f.write(f"matrix={json.dumps(matrix)}\n")
96+
return 0
97+
98+
99+
if __name__ == "__main__":
100+
sys.exit(main())
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#!/usr/bin/env python3
2+
"""Download the payload from OBS repeatedly and record per-attempt timing."""
3+
4+
import argparse
5+
import hashlib
6+
import json
7+
import os
8+
import time
9+
10+
from obs import ObsClient
11+
12+
13+
def sha256_file(path: str) -> str:
14+
digest = hashlib.sha256()
15+
with open(path, "rb") as f:
16+
for block in iter(lambda: f.read(4 * 1024 * 1024), b""):
17+
digest.update(block)
18+
return digest.hexdigest()
19+
20+
21+
def main() -> None:
22+
parser = argparse.ArgumentParser()
23+
parser.add_argument("--endpoint", required=True)
24+
parser.add_argument("--bucket", required=True)
25+
parser.add_argument("--key", required=True)
26+
parser.add_argument("--sha256", required=True)
27+
parser.add_argument("--downloads", type=int, default=5)
28+
parser.add_argument("--region", default="other")
29+
parser.add_argument("--runner-id", default="")
30+
parser.add_argument("--runner-tag", default="")
31+
parser.add_argument("--out", required=True)
32+
args = parser.parse_args()
33+
34+
attempts = []
35+
verified = False
36+
for n in range(args.downloads):
37+
record = {"attempt": n, "ok": False, "seconds": None, "mbps": None, "error": None}
38+
client = ObsClient(
39+
access_key_id=os.environ["HW_OBS_AK"],
40+
secret_access_key=os.environ["HW_OBS_SK"],
41+
server=args.endpoint,
42+
)
43+
target = f"/tmp/obs-dl-{n}.bin"
44+
start = time.perf_counter()
45+
try:
46+
resp = client.getObject(args.bucket, args.key, download=target)
47+
elapsed = time.perf_counter() - start
48+
if resp.status >= 300:
49+
record["error"] = f"status={resp.status} {resp.errorMessage}"[:300]
50+
else:
51+
size = os.path.getsize(target)
52+
record["ok"] = True
53+
record["seconds"] = round(elapsed, 3)
54+
record["mbps"] = round(size * 8 / elapsed / 1e6, 1)
55+
record["bytes"] = size
56+
if not verified:
57+
actual = sha256_file(target)
58+
record["sha256_match"] = actual == args.sha256
59+
verified = actual == args.sha256
60+
except Exception as exc: # noqa: BLE001
61+
record["error"] = f"{type(exc).__name__}: {exc}"[:300]
62+
finally:
63+
client.close()
64+
if os.path.exists(target):
65+
os.remove(target)
66+
attempts.append(record)
67+
print(json.dumps(record))
68+
69+
result = {
70+
"reader_id": args.runner_id,
71+
"region": args.region,
72+
"runner_tag": args.runner_tag,
73+
"sha256_verified": verified,
74+
"attempts": attempts,
75+
}
76+
with open(args.out, "w") as f:
77+
json.dump(result, f, indent=2)
78+
79+
ok = sum(1 for a in attempts if a["ok"])
80+
print(f"{ok}/{args.downloads} attempts succeeded, sha256_verified={verified}")
81+
raise SystemExit(0 if ok > 0 else 1)
82+
83+
84+
if __name__ == "__main__":
85+
main()

0 commit comments

Comments
 (0)