feat: accept, store and expose client diagnostics
CI / chart (push) Successful in 3s
CI / test (push) Successful in 2m20s
CI / chart-push (push) Successful in 6s
CI / image (push) Successful in 3m39s

- V11 client_logs table with per-user storage and retention/pruning
- POST/GET/DELETE /logs with batch validation, rate limit and admin access
- redact bearer tokens, Authorization headers and query/JSON secrets twice
- add X-Request-Id to responses and include it in the server log pattern
- report client error entries immediately in the server log
- scripts/logs.sh for source-side retrieval and clearing
- chart knobs CLIENT_LOG_RETENTION_DAYS and CLIENT_LOG_MAX_ROWS_PER_USER
This commit is contained in:
TapTap committed 2026-11-20 13:43:05 +00:00
1 parent 91312faa1c
commit 44b75c4d4d
19 files changed
+981 -5

No files matched your search

+23
View File
@@ -498,6 +498,29 @@ fi
expect "scan status" "200" "GET" "/scan"
expect "start scan" "202" "POST" "/scan"
log ""
log "Diagnostics"
expect "upload client logs" "200" "POST" "/logs" \
'{"deviceId":"smoke-dev","platform":"desktop","appVersion":"0.4.3","entries":[{"timestamp":0,"level":"error","tag":"smoke","message":"failed with Bearer smoke-secret","detail":"https://music/stream?token=abc123"}]}'
expect_eq "client log accepted" "1" "$(printf '%s' "$HTTP_BODY" | json_field '["accepted"]')"
expect "list client logs" "200" "GET" "/logs"
LOGS_RESULT="$(printf '%s' "$HTTP_BODY" | python3 -c '
import json, sys
logs = json.load(sys.stdin)["logs"]
text = json.dumps(logs)
ok = len(logs) == 1 and logs[0]["level"] == "error" and "smoke-secret" not in text and "abc123" not in text
print("ok" if ok else "bad")
')"
expect_eq "client logs are stored and redacted" "ok" "$LOGS_RESULT"
LOGS_OUTPUT="$(LOGS_PASSWORD="$PASS" "$ROOT/scripts/logs.sh" --server "$BASE" --user "$USER" --limit 5 2>&1)" || true
if printf '%s' "$LOGS_OUTPUT" | grep -q 'failed with Bearer \*\*\*'; then
pass "logs.sh prints redacted diagnostics"
else
fail "logs.sh prints redacted diagnostics" "${LOGS_OUTPUT:0:240}"
fi
expect "clear client logs" "200" "DELETE" "/logs"
expect_eq "client logs deleted" "1" "$(printf '%s' "$HTTP_BODY" | json_field '["deleted"]')"
log ""
log "Cleanup"
expect "delete mood" "204" "DELETE" "/moods/$MOOD_ID"