Skip to content

Feed Generator Service - Metrics/Logging #95

Description

@Ashex

Service needs structured logging, Prometheus metrics, robust graceful shutdown, request-ID tracing, and a soak test to confirm no FD leaks or unbounded memory growth.

Metrics to expose (/metrics)

Metric Labels
feedgen_requests_total endpoint, status
feedgen_request_duration_seconds endpoint
feedgen_subscriptions_open kind="service"|"actor"
feedgen_subscription_reconnects_total kind, did (optional)
feedgen_index_posts_total
feedgen_blob_cache_hits_total / _misses_total
feedgen_boundary_cache_hits_total / _misses_total

To-do

  • Add src/logger.tspino logger with Stratos service conventions
  • Add request-ID middleware (src/middleware/request-id.ts): accept X-Request-Id or generate UUID; attach to AsyncLocalStorage
  • Instrument all request handlers to log {requestId, viewerDid?, endpoint, durationMs, status}
  • Add src/metrics.ts — Prometheus-format counter/histogram helpers; register all metrics above
  • Expose /metrics endpoint
  • Add src/lifecycle/shutdown.ts — SIGTERM/SIGINT handler: stop accepting connections → drain in-flight (15 s timeout) → flush actor cursors → close DB
  • Enrich /health to return {ok, version, serviceStreamConnected, actorPoolSize}
  • Add panic handler: catch unhandled promise rejections + exceptions; log and exit with code 1
  • Add tests/shutdown.test.ts and tests/metrics.test.ts
  • Soak test (can be a manual step documented in PR): 50 req/s against in-memory data for 5 min; record RSS and FD count before/after

Acceptance criteria

  • Every completed request log line includes requestId, viewerDid (where available), and durationMs
  • /metrics output passes promtool check metrics or equivalent programmatic validation (test)
  • SIGTERM: open requests complete (up to 15 s), actor cursors flushed, DB closed cleanly (integration test)
  • /health reflects actual subscription state (serviceStreamConnected, actorPoolSize)
  • Handler-level error produces HTTP 500 + logged error; process does not exit (test)
  • Soak test shows RSS growth < 50 MB and zero FD leak over 5 min

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions