Export kvcached metrics through SGLang's native endpoint - #421
Open
shipiyouniao wants to merge 2 commits into
Open
Export kvcached metrics through SGLang's native endpoint#421shipiyouniao wants to merge 2 commits into
shipiyouniao wants to merge 2 commits into
Conversation
Contributor
|
Caution The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased. |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds a read-only observability surface (runtime state, KV pool state, and operation counters) and wires kvcached metrics into SGLang’s existing Prometheus /metrics endpoint by composing with SGLang’s selected scheduler metrics collector (instead of running a separate exporter endpoint).
Changes:
- Introduce a process-local weak registry for live KV pools and expose runtime/pool/operation snapshots via
kvcached.observability. - Add operation counters + error tracking to
KVCacheManager, and register created managers from vLLM/SGLang integrations for snapshot enumeration. - Add SGLang metrics composition: wrap SGLang’s scheduler collector to update kvcached Prometheus metrics and integrate the patch via SGLang autopatch/version gating.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/test_sglang_metrics.py | Adds tests for Prometheus exporter behavior and collector wrapping/error isolation. |
| tests/test_observability.py | Adds tests for runtime/pool/operation snapshots, registry behavior, and integration registration/cleanup. |
| kvcached/pool_registry.py | Implements a weakref-based process-local registry for live KV cache managers. |
| kvcached/observability.py | Adds snapshot dataclasses/builders plus helpers to enumerate snapshots from the registry. |
| kvcached/kv_cache_manager.py | Adds pool naming and operation counters/error metadata; exposes snapshot methods. |
| kvcached/integration/vllm/interfaces.py | Registers created managers, clears registry on shutdown, and exposes integration snapshot helpers. |
| kvcached/integration/sglang/patches.py | Adds the SGLang metrics patch and passes stable pool names when creating managers. |
| kvcached/integration/sglang/metrics.py | Implements Prometheus exporter + wrapper collector class composition. |
| kvcached/integration/sglang/interfaces.py | Registers created managers, clears registry on shutdown, and exposes integration snapshot helpers. |
| kvcached/integration/sglang/autopatch.py | Registers the new metrics patch behind an SGLang version gate. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
shipiyouniao
force-pushed
the
feature/sglang-prometheus-metrics
branch
from
August 3, 2026 17:16
e86ee6a to
14a66e9
Compare
shipiyouniao
force-pushed
the
feature/sglang-prometheus-metrics
branch
2 times, most recently
from
August 19, 2026 10:47
ae9868f to
b1ec53f
Compare
Signed-off-by: 石皮幼鸟 <2960474346@qq.com>
shipiyouniao
force-pushed
the
feature/sglang-prometheus-metrics
branch
2 times, most recently
from
August 26, 2026 10:22
b1ec53f to
6dd80fd
Compare
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
/metricsendpointDesign
This reuses
ServerArgs.stat_loggersandresolve_collector_classinstead of starting another HTTP endpoint, background thread, filesystem protocol, or IPC channel. The wrapper subclasses whichever scheduler collector SGLang (or another integration) already selected and uses the collector's configured metric classes.The integration is active only when kvcached is enabled. SGLang remains responsible for enabling and serving metrics with
--enable-metrics; kvcached remains responsible for producing the underlying read-only snapshots.Depends on #385 and #410. This PR must not merge before both dependencies.
Related to #375.
Validation
ruff,codespell,isort,clang-format, PyMarkdown, actionlint, and trailing-whitespace hooks14 passed: observability and SGLang metrics tests/metricsexportedkvcached_runtime_*andkvcached_sglang_metrics_export_last_success_timestamp_seconds