Skip to content

feat(devshard): expose gateway chat cache size metric#1410

Closed
ouicate wants to merge 1 commit into
gonka-ai:mainfrom
ouicate:feat/devshard-chat-cache-metric
Closed

feat(devshard): expose gateway chat cache size metric#1410
ouicate wants to merge 1 commit into
gonka-ai:mainfrom
ouicate:feat/devshard-chat-cache-metric

Conversation

@ouicate

@ouicate ouicate commented Jul 6, 2026

Copy link
Copy Markdown

Problem

The gateway chat cache exports no metrics, so operators can't see how many responses are cached or how occupancy tracks traffic. Every other gateway subsystem (limiter, capacity, participant limiter, host connections) already exposes gauges via gatewayMetricsCollector; the cache was the only unobservable one.

Fix

Add a chatResponseCache.Len() accessor and a new gauge devshard_gateway_chat_cache_entries to gatewayMetricsCollector — declared in Describe, emitted in Collect when gateway.chatCache != nil. No labels
(single process-wide cache). Purely additive, read-only, reuses the existing collector wiring.

Tests

TestGatewayMetricsCollectorReportsChatCacheEntries seeds two entries and asserts the gauge reads 2 via the registry, following the existing requireMetricGaugeValue pattern.

Note

Companion to #1409 (which bounds the same cache). Independent of it: this PR only adds the accessor + gauge, so it applies cleanly on its own, and #1409 keeps the reported count bounded.

The gateway chat cache exports no metrics, so operators can't see how many
responses are cached or how occupancy tracks traffic -- every other gateway
subsystem (limiter, capacity, participant limiter, host connections) already
exposes gauges via gatewayMetricsCollector.

Add a chatResponseCache.Len() accessor and a devshard_gateway_chat_cache_entries
gauge, declared in Describe and emitted in Collect when chatCache is set. No
labels (single process-wide cache); purely additive and read-only.
@qdanik

qdanik commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

@ouicate Please, take a look into PR #1402 and adjust your changes based on changes in #1402.

One note: #1402 adds a Stats() accessor returning (entryCount, totalBytes) that overlaps this PR's Len(). Since #1402 bounds the cache by BYTES, if it lands first, rebasing onto Stats() and also exposing a bytes gauge (devshard_gateway_chat_cache_bytes) would match what actually caps the cache.

@ouicate ouicate closed this Jul 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants