feat(ci): export job logs to loki, clean up pr artifacts #831

Sammanfogat
supernaut sammanfogade 4 incheckningar från feat/ci-logs-and-artifact-cleanup in i main 2026-10-19 22:54:06 +00:00
Ägare

Closes #177
Closes #178

CI job-log export (#177)

  • New role ci-log-export: 10-minute timer, Python script. Walks org repos, lists finished runs and jobs, downloads each job log as NDJSON (GET /repos/{o}/{r}/actions/jobs/{id}/logs?format=ndjson), pushes to Loki.
  • Labels: source, repo, workflow, ci_job, status. Run and job id are in the first log line, not labels.
  • State file of shipped repo#job.attempt keys. Window 120 h (Loki rejects samples older than 168 h).
  • Metrics bitborg_ci_log_export_*, alerts CiLogExportFailed and CiLogExportStale.

Artifact cleanup (#178)

  • New role artifact-cleanup: daily timer. Purges artifacts of pull_request* runs older than 7 days. Tag, release, push and schedule artifacts are kept. ARTIFACT_RETENTION_DAYS stays the backstop.
  • Dry run unless artifact_cleanup_delete_enabled: true.
  • Metrics bitborg_artifact_cleanup_*, alerts ArtifactCleanupFailed and ArtifactCleanupStale.

Tokens

Two new service accounts in forgejo_service_accounts (non-admin, one token each). Token-audit derives its list from that variable, so it covers them.

Operator steps

  • Apply with --tags forgejo to create bitborg-ci-logs and bitborg-artifact-cleanup.
  • Add bitborg-ci-logs to a read team and bitborg-artifact-cleanup to a write team (Actions unit) of the bitborg org.
  • Mint PATs: read:repository,read:organization and write:repository,read:organization. Vault as vault_forgejo_ci_log_export_token and vault_forgejo_artifact_cleanup_token.
  • Apply --tags ci-log-export,artifact-cleanup,monitoring.
  • Check Loki for {source="forgejo-actions"}.
  • Read a dry-run journal of bitborg-artifact-cleanup, then set artifact_cleanup_delete_enabled: true and apply.

Tests

python3 ansible/roles/ci-log-export/files/test_ci_log_export.py, python3 ansible/roles/artifact-cleanup/files/test_artifact_cleanup.py, wired into CI.

Closes #177 Closes #178 ## CI job-log export (#177) - New role `ci-log-export`: 10-minute timer, Python script. Walks org repos, lists finished runs and jobs, downloads each job log as NDJSON (`GET /repos/{o}/{r}/actions/jobs/{id}/logs?format=ndjson`), pushes to Loki. - Labels: `source`, `repo`, `workflow`, `ci_job`, `status`. Run and job id are in the first log line, not labels. - State file of shipped `repo#job.attempt` keys. Window 120 h (Loki rejects samples older than 168 h). - Metrics `bitborg_ci_log_export_*`, alerts `CiLogExportFailed` and `CiLogExportStale`. ## Artifact cleanup (#178) - New role `artifact-cleanup`: daily timer. Purges artifacts of `pull_request*` runs older than 7 days. Tag, release, push and schedule artifacts are kept. `ARTIFACT_RETENTION_DAYS` stays the backstop. - Dry run unless `artifact_cleanup_delete_enabled: true`. - Metrics `bitborg_artifact_cleanup_*`, alerts `ArtifactCleanupFailed` and `ArtifactCleanupStale`. ## Tokens Two new service accounts in `forgejo_service_accounts` (non-admin, one token each). Token-audit derives its list from that variable, so it covers them. ## Operator steps - [ ] Apply with `--tags forgejo` to create `bitborg-ci-logs` and `bitborg-artifact-cleanup`. - [ ] Add `bitborg-ci-logs` to a read team and `bitborg-artifact-cleanup` to a write team (Actions unit) of the `bitborg` org. - [ ] Mint PATs: `read:repository,read:organization` and `write:repository,read:organization`. Vault as `vault_forgejo_ci_log_export_token` and `vault_forgejo_artifact_cleanup_token`. - [ ] Apply `--tags ci-log-export,artifact-cleanup,monitoring`. - [ ] Check Loki for `{source="forgejo-actions"}`. - [ ] Read a dry-run journal of `bitborg-artifact-cleanup`, then set `artifact_cleanup_delete_enabled: true` and apply. ## Tests `python3 ansible/roles/ci-log-export/files/test_ci_log_export.py`, `python3 ansible/roles/artifact-cleanup/files/test_artifact_cleanup.py`, wired into CI.
supernaut lade till 4 incheckningar 2026-10-19 19:10:36 +00:00
Timer script lists finished runs of the org repos, downloads each job log
as NDJSON and pushes it to Loki with low-cardinality labels. A state file
makes each job ship once.

Refs #177
Keeps artifacts of tag, release, push and schedule runs. Wires both new
roles into site.yml, service accounts, vault example, alerts, CI tests and
the runbook.

Closes #177
Closes #178
The org repo list needs read:organization on both PATs. Ship runs oldest
first so Loki's out-of-order window does not reject backfill. Write state
atomically after each job, tolerate a corrupt state file and always write
metrics. Use plain metric names in the new alerts and fix a timer
description.
fix(artifact-cleanup): isolate per-repo errors, always write metrics
Alla kontroller lyckades
ci / ci (pull_request) Successful in 9m9s
c0e93d8062
A failing repo list or artifact list no longer aborts the run, and an
uncaught error still writes metrics so ArtifactCleanupFailed can fire.
supernaut sammanfogade incheckning 77986e8cfb till main 2026-10-19 22:54:06 +00:00
supernaut tog bort grenen feat/ci-logs-and-artifact-cleanup 2026-10-19 22:54:06 +00:00
Logga in för att delta i denna konversation.
Inga granskare
Ingen milstolpe
Inget projekt
Inga tilldelade
1 deltagare
Notiser
Förfallodatum
Förfallodatumet är ogiltigt eller utanför gränserna. Använd formatet "åååå-mm-dd".

Inget förfallodatum satt.

Beroenden

Inga beroenden satta

Referens
bitborg/bitborg-infra!831
Ingen beskrivning angiven.