Files
DongHyeonka dd8e9140b7 feat(ci): add a read-only CI metrics script for the desktop runner
There is no number for how long CI runs wait, how busy the one runner is,
how many runs a pull request costs or how long main stays red. Run times
were added up by hand from single runs, so whether a change helped could
not be told apart from load.

infrastructure/ci/metrics/ci_metrics.py reads the Gitea Actions API (runs,
their jobs, closed pull requests) for the repositories the runner serves
and prints the CI manual's metrics 1-5 per repository and stage: run
execution p50/p90, queue wait p50/p90, runner utilisation per KST day,
pull request runs per merged pull request, and main red time. It only
reads; credentials come from GITEA_TOKEN or `git credential fill` and are
never printed.

The arithmetic follows what our Gitea 1.27 returns, which differs from the
API reference: a run has no created_at (the earliest job created_at is
used), unstarted runs and jobs report 1970-01-01 times (treated as
absent), and a job's created_at is its run's, so queue wait is measured
per run (first job start minus run creation) instead of per job.

Verification: python3 -m unittest test_ci_metrics (11 offline tests) and
one run against the server for 2026-11-07..13 (two repositories, 30 s,
rc=0). The sensitive-source scan needs rg and ran on the desktop host.

Refs: design-docs ci/03-time-reduction-plan.md M-0
2026-11-13 19:34:38 +09:00
..

CI 지표

desktop runner 하나가 받는 repo들의 CI 지표를 Gitea Actions API에서 뽑는다. 읽기만 하고 서버에 아무것도 쓰지 않는다. 지표의 정의와 목표는 design-docs ci/manual.md 10절이고, 주 1회 결과를 design-docs ci/metrics.md에 한 줄 남긴다.

돌리기

python3 infrastructure/ci/metrics/ci_metrics.py \
  --repo clean-architecture-backend-template \
  --repo clean-architecture-frontend-template \
  --since 2026-11-07 --until 2026-11-13
  • 날짜는 KST 하루 단위이고 --until도 그날을 포함한다(--utc-offset-hours로 바꾼다).
  • 인증: GITEA_TOKEN(읽기 전용 토큰)이 있으면 그것을, 없으면 git credential fill의 그 호스트 자격 증명을 쓴다. 어느 쪽도 출력하지 않는다.
  • --json은 표 대신 숫자를 JSON으로 낸다.
  • 두 repo, 지난 7일이면 30초 안팎이다(run마다 jobs API를 한 번 부른다).

내는 것

# 지표 계산
1 실행 시간 p50·p90 단계(workflow:event)별, 끝난 run(success·failure)의 job 실행 시간 합. cancelled run은 run 수에만 센다
2 대기 시간 p50·p90 run의 첫 job 시작 − run 생성
3 runner 사용률 날짜(job 시작 시각, KST)별 job 실행 시간 합 ÷ 1,440분. 준 repo를 모두 더한다(runner가 하나라서)
4 PR당 run 수 기간 안에 병합된 PR마다 그 PR의 pull_request run 수. 병합 전 7일의 run까지 센다
5 main 빨강 시간 workflow별 main push run이 처음 실패한 run의 생성부터 다음 성공 run의 끝까지. 기간 끝까지 빨강이면 그때까지

지표 6(흔들림)은 각 repo docs/ledger/flaky-tests.jsonl, 지표 7(캐시 적중)은 PR run 로그에서 나온다. 이 스크립트는 보지 않는다.

우리 서버(Gitea 1.27)가 API 명세와 다른 곳

2026-11-13 응답 한 건씩으로 확인했다. 계산은 서버를 따른다.

  • run에 created_at이 없다. run의 job은 run과 함께 만들어지므로, job created_at의 가장 이른 값을 run 생성 시각으로 쓴다.
  • 시작하지 않은 run·job의 started_at·completed_at은 1970-01-01T00:00:00Z다. 없는 값으로 본다.
  • job의 created_at은 그 job이 실행할 수 있게 된 시각이 아니라 run의 생성 시각이다. runner 하나가 run의 job을 차례로 돌리므로 job마다 started_at − created_at을 대기로 세면 앞 job의 실행이 대기에 들어간다. 그래서 대기는 run 단위로 센다. needs가 있는 job이 늦게 풀려 대기열 뒤로 가는 시간은 이 지표에 안 보이고 실행 시간에도 안 들어간다.
  • run 목록의 run에는 head_branch가 없다. 단계와 ref는 path(<workflow>@<ref>)에서 읽고, PR 번호는 pull_requests에서 읽는다.

시험

cd infrastructure/ci/metrics && python3 -m unittest -v test_ci_metrics

서버 없이 계산만 본다. 만든 run·job 기록으로 대기·실행·빨강 시간·사용률을 확인한다.