Skip to content

Implement health check endpoint#28

Merged
Villarley merged 7 commits intoNeko-Protocol:mainfrom
JamesVictor-O:feat/health-check
Jan 31, 2026
Merged

Implement health check endpoint#28
Villarley merged 7 commits intoNeko-Protocol:mainfrom
JamesVictor-O:feat/health-check

Conversation

@JamesVictor-O
Copy link
Contributor

📝 Changes description

Summary

Implements health check endpoints, Prometheus metrics, and monitoring/debug APIs for the aggregator service to support production observability and Kubernetes probes.

Context: Production needs clear visibility into the aggregator’s state. Health checks let Kubernetes determine if the service is healthy; metrics support performance and error analysis.


Closes #22

Health checks (@nestjs/terminus)

Endpoint Purpose
GET /health Full health check. Returns 200 when all configured dependencies are healthy, 503 otherwise.
GET /ready Readiness probe (same checks as /health).
GET /live Liveness probe (process alive, no dependency checks).
GET /status Detailed system info: uptime, memory, dependency check results, version.

Indicators:

  • Redis – When REDIS_URL is set, pings Redis; health fails if unreachable. Skipped if not set.
  • Ingestor – When INGESTOR_URL is set, HTTP GET to INGESTOR_URL/prices/raw; health fails if unreachable or non-2xx. Skipped if not set.

Prometheus metrics

Endpoint Purpose
GET /metrics Prometheus exposition format for scraping.

Registered metrics:

  • aggregator_aggregations_total (by method)
  • aggregator_aggregation_duration_seconds (histogram, by method)
  • aggregator_errors_total (by method)
  • aggregator_aggregations_by_symbol_total (by symbol, method)
  • Default Node.js metrics with aggregator_ prefix

AggregationService records success (count + latency) and errors on each aggregation when MetricsService is injected.


Debug

Endpoint Purpose
GET /debug/prices Last aggregated and normalized prices held in memory (for debugging).

Files changed / added

New:

  • apps/aggregator/src/health/ – Health module, controller, Redis/Ingestor indicators + specs
  • apps/aggregator/src/metrics/ – Metrics module, controller, service + specs
  • apps/aggregator/src/debug/ – Debug module, controller, service + specs

Modified:

  • apps/aggregator/package.json – Dependencies: @nestjs/terminus, @nestjs/axios, @nestjs/config, prom-client, ioredis
  • apps/aggregator/src/app.module.ts – Imports ConfigModule, HealthModule, MetricsModule, DebugModule
  • apps/aggregator/src/services/aggregation.service.ts – Optional MetricsService and DebugService; records metrics and last prices on aggregate()
  • apps/aggregator/README.md – API endpoints table and updated architecture
  • apps/aggregator/.env.exampleREDIS_URL, INGESTOR_URL

Acceptance criteria

  • /health returns 200 when OK, 503 when a configured dependency is down
  • Redis connectivity verified when REDIS_URL is set; health fails if no connection
  • Ingestor connectivity verified when INGESTOR_URL is set; health fails if it doesn’t respond
  • /metrics returns Prometheus format with latency, throughput, and error metrics
  • /ready and /live work for Kubernetes probes
  • /status returns detailed system information
  • Tests for health endpoints; health-related code >80% coverage
  • Endpoints and purpose documented in README

JamesVictor-O and others added 7 commits January 30, 2026 12:53
- @nestjs/terminus, @nestjs/axios, @nestjs/config for health checks
- prom-client for Prometheus metrics
- ioredis for Redis health indicator
- /health: full check (Redis, Ingestor), returns 200 or 503
- /ready: readiness probe for Kubernetes
- /live: liveness probe
- /status: detailed system info (uptime, memory, checks)
- RedisHealthIndicator: ping when REDIS_URL is set
- IngestorHealthIndicator: GET ingestor when INGESTOR_URL is set
- Health controller and module with tests
- /metrics: Prometheus exposition format
- MetricsService: aggregation count, latency histogram, errors, by-symbol
- Default Node.js metrics with aggregator_ prefix
- Metrics controller and service with tests
- /debug/prices: returns last aggregated and normalized prices in memory
- DebugService: in-memory store for last prices per symbol
- Debug controller and service with tests
- AppModule: import ConfigModule, HealthModule, MetricsModule, DebugModule
- AggregationService: optional MetricsService and DebugService injection
- Record aggregation metrics (count, latency, errors) and last prices on aggregate()
- README: API endpoints table (health, ready, live, status, metrics, debug/prices)
- README: update architecture with health, metrics, debug folders
- .env.example: REDIS_URL and INGESTOR_URL for health checks
@JamesVictor-O
Copy link
Contributor Author

@Villarley could you please review my pr

@Villarley Villarley merged commit 12fcce1 into Neko-Protocol:main Jan 31, 2026
1 check failed
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.

Health Checks

2 participants