Skip to content

Add since timestamp FIXED - #212

Merged
Jagadeeshftw merged 1 commit into
AnchorNet-Org:mainfrom
Mitch5000:Add-a-since-timestamp
Jul 27, 2026
Merged

Add since timestamp FIXED#212
Jagadeeshftw merged 1 commit into
AnchorNet-Org:mainfrom
Mitch5000:Add-a-since-timestamp

Conversation

@Mitch5000

Copy link
Copy Markdown
Contributor

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

@Jagadeeshftw
Jagadeeshftw merged commit 20afddf into AnchorNet-Org:main Jul 27, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants