feat(observer): add context usage metrics endpoint#1361
feat(observer): add context usage metrics endpoint#1361mvanhorn wants to merge 1 commit intovolcengine:mainfrom
Conversation
Add UsageObserver and /api/v1/observer/usage endpoint that returns vector count from VikingDB. Extends the existing observer pattern (BaseObserver + router endpoint) to provide usage visibility alongside the existing health checks. The endpoint follows the same auth flow as other observer endpoints, scoping results to the authenticated user's context.
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Explore these optional code suggestions:
|
Description
Add a
/api/v1/observer/usageendpoint that returns context usage metrics (vector count from VikingDB). The existing observer system shows component health (healthy/unhealthy) but provides no usage data. This endpoint answers "how much is stored?" alongside the existing "is it working?" checks.Related Issue
No existing issue. This fills a gap in the observer system where health checks exist but usage metrics do not.
Type of Change
Changes Made
UsageObserverclass inopenviking/storage/observers/usage_observer.pyextendingBaseObserverUsageObserverinobservers/__init__.pyusage()method toObserverServiceindebug_service.py/api/v1/observer/usageendpoint inobserver.pyrouterThe implementation follows the same pattern as
VikingDBObserverandQueueObserver. TheUsageObserverqueriesvikingdb_manager.count()for total vector count and formats the result usingtabulate.Testing
Checklist
Screenshots (if applicable)
Demo
Shows the
/api/v1/observer/usageendpoint returning vector count, the usage component appearing in the system status, and a comparison with the existing vikingdb observer endpoint.Additional Notes
The
UsageObserverreuses the samevikingdb_manager.count()call thatVikingDBObserver._get_collection_statuses()already makes. The difference is framing: VikingDB observer focuses on collection health (index count, error state), while the usage observer focuses on consumption metrics (total vectors). Future extensions could add per-user breakdowns usingRequestContextscoping.This contribution was developed with AI assistance (Claude Code).