From 5b4443c67e0ba788090fdedc6fc605233d857a66 Mon Sep 17 00:00:00 2001 From: Codex Date: Sat, 30 May 2026 03:11:25 +0800 Subject: [PATCH] chore: add git mirror sync timing --- scripts/g14-gitops-render.mjs | 19 +++++++++++++++++++ scripts/g14-gitops-render.test.ts | 3 +++ 2 files changed, 22 insertions(+) diff --git a/scripts/g14-gitops-render.mjs b/scripts/g14-gitops-render.mjs index 749c0d82..359c8712 100644 --- a/scripts/g14-gitops-render.mjs +++ b/scripts/g14-gitops-render.mjs @@ -2808,6 +2808,16 @@ set -eu repo_url="ssh://git@ssh.github.com:443/pikasTech/HWLAB.git" repo_path="/cache/pikasTech/HWLAB.git" lock_dir="/cache/.hwlab-sync.lock" +sync_started_ms=$(node -e 'console.log(Date.now())') +now_ms() { node -e 'console.log(Date.now())'; } +emit_timing() { + phase="$1" + status="$2" + started_ms="$3" + finished_ms=$(now_ms) + duration_ms=$((finished_ms - started_ms)) + printf '{"event":"git-mirror-sync-timing","phase":"%s","status":"%s","durationMs":%s,"repository":"pikasTech/HWLAB"}\n' "$phase" "$status" "$duration_ms" +} mkdir -p /cache/pikasTech /root/.ssh if ! mkdir "$lock_dir" 2>/dev/null; then echo "git mirror sync already running" @@ -2830,7 +2840,9 @@ git -C "$repo_path" config --add remote.origin.fetch '+refs/heads/v0.2:refs/mirr git -C "$repo_path" config --add remote.origin.fetch '+refs/heads/v0.2-gitops:refs/mirror-stage/heads/v0.2-gitops' git -C "$repo_path" config --add remote.origin.fetch '+refs/heads/G14:refs/mirror-stage/heads/G14' git -C "$repo_path" config --add remote.origin.fetch '+refs/heads/G14-gitops:refs/mirror-stage/heads/G14-gitops' +fetch_started_ms=$(now_ms) timeout 180 git -C "$repo_path" fetch --quiet --prune origin +emit_timing fetch succeeded "$fetch_started_ms" git -C "$repo_path" for-each-ref --format='%(objectname) %(refname)' refs/mirror-stage/heads > /tmp/hwlab-stage-heads git -C "$repo_path" for-each-ref --format='%(refname)' refs/mirror-stage/heads > /tmp/hwlab-stage-head-refs git -C "$repo_path" for-each-ref --format='%(objectname) %(refname)' refs/mirror-stage/tags > /tmp/hwlab-stage-tags @@ -2842,6 +2854,7 @@ fi for required_ref in refs/mirror-stage/heads/v0.2 refs/mirror-stage/heads/v0.2-gitops refs/mirror-stage/heads/G14 refs/mirror-stage/heads/G14-gitops; do git -C "$repo_path" show-ref --verify --quiet "$required_ref" || { echo "git mirror sync missing required ref $required_ref" >&2; exit 43; } done +validate_started_ms=$(now_ms) while read -r sha ref; do [ -n "$sha" ] || continue git -C "$repo_path" cat-file -e "$sha^{commit}" @@ -2851,6 +2864,8 @@ while read -r sha ref; do exit 42 fi done < /tmp/hwlab-stage-heads +emit_timing validate succeeded "$validate_started_ms" +publish_started_ms=$(now_ms) while read -r sha ref; do [ -n "$sha" ] || continue name=$(printf '%s\n' "$ref" | sed 's#^refs/mirror-stage/heads/##') @@ -2877,12 +2892,15 @@ while read -r ref; do git -C "$repo_path" update-ref -d "$ref" fi done < /tmp/hwlab-public-tags +emit_timing publish succeeded "$publish_started_ms" if git -C "$repo_path" show-ref --verify --quiet refs/heads/v0.2; then git -C "$repo_path" symbolic-ref HEAD refs/heads/v0.2 elif git -C "$repo_path" show-ref --verify --quiet refs/heads/G14; then git -C "$repo_path" symbolic-ref HEAD refs/heads/G14 fi +fsck_started_ms=$(now_ms) git -C "$repo_path" fsck --connectivity-only --no-dangling >/tmp/hwlab-git-fsck.out +emit_timing fsck succeeded "$fsck_started_ms" git -C "$repo_path" update-server-info v02_head=$(git -C "$repo_path" rev-parse refs/heads/v0.2 2>/dev/null || true) g14_head=$(git -C "$repo_path" rev-parse refs/heads/G14 2>/dev/null || true) @@ -2905,6 +2923,7 @@ const payload = { }; console.log(JSON.stringify(payload)); NODE +emit_timing total succeeded "$sync_started_ms" `, "http.mjs": `import { createServer } from "node:http"; import { spawn } from "node:child_process"; diff --git a/scripts/g14-gitops-render.test.ts b/scripts/g14-gitops-render.test.ts index 8e91ce27..24fc2f8e 100644 --- a/scripts/g14-gitops-render.test.ts +++ b/scripts/g14-gitops-render.test.ts @@ -93,6 +93,9 @@ test("v02 render follows TypeScript runtime checks and does not self-patch boots assert.match(gitMirrorScript, /refs\/heads\/G14-gitops:refs\/mirror-stage\/heads\/G14-gitops/u); assert.doesNotMatch(gitMirrorScript, /refs\/heads\/\*:refs\/mirror-stage\/heads\/\*/u); assert.match(gitMirrorScript, /git -C "\$repo_path" update-ref "refs\/heads\/\$name" "\$sha"/u); + assert.match(gitMirrorScript, /git-mirror-sync-timing/u); + assert.match(gitMirrorScript, /emit_timing fetch succeeded/u); + assert.match(gitMirrorScript, /emit_timing total succeeded/u); assert.ok((gitMirrorJson.items || []).every((item) => item.kind !== "Secret")); assert.ok((gitMirrorJson.items || []).every((item) => item.kind !== "CronJob")); assert.ok((gitMirrorJson.items || []).every((item) => !item.data?.["ssh-privatekey"]));