Skip to content

Conversation

@benoitc
Copy link
Owner

@benoitc benoitc commented Jan 19, 2026

Summary

  • Replace external metrics library with hackney-native metrics abstraction
  • Add pluggable backend system with dummy (default) and Prometheus backends
  • Fix metric types: pool counts now use gauges instead of histograms (Free count hackney pool metric is sending a wrong type #560)
  • Prometheus backend is opt-in, requiring explicit configuration

Changes

  • New files: hackney_metrics_backend.erl (behaviour), hackney_metrics_dummy.erl, hackney_metrics_prometheus.erl
  • Modified: hackney_metrics.erl (API facade), hackney_manager.erl, hackney_pool.erl, hackney_util.erl
  • Removed: metrics dependency from rebar.config and hackney.app.src

New Metrics (Prometheus-compatible names)

Metric Type Labels Description
hackney_requests_total Counter host Total requests started
hackney_requests_active Gauge host Currently active requests
hackney_requests_finished_total Counter host Completed requests
hackney_request_duration_seconds Histogram host Request duration
hackney_pool_free_count Gauge pool Available connections
hackney_pool_in_use_count Gauge pool In-use connections
hackney_pool_checkouts_total Counter pool Total checkouts

Configuration

%% Default: no-op dummy backend (zero overhead)
%% To enable Prometheus metrics:
{hackney, [{metrics_backend, prometheus}]}

Closes #772, closes #560

@benoitc benoitc force-pushed the feat/772-prometheus-metrics branch 3 times, most recently from 5ff03df to 8d375cf Compare January 19, 2026 19:26
Replace external metrics library with hackney-native metrics abstraction:

- Add hackney_metrics_backend behaviour for pluggable backends
- Add hackney_metrics_dummy backend (no-op, default)
- Add hackney_metrics_prometheus backend (opt-in)
- Rewrite hackney_metrics as API facade routing to backends
- Update hackney_manager to use new metrics API (request metrics)
- Update hackney_pool to use new metrics API (pool metrics)
- Remove external metrics library dependency

Metric types fixed (issue #560):
- Pool free_count/in_use_count now use gauges (not histograms)
- Request active count now uses gauge (not counter)

New metric names (Prometheus-compatible):
- hackney_requests_total (counter, labels: host)
- hackney_requests_active (gauge, labels: host)
- hackney_requests_finished_total (counter, labels: host)
- hackney_request_duration_seconds (histogram, labels: host)
- hackney_pool_free_count (gauge, labels: pool)
- hackney_pool_in_use_count (gauge, labels: pool)
- hackney_pool_checkouts_total (counter, labels: pool)

Configuration:
- Default: hackney_metrics_dummy (no-op, zero overhead)
- To enable Prometheus: {hackney, [{metrics_backend, prometheus}]}

Closes #772, closes #560
@benoitc benoitc force-pushed the feat/772-prometheus-metrics branch from 8d375cf to eb693c4 Compare January 19, 2026 19:32
@benoitc benoitc merged commit 2943f4a into master Jan 19, 2026
5 checks passed
@benoitc benoitc deleted the feat/772-prometheus-metrics branch January 19, 2026 19:43
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.

Integrate prometheus metrics in hackney Free count hackney pool metric is sending a wrong type

2 participants