forgejo/prune: prune every Docker daemon, cap builder cache by age, alert on growth
The nightly CronJob reported Complete while never reclaiming build cache: docker 27/buildx 0.20.1 accepts --keep-storage and --max-used-space but returns 'Total: 0B' for both (measured: 21.44GB cache with a 20GB cap, and 541MB cache with a 100MB cap). The comment claiming 53GB reclaimed was true on an older CLI and is now false. --filter until= does reclaim, so the cash cap is enforced by walking age windows down (72h -> 0s) and stopping as soon as the cache is under the cap. Coverage is now every daemon, discovered not listed: the Pi host socket and every in-cluster dind pod matching label app=forgejo-runner with a dind container, pruned over pods/exec with a namespace-scoped ServiceAccount, so the arm64 dind migration is picked up without editing this job. Busy guard skips a daemon with a live build and still exits 0. Named volumes are never pruned; their sizes are printed every run. Adds PrometheusRule forgejo-prune: cronjob staleness/failure plus node filesystem high-watermark.
This commit is contained in:
parent
e63af123c5
commit
f1fcf21a94
3 changed files with 497 additions and 28 deletions
|
|
@ -7,6 +7,7 @@ resources:
|
|||
- release.yaml
|
||||
- httproute.yaml
|
||||
- gateway-probe.yaml
|
||||
- prune-alerts.yaml
|
||||
- dashboards
|
||||
configMapGenerator:
|
||||
- name: kube-prometheus-stack-values
|
||||
|
|
|
|||
176
monitoring/controllers/home/prune-alerts.yaml
Normal file
176
monitoring/controllers/home/prune-alerts.yaml
Normal file
|
|
@ -0,0 +1,176 @@
|
|||
# Alerts for the disk-reclamation job and the daemons it prunes.
|
||||
#
|
||||
# Context: `forgejo/forgejo-runner-prune` reclaims build cache nightly. Its
|
||||
# own success/failure is invisible unless kube-state-metrics is watched, and
|
||||
# the failure mode it exists to prevent (a full disk on siriussec → DiskPressure
|
||||
# → Forgejo + Postgres evicted, public 503) shows up in node_exporter first.
|
||||
#
|
||||
# What is measurable here:
|
||||
# - node filesystem utilisation per node (node-exporter, all three nodes);
|
||||
# on siriussec the local-path PVs — including the runner's dind data-root —
|
||||
# live on `/`, so this is the DiskPressure precursor and the PVC watchdog
|
||||
# in one series.
|
||||
# - CronJob last-success timestamp and Job failure counters
|
||||
# (kube-state-metrics).
|
||||
#
|
||||
# What is NOT measurable here: kubelet_volume_stats_* does not exist on this
|
||||
# cluster. Verified 2026-10-27: kubelet v1.36.4 exposes
|
||||
# kubelet_volume_metric_collection_duration_seconds but no
|
||||
# kubelet_volume_stats_used_bytes / _capacity_bytes on any node
|
||||
# (`kubectl get --raw /api/v1/nodes/<node>/proxy/metrics | grep volume_stats`
|
||||
# is empty, and Prometheus has zero series). So the per-PVC rules below are
|
||||
# written against those metric names but stay inert until a kubelet exports
|
||||
# them; the node-filesystem rules are the live coverage. Per-PVC and per-Docker
|
||||
# -volume sizes are printed by the prune job every night
|
||||
# (`docker system df -v`), which is the record of growth.
|
||||
#
|
||||
# Alertmanager is disabled in this stack (monitoring card), so these surface in
|
||||
# Prometheus → Alerts and Grafana → Alerting. No external receiver is added.
|
||||
apiVersion: monitoring.coreos.com/v1
|
||||
kind: PrometheusRule
|
||||
metadata:
|
||||
name: forgejo-prune
|
||||
namespace: monitoring
|
||||
labels:
|
||||
release: kube-prometheus-stack
|
||||
spec:
|
||||
groups:
|
||||
- name: forgejo-prune
|
||||
rules:
|
||||
- alert: ForgejoPruneCronJobStale
|
||||
# 04:17 UTC nightly; 26 h leaves room for one missed tick before it
|
||||
# pages a human. `or absent(...)` catches the job being deleted or
|
||||
# never having succeeded at all.
|
||||
expr: |
|
||||
(
|
||||
time() - kube_cronjob_status_last_successful_time{namespace="forgejo", cronjob="forgejo-runner-prune"} > 26 * 3600
|
||||
)
|
||||
or
|
||||
absent(kube_cronjob_status_last_successful_time{namespace="forgejo", cronjob="forgejo-runner-prune"})
|
||||
for: 10m
|
||||
labels:
|
||||
severity: warning
|
||||
annotations:
|
||||
summary: >-
|
||||
forgejo-runner-prune has not completed successfully in over 26 h
|
||||
description: >-
|
||||
Build cache, exited containers and unused images are not being
|
||||
reclaimed on the Pi host daemon or on the dind daemons. Check
|
||||
`kubectl -n forgejo get jobs -l role=prune` and the pod logs of
|
||||
the newest Job; the job skips (exit 0) when a build is live, but
|
||||
a *stale* success means it has not run at all. Force one run:
|
||||
kubectl -n forgejo create job --from=cronjob/forgejo-runner-prune prune-manual-$(date +%s)
|
||||
- alert: ForgejoPruneJobFailed
|
||||
# kube_job_failed was removed from kube-state-metrics; the supported
|
||||
# series is kube_job_status_failed (0 for a successful job, >0 when a
|
||||
# pod failed). Only the most recent jobs are kept in Prometheus, so a
|
||||
# transient failure ages out on its own after the history limit.
|
||||
expr: |
|
||||
max by (job_name) (
|
||||
kube_job_status_failed{namespace="forgejo", job_name=~"forgejo-runner-prune-.*"}
|
||||
) > 0
|
||||
for: 5m
|
||||
labels:
|
||||
severity: warning
|
||||
annotations:
|
||||
summary: forgejo-runner-prune Job {{ $labels.job_name }} has a failed pod
|
||||
description: >-
|
||||
A prune run failed (or its dind discovery/exec container did).
|
||||
Read `kubectl -n forgejo logs job/{{ $labels.job_name }} -c
|
||||
dind-daemons` — a failure there means a running dind daemon was
|
||||
not reachable over the exec API, so that daemon is growing
|
||||
unpruned. One retry is allowed by backoffLimit; persistent
|
||||
failures need the RBAC or the pod checked.
|
||||
# Per-PVC rules: correct expressions, currently inert (see the header —
|
||||
# this cluster's kubelet exports no kubelet_volume_stats_* series). They
|
||||
# start working the day that comes back, and they cost nothing until
|
||||
# then. Coverage today is NodeFilesystemFillingUp on siriussec, where
|
||||
# every local-path PV physically lives.
|
||||
- alert: RunnerDindPvcHighWatermark
|
||||
expr: |
|
||||
max by (namespace, persistentvolumeclaim) (
|
||||
kubelet_volume_stats_used_bytes{namespace="forgejo", persistentvolumeclaim=~"forgejo-runner-.*"}
|
||||
)
|
||||
/
|
||||
max by (namespace, persistentvolumeclaim) (
|
||||
kubelet_volume_stats_capacity_bytes{namespace="forgejo", persistentvolumeclaim=~"forgejo-runner-.*"}
|
||||
) > 0.85
|
||||
for: 15m
|
||||
labels:
|
||||
severity: warning
|
||||
annotations:
|
||||
summary: >-
|
||||
dind PVC {{ $labels.persistentvolumeclaim }} is over 85% full
|
||||
description: >-
|
||||
The image/build-cache/volume footprint on this runner's dind
|
||||
daemon is approaching the 20Gi PVC. Inspect it with
|
||||
`kubectl -n forgejo exec <runner-pod> -c dind -- docker system df -v`;
|
||||
the nightly prune caps build cache but never deletes named
|
||||
volumes.
|
||||
- alert: RunnerDindPvcCritical
|
||||
expr: |
|
||||
max by (namespace, persistentvolumeclaim) (
|
||||
kubelet_volume_stats_used_bytes{namespace="forgejo", persistentvolumeclaim=~"forgejo-runner-.*"}
|
||||
)
|
||||
/
|
||||
max by (namespace, persistentvolumeclaim) (
|
||||
kubelet_volume_stats_capacity_bytes{namespace="forgejo", persistentvolumeclaim=~"forgejo-runner-.*"}
|
||||
) > 0.95
|
||||
for: 5m
|
||||
labels:
|
||||
severity: critical
|
||||
annotations:
|
||||
summary: >-
|
||||
dind PVC {{ $labels.persistentvolumeclaim }} is over 95% full
|
||||
description: >-
|
||||
Builds will start failing with ENOSPC. Scale the runner to 0,
|
||||
raise the PVC, or clear the dind data-root deliberately (see the
|
||||
DiskPressure runbook in the home-k8s skill) — do not wipe it
|
||||
while the runner pod is up.
|
||||
- name: disk-capacity
|
||||
rules:
|
||||
- alert: NodeFilesystemFillingUp
|
||||
# Root filesystem per node, named by hostname rather than IP so the
|
||||
# alert is actionable. 85% is where kubelet's imagefs/nodefs GC and
|
||||
# the DiskPressure taint start to matter on siriussec; the Pi's
|
||||
# Docker volumes (169 GB of CI caches) live here too.
|
||||
expr: |
|
||||
(
|
||||
1 - (
|
||||
node_filesystem_avail_bytes{mountpoint="/", fstype=~"ext4|xfs|btrfs"}
|
||||
/
|
||||
node_filesystem_size_bytes{mountpoint="/", fstype=~"ext4|xfs|btrfs"}
|
||||
)
|
||||
) * on (instance) group_left (nodename) node_uname_info > 0.85
|
||||
for: 30m
|
||||
labels:
|
||||
severity: warning
|
||||
annotations:
|
||||
summary: "{{ $labels.nodename }} root filesystem is {{ $value | humanizePercentage }} full"
|
||||
description: >-
|
||||
Reclaim with `kubectl -n forgejo create job
|
||||
--from=cronjob/forgejo-runner-prune prune-manual-$(date +%s)` (it
|
||||
prunes the Pi host daemon and every dind daemon), and read that
|
||||
job's `docker system df -v` output for the volumes that are
|
||||
growing. At 85% kubelet starts evicting on siriussec — that is
|
||||
the Forgejo 503 failure mode.
|
||||
- alert: NodeFilesystemCritical
|
||||
expr: |
|
||||
(
|
||||
1 - (
|
||||
node_filesystem_avail_bytes{mountpoint="/", fstype=~"ext4|xfs|btrfs"}
|
||||
/
|
||||
node_filesystem_size_bytes{mountpoint="/", fstype=~"ext4|xfs|btrfs"}
|
||||
)
|
||||
) * on (instance) group_left (nodename) node_uname_info > 0.92
|
||||
for: 10m
|
||||
labels:
|
||||
severity: critical
|
||||
annotations:
|
||||
summary: "{{ $labels.nodename }} root filesystem is {{ $value | humanizePercentage }} full"
|
||||
description: >-
|
||||
DiskPressure is imminent/immediate. Free space before the next
|
||||
build: prune now, then check `docker system df -v` on that host
|
||||
for the named volume that grew (never delete named volumes
|
||||
blind — onionwire-target-ci and the Android SDK/Gradle caches
|
||||
are shared CI state).
|
||||
Loading…
Reference in a new issue