From 853834d778964c86106e90045684e5baaab6b663 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Thu, 21 Aug 2025 15:04:59 +0200 Subject: [PATCH] Add connect_timeout: settings to PrometheusExporter::Client Fix https://github.com/discourse/prometheus_exporter/issues/335 --- lib/prometheus_exporter/client.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/prometheus_exporter/client.rb b/lib/prometheus_exporter/client.rb index a1deada8..310bdb27 100644 --- a/lib/prometheus_exporter/client.rb +++ b/lib/prometheus_exporter/client.rb @@ -56,6 +56,7 @@ def initialize( port: ENV.fetch("PROMETHEUS_EXPORTER_PORT", PrometheusExporter::DEFAULT_PORT), max_queue_size: nil, thread_sleep: 0.5, + connect_timeout: nil, json_serializer: nil, custom_labels: nil, logger: Logger.new(STDERR), @@ -83,6 +84,7 @@ def initialize( @worker_thread = nil @mutex = Mutex.new @thread_sleep = thread_sleep + @connect_timeout = connect_timeout @json_serializer = json_serializer == :oj ? PrometheusExporter::OjCompat : JSON @@ -228,7 +230,8 @@ def ensure_socket! close_socket_if_old! if !@socket - @socket = TCPSocket.new @host, @port + @socket = TCPSocket.new @host, @port, connect_timeout: @connect_timeout + @socket.write("POST /send-metrics HTTP/1.1\r\n") @socket.write("Transfer-Encoding: chunked\r\n") @socket.write("Host: #{@host}\r\n")