Skip to content

Add a ?since= timestamp filter to GET /api/v1/metrics/history #147

Description

@Jagadeeshftw

📌 Description

GET /api/v1/metrics/history in routes/metrics.ts returns the entire buffered BoundedHistory (history.all()) with no way to ask for only snapshots since a given point in time, forcing clients that poll infrequently to re-fetch and re-filter the whole (bounded, but potentially still sizeable) history every time.

🧩 Requirements and context

  • Accept an optional ?since= ISO-8601 timestamp query param; return only snapshots with timestamp > since.
  • Invalid (non-parseable) ?since= values return 400.
  • Omitting ?since= preserves current full-history behavior.

🛠️ Suggested execution

  • Modify src/routes/metrics.ts's GET /history handler to parse and validate req.query.since (e.g. via new Date(...) + isNaN check, or a small helper in utils/validation.ts) and filter history.all() accordingly.
  • Update src/openapi.ts's /api/v1/metrics/history entry.
  • Add tests in src/routes/metrics.test.ts for a valid ?since=, an invalid one, and the omitted case.

✅ Acceptance criteria

  • GET /api/v1/metrics/history?since=<iso-timestamp> returns only snapshots after that time.
  • An invalid ?since= value returns 400 with a clear message.
  • Omitting the param returns the full buffered history as before.

🔒 Security notes

N/A — read-only filter over already-exposed metrics history.

📋 Guidelines

  • Minimum 95% test coverage
  • Clear documentation
  • Timeframe: 96 hours

Metadata

Metadata

Assignees

Labels

GrantFox OSSGrantFox open-source programMaybe RewardedGrantFox: potentially rewarded contributionOfficial Campaign | FWC26GrantFox official campaign issueapiHTTP/WebSocket APIenhancementNew feature or improvement

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions