Add memory consumption telemetry logs#169
Open
arpita-1111 wants to merge 1 commit into
Open
Conversation
- Add src/telemetry.mjs: - computeDatabaseSizeBytes() to measure store size in bytes - logDatabaseSize() to log size + memory count as structured JSON - instrumentQuery() to wrap any query function with duration/result-count logging - Wire logDatabaseSize into createStatsServer so database size is logged on every stats request, with an injectable logger for testability - Add tests for telemetry.mjs and a new createStatsServer logging test
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.
Closes #54
What this PR does
Adds instrumentation logging database size and query metrics, so
resource usage can be monitored over time.
Changes
src/telemetry.mjs:computeDatabaseSizeBytes(memoryStore)— measures store size in byteslogDatabaseSize(memoryStore, logger)— logs size + memory count asstructured JSON (
{ event: "database_size", bytes, memoryCount, timestamp })instrumentQuery(queryFn, logger)— wraps any query function (e.g.retrieveMemories) to log duration and result count without changing
its return value (
{ event: "query_metrics", durationMs, resultCount, timestamp })logDatabaseSizeintocreateStatsServer, so database size islogged on every stats request. The logger is injectable (defaults to
console.log) for testability.
Tests
Added
test/telemetry.test.mjscovering size computation, size logging,empty stores, and query instrumentation (including zero-result queries).
Added a new test in
test/memory-stats.test.mjsconfirming createStatsServerlogs database size on each real HTTP request.