Skip to content

Fix/metrics indexer improvements#456

Open
OxDev-max wants to merge 4 commits into
Vatix-Protocol:mainfrom
OxDev-max:fix/metrics-indexer-improvements
Open

Fix/metrics indexer improvements#456
OxDev-max wants to merge 4 commits into
Vatix-Protocol:mainfrom
OxDev-max:fix/metrics-indexer-improvements

Conversation

@OxDev-max

Copy link
Copy Markdown

Summary

closes #361
closes #362
closes #363
closes #364

  1. Fix false critical indexer lag alerts (indexer-monitor.service.ts)

The computeStatus method was computing lag as latestLedger - 0 whenever no ledger checkpoint existed in Redis (cache miss), producing a lag in the millions and triggering a false critical alert on every cold start. Fixed by tracking whether a checkpoint exists (hasCheckpoint) and short-circuiting to healthy when it doesn't — the indexer simply hasn't started tracking yet.

  1. Expose pool count and swap rate gauges (db-metrics.service.ts, metrics.controller.ts, metrics.module.ts)

Added two new runtime gauges to DbMetricsService:

  • poolCount — set externally via setPoolCount() as pools are created
  • swapRatePerMinute — computed from a rolling 60-second window of swap timestamps recorded via recordSwap()

Both are included in the existing snapshot() response. Wired IndexerMonitorService into MetricsModule and added a new GET /metrics/indexer endpoint (auth-gated with x-internal-key) alongside the existing GET /metrics/db.

  1. E2E swap flow with mocked RPC (swaps.e2e.spec.ts)

Added an end-to-end test suite that spins up a real NestJS application with SwapsController + SwapsService and a mocked SwapsRepository. Tests cover: paginated responses, empty results, pool/wallet filtering, default pagination, feeAmount and transactionHash field mapping, totalPages computation, and error propagation on repository failure.

  1. Indexer worker integration with test DB (indexer.worker.integration.spec.ts)

Added an integration test suite that replaces the flat mock Prisma client with an in-memory store (Maps per table) that actually applies upsert semantics. Tests verify end-to-end data flow for all five event types — pool created, swap processed, fees collected, position minted, position burned — including ledger checkpoint advancement, idempotency, placeholder pool creation on out-of-order swaps, zero-liquidity position closure, and that a failed write never advances the ledger checkpoint prematurely.

Related issue

  • Closes #

Type of change

  • Bug fix
  • New feature
  • Docs update
  • Chore / refactor

Checklist

  • CI passes (lint + tests + build)
  • Self-reviewed the diff
  • Added or updated tests where relevant
  • Docs updated if needed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant