mirror of
https://github.com/KohakuBlueleaf/KohakuHub.git
synced 2026-07-19 08:12:30 -05:00
Brings the L2 cache fully into the operational UI surface and tightens the
local-reset semantics around the cache.
Admin UI surface:
- New Cache page at /cache, modeled on the existing Health page: shows
configured/initialized state, namespace, Valkey memory + maxmemory_policy
+ eviction counter, the bootstrap-flush metadata (last seen run_id,
timestamp, keys flushed), and per-namespace hit/miss/error/set/invalidate
counters with computed hit rate. Auto-refresh selector with 0/5s/15s/60s
options. "Reset counters" button is gated to the operational state and
disabled when the cache is configured-off.
- Three operational states surfaced as a single tag:
* enabled — configured on AND client initialized
* degraded — configured on but client not initialized (silent
fallback to source — operationally important to
surface; without this, "low hit rate" looks like a
miss-heavy workload when actually Valkey is unreachable)
* disabled — configured off
- New AdminLayout nav entry pointing at /cache.
- New API client wrappers getCacheStats / resetCacheMetrics in
src/kohaku-hub-admin/src/utils/api.js, mirroring the read/probe split
used elsewhere.
Tests (test/kohaku-hub-admin/pages/test_cache_page.test.js, 11 cases):
mount + render assertions for each operational state; refresh button
re-fetches; reset confirm dialog flow (both confirmed and cancelled
paths) verified through ElMessageBox.confirm spying; 401/403 force
re-login; missing token redirects to /login; auto-refresh interval
toggles + unmount cleanup. ElMessageBox.confirm is hijacked via
``vi.spyOn`` against the live Element Plus module rather than
``vi.mock("element-plus", ...)``: Element Plus's resolved module identity
inside Vite differs from a test-file ``vi.mock`` interceptor, so spying
on the actual module is the only path that lets the SFC's
``await ElMessageBox.confirm(...)`` land in our test-controllable spy.
Reset semantics:
- ``scripts/dev/reset_local_data.sh`` now follows FLUSHALL with an
explicit synchronous SAVE on the dev Valkey container. Without this
the on-disk RDB still holds entries from before the reset; a Valkey
crash before the next BGSAVE would resurrect cache entries pointing
at repos / commits that no longer exist — observable as ghost cache
hits after ``make reset`` "succeeded".
Refs: #73, #74
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
84 lines
2.9 KiB
Bash
Executable File
84 lines
2.9 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
|
|
ENV_FILE="${ROOT_DIR}/.env.dev"
|
|
LAKEFS_CREDENTIALS_FILE="${ROOT_DIR}/hub-meta/dev/lakefs/credentials.env"
|
|
|
|
warn_red() {
|
|
printf '\033[1;31m%s\033[0m\n' "$1"
|
|
}
|
|
|
|
warn_red "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
|
|
warn_red "!! DANGER: THIS IRREVERSIBLY CLEARS LOCAL KOHAKUHUB DEV DATA !!"
|
|
warn_red "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
|
|
warn_red "This clears through the local reset helper:"
|
|
warn_red " - application data in PostgreSQL"
|
|
warn_red " - all objects in the local S3 bucket"
|
|
warn_red " - all LakeFS repositories in the local dev instance"
|
|
warn_red " - the local demo seed manifest"
|
|
warn_red ""
|
|
warn_red "Consequence:"
|
|
warn_red " - all local accounts, repos, orgs, commits, likes, and download stats are lost"
|
|
warn_red " - the Docker bind-mount directories are kept in place"
|
|
warn_red " - local infra stays running so you can re-seed immediately"
|
|
warn_red ""
|
|
warn_red ".env.dev and persisted LakeFS credentials are NOT removed."
|
|
echo
|
|
|
|
read -r -p "Continue with local reset? [y/N]: " confirmation
|
|
if [[ ! "${confirmation}" =~ ^[Yy]$ ]]; then
|
|
echo "Aborted. Local data was not changed."
|
|
exit 0
|
|
fi
|
|
|
|
if [[ ! -f "${ENV_FILE}" ]]; then
|
|
echo "Missing ${ENV_FILE}"
|
|
echo "Create it first: cp .env.dev.example .env.dev"
|
|
exit 1
|
|
fi
|
|
|
|
if [[ -n "${VIRTUAL_ENV:-}" ]]; then
|
|
PYTHON_BIN="${PYTHON_BIN:-python}"
|
|
elif [[ -x "${ROOT_DIR}/venv/bin/python" ]]; then
|
|
PYTHON_BIN="${PYTHON_BIN:-${ROOT_DIR}/venv/bin/python}"
|
|
else
|
|
PYTHON_BIN="${PYTHON_BIN:-python3}"
|
|
fi
|
|
|
|
set -a
|
|
# shellcheck disable=SC1090
|
|
source "${ENV_FILE}"
|
|
set +a
|
|
|
|
"${ROOT_DIR}/scripts/dev/up_infra.sh"
|
|
"${ROOT_DIR}/scripts/dev/run_backend.sh" --prepare-only --skip-seed
|
|
|
|
if [[ ! -f "${LAKEFS_CREDENTIALS_FILE}" ]]; then
|
|
echo "Missing ${LAKEFS_CREDENTIALS_FILE}"
|
|
echo "LakeFS bootstrap did not produce reusable credentials."
|
|
exit 1
|
|
fi
|
|
|
|
set -a
|
|
# shellcheck disable=SC1090
|
|
source "${LAKEFS_CREDENTIALS_FILE}"
|
|
set +a
|
|
|
|
"${PYTHON_BIN}" "${ROOT_DIR}/scripts/dev/reset_local_data_direct.py"
|
|
|
|
# Wipe the L2 cache after the reset. The cache references repos / commits
|
|
# that no longer exist; leaving stale Mode-A entries (commit_id-keyed) in
|
|
# place is correctness-safe but wastes memory. Targeted at the dev
|
|
# container only, never at production.
|
|
#
|
|
# We do FLUSHALL + synchronous SAVE so the on-disk RDB also reflects the
|
|
# empty state. Without the SAVE, a Valkey crash before the next BGSAVE
|
|
# would resurrect cache entries that point at repos / commits that no
|
|
# longer exist — observable as ghost hits after the reset.
|
|
if docker ps --format '{{.Names}}' | grep -Fxq "kohakuhub-dev-valkey"; then
|
|
docker exec kohakuhub-dev-valkey valkey-cli FLUSHALL >/dev/null 2>&1 || true
|
|
docker exec kohakuhub-dev-valkey valkey-cli SAVE >/dev/null 2>&1 || true
|
|
echo "Flushed kohakuhub-dev-valkey contents and persisted empty RDB"
|
|
fi
|