From c59bd30ac1d5180236b8418c92a36ca8deeee38c Mon Sep 17 00:00:00 2001 From: harshit-splunk Date: Thu, 9 Dec 2021 14:47:03 +0530 Subject: [PATCH] handled exception for post request to hec --- lib/fluent/plugin/out_splunk_hec.rb | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/fluent/plugin/out_splunk_hec.rb b/lib/fluent/plugin/out_splunk_hec.rb index 4dd6707..84a1163 100644 --- a/lib/fluent/plugin/out_splunk_hec.rb +++ b/lib/fluent/plugin/out_splunk_hec.rb @@ -323,10 +323,13 @@ def write_to_splunk(chunk) post.body = chunk.read log.debug { "[Sending] Chunk: #{dump_unique_id_hex(chunk.unique_id)}(#{post.body.bytesize}B)." } log.trace { "POST #{@api} body=#{post.body}" } - - t1 = Time.now - response = @conn.request @api, post - t2 = Time.now + begin + t1 = Time.now + response = @conn.request @api, post + t2 = Time.now + rescue Net::HTTP::Persistent::Error => e + raise e.cause + end raise_err = response.code.to_s.start_with?('5') || (!@consume_chunk_on_4xx_errors && response.code.to_s.start_with?('4'))