Skip to content

feat: expose pg-pool metrics, add indexer-state race guard, add admin rate limiter - #1130

Merged
ogazboiz merged 1 commit into
LabsCrypt:mainfrom
Smartdevs17:fix/admin-metrics-indexer-state-rate-limit
Jul 29, 2026
Merged

feat: expose pg-pool metrics, add indexer-state race guard, add admin rate limiter#1130
ogazboiz merged 1 commit into
LabsCrypt:mainfrom
Smartdevs17:fix/admin-metrics-indexer-state-rate-limit

Conversation

@Smartdevs17

Copy link
Copy Markdown
Contributor

Summary

This PR addresses three assigned issues:

Closes #1023

[Backend] pg-pool.ts does not expose pool metrics (total/idle/waiting) to the admin metrics endpoint

  • Added getPoolMetrics() function in pg-pool.ts to expose totalCount, idleCount, and waitingCount
  • Exported pool instance from prisma.ts
  • Added pgPool section to admin metrics response

Closes #1022

[Backend] indexer-state.ts singleton row has no migration guard against concurrent first-insert race

  • Added ensureIndexerState() function with catch-and-retry pattern for P2002 unique-constraint violations
  • Updated soroban-event-worker.ts to use the new safe initializer
  • Added tests simulating duplicate insert scenarios

Closes #1020

[Backend] admin.routes.ts registers admin endpoints with no route-level rate limiting

  • Created admin-rate-limiter.middleware.ts with 30 requests/minute limit
  • Applied rate limiter to admin router after auth middleware
  • Added test for the rate limiter

Changes

Modified files:

  • backend/src/lib/pg-pool.ts - Added getPoolMetrics() function
  • backend/src/lib/prisma.ts - Exported pool instance and getPoolMetrics
  • backend/src/lib/indexer-state.ts - Added ensureIndexerState() with race condition guard
  • backend/src/routes/v1/admin.routes.ts - Added rate limiter and pool metrics
  • backend/src/workers/soroban-event-worker.ts - Updated to use ensureIndexerState()
  • backend/tests/pg-pool.test.ts - Added test for getPoolMetrics()

New files:

  • backend/src/middleware/admin-rate-limiter.middleware.ts - Admin rate limiter middleware
  • backend/tests/admin-rate-limiter.test.ts - Rate limiter tests
  • backend/tests/indexer-state.test.ts - Indexer state race condition tests

… rate limiter

- Issue LabsCrypt#1023: Expose pg-pool totalCount/idleCount/waitingCount in admin metrics
- Issue LabsCrypt#1022: Add ensureIndexerState with unique-constraint violation guard for concurrent first-insert race
- Issue LabsCrypt#1020: Add rate limiter middleware to admin routes (30 req/min)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants