Skip to content

feat: admin usage spike endpoint for GrantFox FWC26 campaign#858

Merged
greatest0fallt1me merged 1 commit into
CalloraOrg:mainfrom
israeloluwasegun293-stars:feature/spike
Jul 27, 2026
Merged

feat: admin usage spike endpoint for GrantFox FWC26 campaign#858
greatest0fallt1me merged 1 commit into
CalloraOrg:mainfrom
israeloluwasegun293-stars:feature/spike

Conversation

@israeloluwasegun293-stars

Copy link
Copy Markdown
Contributor

Summary

Implements GET /api/admin/usage/spike endpoint for the GrantFox FWC26 campaign to detect per-API daily usage spikes using z-score analysis.

Close #612

Changes

New Files

  • src/routes/admin/usage/spike.ts — Admin endpoint that queries usage_events for daily per-API aggregates and applies the detectSpikes() algorithm from the existing spike detector service. Returns detected spikes with baseline statistics (mean, stdDev, zScore, percentageChange) and a summary.
  • src/routes/admin/usage/spike.test.ts — 18 tests covering success paths, audit logging, input validation, and error handling.

Modified Files

  • src/validators/admin.ts — Added spikeQuerySchema with Zod validation for from, to, threshold, limit, apiId query params
  • src/app.ts — Imported and mounted createSpikeRouter at /api/admin/usage/spike alongside other admin usage routes
  • src/middleware/errorHandler.ts — Fixed pre-existing duplicate declarations causing a syntax error

API

GET /api/admin/usage/spike?from=ISO8601&to=ISO8601&threshold=3&limit=100&apiId=abc

Response: { data: { spikes: [...], summary: { window, threshold, minDataPoints, seriesAnalyzed, spikeCount } } }

Testing

All 18 new tests pass.

Implements GET /api/admin/usage/spike endpoint for the GrantFox FWC26
campaign to detect per-API daily usage spikes using z-score analysis.

- New spike query schema in validators/admin.ts
- New spike route at src/routes/admin/usage/spike.ts
- Mounted at /api/admin/usage/spike in app.ts
- 18 comprehensive tests covering success, validation, and error cases
- Fixed pre-existing duplicate declarations in errorHandler.ts

Close CalloraOrg#612
@drips-wave

drips-wave Bot commented Jul 27, 2026

Copy link
Copy Markdown

@israeloluwasegun293-stars Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@greatest0fallt1me

Copy link
Copy Markdown
Contributor

Merged via direct push to main (admin)

@greatest0fallt1me
greatest0fallt1me merged commit 2c6cff2 into CalloraOrg:main Jul 27, 2026
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 /api/admin/usage/spike endpoint

2 participants