feat: Design metrics data model and storage schema#3
Open
charliewwdev wants to merge 6 commits intomainfrom
Open
feat: Design metrics data model and storage schema#3charliewwdev wants to merge 6 commits intomainfrom
charliewwdev wants to merge 6 commits intomainfrom
Conversation
…s/ring-buffer.test.ts
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.
Define the schema for metric samples (metric_name, value, unit, timestamp, labels). Choose a time-series-friendly storage strategy (e.g. InfluxDB, TimescaleDB, or in-memory ring buffer for MVP).
Generated by OpenDev AI
Storage strategy: in-memory ring buffer (MVP)
Chose a fixed-capacity ring buffer over InfluxDB/TimescaleDB because the agent-runtime has no time-series infrastructure dependency and the volume at MVP scale fits in memory. The MetricStore interface is deliberately narrow so a TimescaleDB or InfluxDB adapter can be swapped behind the same API later.
Schema
metric_name— dot-separated hierarchical name (e.g.agent.task.duration_ms)value—number, validated finite (no NaN/Infinity)unit— closed enum via Zod; forces callers to pick from well-known units so dashboards can render correctly without guessingtimestamp—Date, defaults toDate.now()on record() so callers rarely need to supply itlabels— flatRecord<string,string>, Prometheus-style; enables slicing byagent_type,workspace_id,environment, etc.Ring buffer
MetricStore
record()— validates input with Zod then pushes to bufferquery()— filter by name, time range, labels; returns newest-firstaggregate()— avg/min/max/sum/count/p95/p99 over a filtered windowTests cover ring buffer wraparound, overwrite behaviour, all query filters, all aggregate functions including percentiles, and Zod validation rejection.