feat: add kvweb rest api - #457
Open
allen3325 wants to merge 4 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds an HTTP control surface (kvweb) for inspecting /dev/shm KV-cache segments and applying the same limit operations that kvctl limit performs, with FastAPI-generated docs and an SSE status stream.
Changes:
- Introduces
kvcached.cli.kvweb(FastAPI app) with status, IPC inspection, limit mutation, delete, and SSE streaming endpoints. - Extends
kvctlwith awebsubcommand and reuses the renamedparse_size()helper for size parsing. - Adds endpoint-level tests + docs, and updates CI/test manifests to run the new API tests.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
tests/test_kvweb_api.py |
Adds end-to-end API tests (CRUD-ish flows, auth, SSE behavior). |
tests/manifests/cpu.txt |
Ensures the new API test is included in the CPU suite classification. |
pyproject.toml |
Registers kvweb script and adds web optional dependencies. |
kvcached/cli/kvweb.py |
Implements the FastAPI-based REST/SSE control API and server entrypoint. |
kvcached/cli/kvctl.py |
Adds kvctl web + interactive-shell dispatch; renames _parse_size to parse_size. |
docs/WEB_API.md |
Documents install/run, endpoints, and security model for the web API. |
.github/workflows/cpu-tests.yml |
Installs web-related deps in CPU CI so the new tests can run. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Collaborator
|
Hi, thanks for the contribution, however, i dont think we need this in kvcached, it could be something in the production layer like discussed in #375 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
kvctlandkvtoponly work in terminal. this PR exposes the same/dev/shmKV cache stats over HTTP, plus the limit changeskvctl limitperforms, so asegment can be inspected or resized from HTTP. Start it with
kvweborkvctl web; FastAPI generates the docs at/docs.GET /api/status,/api/ipcs,/api/ipcs/{name},POST .../limit,POST .../limit-percent,DELETE .../{name}, andGET /api/stream(SSE).Details in
docs/WEB_API.md.Notes for review
127.0.0.1, sends no CORS headers, and takes an optional API key viaKVCACHED_WEB_API_KEY. Binding elsewhere without a key prints a warning.RwLockedShmsilently creates missing files when updating limits. We added an upfront existence check that throws a 404 so a typo doesn't spawn random dummy segments in kvtop. (kvctl limithas the same behaviour today; not touched here.)fastapi/uvicornare an optionalwebextra, andkvctlimportskvweblazily, so nothing changes for users who do not install it._parse_size()inkvctl.pyis renamedparse_size()and reused, rather than copied into the new module.kvctlshell bug this touched:webwas inCOMMANDSand the help text but had no dispatch branch, so it fell through to theos.system()fallback.I'll follow up with a web dashboard PR on top of this API.
Testing
tests/test_kvweb_api.pycovers the endpoints, the 404 paths, and the API key.Full CPU suite passes (176), as does
pre-commit run --all-files.Adds [fastapi, uvicorn, pydantic, httpx] to the CPU CI deps so the new tests actually run