Skip to content

Commit b109334

Browse files
authored
Add connect_timeout: settings to PrometheusExporter::Client (#352)
Fix #335
1 parent 87141bc commit b109334

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

lib/prometheus_exporter/client.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ def initialize(
5656
port: ENV.fetch("PROMETHEUS_EXPORTER_PORT", PrometheusExporter::DEFAULT_PORT),
5757
max_queue_size: nil,
5858
thread_sleep: 0.5,
59+
connect_timeout: nil,
5960
json_serializer: nil,
6061
custom_labels: nil,
6162
logger: Logger.new(STDERR),
@@ -83,6 +84,7 @@ def initialize(
8384
@worker_thread = nil
8485
@mutex = Mutex.new
8586
@thread_sleep = thread_sleep
87+
@connect_timeout = connect_timeout
8688

8789
@json_serializer = json_serializer == :oj ? PrometheusExporter::OjCompat : JSON
8890

@@ -228,7 +230,8 @@ def ensure_socket!
228230

229231
close_socket_if_old!
230232
if !@socket
231-
@socket = TCPSocket.new @host, @port
233+
@socket = TCPSocket.new @host, @port, connect_timeout: @connect_timeout
234+
232235
@socket.write("POST /send-metrics HTTP/1.1\r\n")
233236
@socket.write("Transfer-Encoding: chunked\r\n")
234237
@socket.write("Host: #{@host}\r\n")

0 commit comments

Comments
 (0)