Replace koa-prometheus-exporter with prom-client#79
Merged
Conversation
The @echo-health/koa-prometheus-exporter wrapper hard-pinned prom-client ^10.2.3, which only emits the mean event-loop lag gauge (nodejs_eventloop_lag_seconds) and routed GC through the legacy prometheus-gc-stats package. As a result the perf_hooks-based collectors were missing: event-loop lag percentiles (nodejs_eventloop_lag_p50/p90/p99 _seconds) and the nodejs_gc_duration_seconds histogram, both added in prom-client v12. Drop the wrapper (and its prometheus-gc-stats dependency) and depend on prom-client ^15.1.3 directly. collectDefaultMetrics() is called once at module load, and useObservability() serves /metrics from the default registry. The existing http_requests_total counter (labels method,status) is preserved unchanged; nothing in prom-client's default metrics replaces it. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015kkNPwFkKLCTmbRYerVwSy
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Summary
Replaces the
@echo-health/koa-prometheus-exporterdependency with the standardprom-clientlibrary, implementing a custom metrics endpoint middleware instead of relying on the wrapper package.Changes
@echo-health/koa-prometheus-exporter, addedprom-client(^15.1.3)promClient.collectDefaultMetrics()at module load to collect Node.js runtime metrics (event-loop lag, GC duration, heap usage, etc.)prometheus.middleware({})with a custommetricsEndpointmiddleware that:/metricsContent-Typeheader from the prom-client registrypromClient.register.metrics()const promClient = prometheus.clientassignment and now useprom-clientdirectlyImplementation Details
The custom middleware approach provides more explicit control over the metrics endpoint while maintaining the same functionality. The
collectDefaultMetrics()call is placed at module load inapp-common.js(which is cached) so that in production, where www and download run as separate processes, each process gets its own collector instance.https://claude.ai/code/session_015kkNPwFkKLCTmbRYerVwSy