Add since timestamp FIXED - #212
Merged
Merged
Conversation
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.
Title: Add since filtering to metrics history endpoint
Summary:
This pull request adds support for an optional since query parameter on GET /api/v1/metrics/history.
Previously, the endpoint always returned the full bounded metrics history via history.all(), forcing clients to repeatedly fetch and filter the entire buffer. With this change, clients can request only snapshots created after a specific timestamp.
Changes:
Updated src/routes/metrics.ts
Added parsing for req.query.since.
Preserved existing full-history behavior when since is omitted.
Added validation for invalid or repeated since values.
Returns 400 with a clear error message when since is invalid.
Filters snapshots using timestamp > since when a valid timestamp is provided.
Updated src/openapi.ts
Documented the optional since parameter for GET /api/v1/metrics/history.
Added description explaining that since must be an ISO-8601 timestamp and returns only newer snapshots.
Updated src/routes/metrics.test.ts
Added test coverage for omitted since returning full history.
Added test coverage for valid since filtering.
Added test coverage for invalid since returning 400.
Added test coverage for repeated since query params returning 400.
Behavior:
GET /api/v1/metrics/history
Returns the full buffered metrics history as before.
GET /api/v1/metrics/history?since=2026-01-01T00:00:10.000Z
Returns only snapshots with timestamp values strictly after 2026-01-01T00:00:10.000Z.
GET /api/v1/metrics/history?since=not-a-date
Returns 400 with:
"since" must be a valid ISO-8601 timestamp
Validation:
npm test -- --runInBand src/routes/metrics.test.ts
Passed: 9 tests
npm run build
Passed
npm run lint
Passed
npm test -- --runInBand --coverage
Passed: 40 test suites
Passed: 443 tests
Overall statement coverage: 97.14%
src/routes/metrics.ts coverage: 100%
Files modified:
src/routes/metrics.ts
src/routes/metrics.test.ts
src/openapi.ts
Files created:
None
Confidence:
98% confidence. The fix directly addresses the described issue, preserves backward compatibility, updates documentation, and is covered by targeted tests plus the full test/build/lint validation suite.
Closes #147