Vaultx.Transport.Pool (Vaultx v0.7.0)

View Source

Enterprise-grade connection pool for HashiCorp Vault HTTP transport.

This module provides sophisticated connection pooling functionality optimized for high-throughput Vault operations. It manages connection lifecycle, health monitoring, load balancing, and automatic failover across multiple Vault instances in a cluster.

Enterprise Features

  • Connection Pooling: Efficient HTTP connection reuse and management
  • Health Monitoring: Continuous connection health checks and recovery
  • Load Balancing: Intelligent request distribution across Vault nodes
  • Connection Limits: Configurable pool sizing with overflow protection
  • Timeout Management: Comprehensive timeout handling and recovery
  • Performance Metrics: Detailed pool performance and health metrics
  • Circuit Breaker: Automatic failover for unhealthy connections

Configuration

config :vaultx, :pool,
  size: 10,                     # Base pool size per Vault instance
  max_overflow: 5,              # Additional connections when pool is full
  timeout: 30_000,              # Connection timeout in milliseconds
  max_idle_time: 300_000,       # Maximum idle time before cleanup
  health_check_interval: 60_000 # Health check interval in milliseconds

Usage Examples

# Get a connection from the pool
{:ok, conn} = Vaultx.Transport.Pool.get_connection()

# Return connection to the pool
:ok = Vaultx.Transport.Pool.return_connection(conn)

# Execute request with automatic connection management
{:ok, response} = Vaultx.Transport.Pool.request(:get, "/v1/sys/health", nil, [])

# Get pool statistics
{:ok, stats} = Vaultx.Transport.Pool.stats()

References

Pool Statistics

# Get pool statistics
stats = Vaultx.Transport.Pool.stats()
# Returns: %{
#   total_connections: 10,
#   active_connections: 3,
#   idle_connections: 7,
#   pending_requests: 0,
#   total_requests: 1234,
#   failed_requests: 5
# }

Health Monitoring

The pool automatically monitors connection health by:

  • Sending periodic health check requests
  • Removing connections that fail health checks
  • Tracking connection error rates
  • Implementing circuit breaker patterns for failing endpoints

Summary

Functions

Returns a specification to start this module under a supervisor.

Gets a connection from the pool.

Gets pool health status.

Executes an HTTP request using a pooled connection.

Returns a connection to the pool.

Starts the connection pool.

Gets pool statistics.

Stops the connection pool.

Types

pool_stats()

@type pool_stats() :: %{
  total_connections: non_neg_integer(),
  active_connections: non_neg_integer(),
  idle_connections: non_neg_integer(),
  pending_requests: non_neg_integer(),
  total_requests: non_neg_integer(),
  failed_requests: non_neg_integer()
}

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

get_connection(pool \\ __MODULE__, timeout \\ 5000)

Gets a connection from the pool.

health(pool \\ __MODULE__)

Gets pool health status.

request(method, path, body, headers, opts \\ [])

Executes an HTTP request using a pooled connection.

return_connection(pool \\ __MODULE__, connection)

Returns a connection to the pool.

start_link(opts \\ [])

Starts the connection pool.

stats(pool \\ __MODULE__)

Gets pool statistics.

stop(pool \\ __MODULE__)

Stops the connection pool.