fluent-plugin-syslog-tls-with-backoff-test 2.1.5 → 2.1.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f63360e8ba81c074c2a2e97ba6fc1992c1266a3f343be95e906ca0720c0e50ef
4
- data.tar.gz: 50cd80391373d67d4df98686a15d182eb2706eef8987894356748414f65b6f70
3
+ metadata.gz: f96a93ca908c016557dab784e8df47fe2c0cf2beb1a1f5192f56b061c501dca0
4
+ data.tar.gz: 2f962b941cd83bbda651f5c1e181700fb64b58bb2a2313fa7140fbc2c3d388df
5
5
  SHA512:
6
- metadata.gz: 8bef8e2ced5f69828b8df0e54298e1405c8353d86716277450effb68c52b5e86d8ec2da4a9681a877b196ce15daeffe9fb3cbcfbb747baf807bd5ba975bea4c9
7
- data.tar.gz: 2b75cfea01bd9e1d5e85b609e49de3445d52f27e87977a85602c491179afbe2fea877c4959a124bdf1e14012ba8ebd8599f06f8750ec85754568abc9640e8a71
6
+ metadata.gz: e80612fe421da60837f5965cff62d90072d07e6bb49c31e2ac1a01e6cffe4a81f1fcedd434f020a74ef62ebc5508ccdaa27c017a4f864bbd69c8a9dfdbc5935d
7
+ data.tar.gz: e9c8e3111151bbd44854ea8f953fad481c90af699c5f7992f42a306d11b0455d359a50bbebafa1186c7ba661a9f0a89ebbfb9a332169d7d768b680807d19105c
data/.gitignore CHANGED
@@ -37,3 +37,4 @@ build/
37
37
 
38
38
  ## System
39
39
  .DS_Store
40
+ .vscode
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fluent-plugin-syslog-tls (2.1.0.rc1)
4
+ fluent-plugin-syslog-tls-with-backoff (2.1.0)
5
5
  fluentd (>= 0.14.0, < 2)
6
6
 
7
7
  GEM
@@ -9,35 +9,41 @@ GEM
9
9
  specs:
10
10
  addressable (2.8.1)
11
11
  public_suffix (>= 2.0.2, < 6.0)
12
- concurrent-ruby (1.1.10)
13
- cool.io (1.7.1)
12
+ base64 (0.2.0)
13
+ concurrent-ruby (1.2.3)
14
+ cool.io (1.8.0)
14
15
  crack (0.4.5)
15
16
  rexml
17
+ csv (3.3.0)
16
18
  docile (1.4.0)
17
- fluentd (1.15.3)
19
+ drb (2.2.1)
20
+ fluentd (1.17.0)
21
+ base64 (~> 0.2)
18
22
  bundler
19
23
  cool.io (>= 1.4.5, < 2.0.0)
24
+ csv (~> 3.2)
25
+ drb (~> 2.2)
20
26
  http_parser.rb (>= 0.5.1, < 0.9.0)
21
27
  msgpack (>= 1.3.1, < 2.0.0)
22
- serverengine (>= 2.3.0, < 3.0.0)
23
- sigdump (~> 0.2.2)
28
+ serverengine (>= 2.3.2, < 3.0.0)
29
+ sigdump (~> 0.2.5)
24
30
  strptime (>= 0.2.4, < 1.0.0)
25
31
  tzinfo (>= 1.0, < 3.0)
26
32
  tzinfo-data (~> 1.0)
27
- webrick (>= 1.4.2, < 1.8.0)
33
+ webrick (~> 1.4)
28
34
  yajl-ruby (~> 1.0)
29
35
  hashdiff (1.0.1)
30
36
  http_parser.rb (0.8.0)
31
37
  minitest (5.17.0)
32
38
  minitest-stub_any_instance (1.0.3)
33
- msgpack (1.6.0)
39
+ msgpack (1.7.2)
34
40
  power_assert (2.0.3)
35
41
  public_suffix (5.0.1)
36
42
  rake (13.0.6)
37
43
  rexml (3.2.5)
38
- serverengine (2.3.1)
44
+ serverengine (2.3.2)
39
45
  sigdump (~> 0.2.2)
40
- sigdump (0.2.4)
46
+ sigdump (0.2.5)
41
47
  simplecov (0.22.0)
42
48
  docile (~> 1.1)
43
49
  simplecov-html (~> 0.11)
@@ -47,22 +53,22 @@ GEM
47
53
  strptime (0.2.5)
48
54
  test-unit (3.5.7)
49
55
  power_assert
50
- tzinfo (2.0.5)
56
+ tzinfo (2.0.6)
51
57
  concurrent-ruby (~> 1.0)
52
- tzinfo-data (1.2022.7)
58
+ tzinfo-data (1.2024.1)
53
59
  tzinfo (>= 1.0.0)
54
60
  webmock (3.18.1)
55
61
  addressable (>= 2.8.0)
56
62
  crack (>= 0.3.2)
57
63
  hashdiff (>= 0.4.0, < 2.0.0)
58
- webrick (1.7.0)
64
+ webrick (1.8.1)
59
65
  yajl-ruby (1.4.3)
60
66
 
61
67
  PLATFORMS
62
68
  ruby
63
69
 
64
70
  DEPENDENCIES
65
- fluent-plugin-syslog-tls!
71
+ fluent-plugin-syslog-tls-with-backoff!
66
72
  minitest (~> 5.8)
67
73
  minitest-stub_any_instance (~> 1.0.0)
68
74
  rake
@@ -20,11 +20,11 @@ require 'syslog_tls/version'
20
20
  Gem::Specification.new do |s|
21
21
  s.name = 'fluent-plugin-syslog-tls-with-backoff-test'
22
22
  s.version = SyslogTls::VERSION
23
- s.authors = ['thomas morgan']
24
- s.email = ['tm@iprog.com']
23
+ s.authors = ['thomas morgan', 'muhammad adil ghaffar']
24
+ s.email = ['tm@iprog.com', 'muhammad.sdil.ghaffar@est.tech']
25
25
  s.summary = %q{Fluent Syslog TLS output plugin}
26
- s.description = %q{Syslog TLS output plugin with formatting support, for Fluentd}
27
- s.homepage = 'https://github.com/zarqman/fluent-plugin-syslog-tls'
26
+ s.description = %q{Syslog TLS output plugin with formatting support, for Fluentd. This is cutom version backoff.}
27
+ s.homepage = 'https://github.com/Nordix/fluent-plugin-syslog-tls/tree/add-expo-backoff/adil'
28
28
  s.license = 'Apache v2'
29
29
  s.files = `git ls-files`.split($/)
30
30
  s.executables = s.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
@@ -16,6 +16,70 @@
16
16
  require 'socket'
17
17
  require 'syslog_tls/logger'
18
18
  require 'fluent/plugin/output'
19
+ require 'syslog_tls/host_backoff_specs'
20
+ require 'pp'
21
+
22
+ $host_backoff_specs_list = []
23
+
24
+ def add_host_backoff_spec(retries_to_do, host_ip_port)
25
+ # Check if an element with the same hostIPport already exists
26
+ return if $host_backoff_specs_list.any? { |spec| spec.hostIPport == host_ip_port }
27
+
28
+ # If not, add a new HostBackoffSpecs instance to the global array
29
+ $host_backoff_specs_list << ::SyslogTls::HostBackoffSpecs.new(retries_to_do, host_ip_port)
30
+ end
31
+
32
+ def can_write(host_ip_port)
33
+ if !conatins_host(host_ip_port)
34
+ add_host_backoff_spec(0, host_ip_port)
35
+ end
36
+ begin
37
+ $host_backoff_specs_list.each do |backoff_specs|
38
+ if backoff_specs.hostIPport == host_ip_port
39
+ return backoff_specs.canwrite
40
+ end
41
+ end
42
+ rescue => e
43
+ pp "Error in can_write: #{e.message}"
44
+ return 0
45
+ end
46
+ return 1
47
+ end
48
+
49
+ def increase_retry(host_ip_port)
50
+ if !conatins_host(host_ip_port)
51
+ add_host_backoff_spec(0, host_ip_port)
52
+ end
53
+ begin
54
+ $host_backoff_specs_list.each do |backoff_specs|
55
+ if backoff_specs.hostIPport == host_ip_port
56
+ backoff_specs.failtowrite
57
+ end
58
+ end
59
+ rescue => e
60
+ pp "Error in increase_retry: #{e.message}"
61
+ end
62
+ end
63
+
64
+ def reset_tries(host_ip_port)
65
+ if !conatins_host(host_ip_port)
66
+ add_host_backoff_spec(0, host_ip_port)
67
+ end
68
+ $host_backoff_specs_list.each do |backoff_specs|
69
+ if backoff_specs.hostIPport == host_ip_port
70
+ backoff_specs.resetRetries
71
+ end
72
+ end
73
+ end
74
+
75
+ def conatins_host(host_ip_port)
76
+ $host_backoff_specs_list.each do |backoff_specs|
77
+ if backoff_specs.hostIPport == host_ip_port
78
+ return true
79
+ end
80
+ end
81
+ return false
82
+ end
19
83
 
20
84
  module Fluent::Plugin
21
85
  class SyslogTlsOutput < Output
@@ -82,6 +146,8 @@ module Fluent::Plugin
82
146
  @mappings[key_name] = conf[conf_key] if conf.key?(conf_key)
83
147
  end
84
148
 
149
+ add_host_backoff_spec(0, conf['host']+":"+conf['port'])
150
+
85
151
  @formatter = formatter_create(conf: conf.elements('format').first, default_type: DEFAULT_FORMAT_TYPE)
86
152
  end
87
153
 
@@ -0,0 +1,48 @@
1
+ require 'pp'
2
+
3
+ module SyslogTls
4
+ class HostBackoffSpecs
5
+ attr_accessor :retriesToDo, :hostIPport
6
+
7
+ def initialize(retries_to_do, host_ip_port)
8
+ @retriesToDo = retries_to_do
9
+ @hostIPport = host_ip_port
10
+ @failTime = nil
11
+ @baseThreshold = 2
12
+ end
13
+
14
+ def canwrite
15
+ time_passed_since_failure = -1
16
+ if @failTime != nil
17
+ pp "canwrite :: @failTime != nil :: retriesToDo :: " + @retriesToDo.to_s + " failTime :: " + @failTime.to_s
18
+ time_passed_since_failure = Time.now - @failTime
19
+ time_passed_since_failure = time_passed_since_failure.round(2)
20
+ end
21
+ if time_passed_since_failure == -1
22
+ return 1
23
+ end
24
+ backoffTime = @baseThreshold ** @retriesToDo
25
+ if backoffTime > 1800
26
+ backoffTime = 1800
27
+ end
28
+ if time_passed_since_failure > backoffTime
29
+ pp "canwrite writting after backoff :: time_passed_since_failure" + time_passed_since_failure.to_s + " time :: " + Time.now.to_s
30
+ return 1
31
+ else
32
+ return 0
33
+ end
34
+ end
35
+
36
+ def failtowrite
37
+ @retriesToDo += 1
38
+ @failTime = Time.now
39
+ pp "failtowrite :: retriesToDo :: " + @retriesToDo.to_s + " failTime :: " + Time.now.to_s
40
+ end
41
+
42
+ def resetRetries
43
+ @retriesToDo = 0
44
+ @failTime = nil
45
+ pp "resetRetries :: retriesToDo :: " + @retriesToDo.to_s + " failTime :: " + @failTime.to_s
46
+ end
47
+ end
48
+ end
@@ -15,6 +15,7 @@
15
15
 
16
16
  require 'socket'
17
17
  require 'openssl'
18
+ require 'pp'
18
19
 
19
20
  module SyslogTls
20
21
  # Supports SSL connection to remote host
@@ -43,6 +44,7 @@ module SyslogTls
43
44
  end
44
45
 
45
46
  def connect
47
+ timwnow = Time.now
46
48
  @socket = get_ssl_connection
47
49
  begin
48
50
  begin
@@ -50,6 +52,7 @@ module SyslogTls
50
52
  rescue Errno::EAGAIN, Errno::EWOULDBLOCK, IO::WaitReadable
51
53
  select_with_timeout(@socket, :connect_read) && retry
52
54
  rescue IO::WaitWritable
55
+ pp "connect :: select_with_timeout(@socket, :connect_write) && retry time :: " + Time.now.to_s
53
56
  select_with_timeout(@socket, :connect_write) && retry
54
57
  end
55
58
  rescue Errno::ETIMEDOUT
@@ -73,6 +76,7 @@ module SyslogTls
73
76
  tcp.setsockopt(Socket::SOL_SOCKET, Socket::Constants::SO_REUSEPORT, true)
74
77
  tcp.connect_nonblock(sock_addr)
75
78
  rescue Errno::EINPROGRESS
79
+ pp "get_tcp_connection :: select_with_timeout(tcp, :connect_write) time :: " + Time.now.to_s
76
80
  select_with_timeout(tcp, :connect_write)
77
81
  begin
78
82
  tcp.connect_nonblock(sock_addr)
@@ -156,6 +160,7 @@ module SyslogTls
156
160
  if e.is_a?(OpenSSL::SSL::SSLError) && e.message !~ /write would block/
157
161
  raise e
158
162
  else
163
+ pp "do_write :: select_with_timeout(@socket, :write) time :: " + Time.now.to_s
159
164
  select_with_timeout(@socket, :write) && retry
160
165
  end
161
166
  end
@@ -166,6 +171,9 @@ module SyslogTls
166
171
  end
167
172
 
168
173
  def select_with_timeout(tcp, type)
174
+ host_ip_port = host + ":" + port.to_s
175
+ pp "select_with_timeout :: time :: " + Time.now.to_s + " :: host_ip_port :: " + host_ip_port
176
+ pp "select_with_timeout :: type :: " + type.to_s
169
177
  case type
170
178
  when :connect_read
171
179
  args = [[tcp], nil, nil, CONNECT_TIMEOUT]
@@ -178,7 +186,25 @@ module SyslogTls
178
186
  else
179
187
  raise "Unknown select type #{type}"
180
188
  end
181
- IO.select(*args) || raise("Socket timeout during #{type}")
189
+ if type.to_s == "connect_write" || type.to_s == "connect_read"
190
+ pp "select_with_timeout :: if :: time :: " + Time.now.to_s + " :: host_ip_port :: " + host_ip_port
191
+ if can_write(host_ip_port) == 1
192
+ io_select_return = IO.select(*args)
193
+ ready_sockets, _, _ = io_select_return
194
+ if !ready_sockets.empty?
195
+ reset_tries(host_ip_port)
196
+ io_select_return
197
+ else
198
+ increase_retry(host_ip_port)
199
+ io_select_return || raise("Socket timeout during #{type}")
200
+ end
201
+ # else
202
+ # raise("Failed to write #{type}")
203
+ end
204
+ else
205
+ pp "select_with_timeout :: else :: time :: " + Time.now.to_s + " :: host_ip_port :: " + host_ip_port
206
+ IO.select(*args) || raise("Socket timeout during #{type}")
207
+ end
182
208
  end
183
209
 
184
210
  # Forward any methods directly to SSLSocket
@@ -14,5 +14,5 @@
14
14
  # limitations under the License.
15
15
 
16
16
  module SyslogTls
17
- VERSION = '2.1.5'
17
+ VERSION = '2.1.7'
18
18
  end
metadata CHANGED
@@ -1,14 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-syslog-tls-with-backoff-test
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.5
4
+ version: 2.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - thomas morgan
8
+ - muhammad adil ghaffar
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2024-05-20 00:00:00.000000000 Z
12
+ date: 2024-05-21 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: fluentd
@@ -114,9 +115,11 @@ dependencies:
114
115
  - - "~>"
115
116
  - !ruby/object:Gem::Version
116
117
  version: '0.11'
117
- description: Syslog TLS output plugin with formatting support, for Fluentd
118
+ description: Syslog TLS output plugin with formatting support, for Fluentd. This is
119
+ cutom version backoff.
118
120
  email:
119
121
  - tm@iprog.com
122
+ - muhammad.sdil.ghaffar@est.tech
120
123
  executables: []
121
124
  extensions: []
122
125
  extra_rdoc_files: []
@@ -134,6 +137,7 @@ files:
134
137
  - fluent-plugin-syslog-tls.gemspec
135
138
  - lib/fluent/plugin/out_syslog_tls.rb
136
139
  - lib/syslog_tls/facility.rb
140
+ - lib/syslog_tls/host_backoff_specs.rb
137
141
  - lib/syslog_tls/logger.rb
138
142
  - lib/syslog_tls/lookup_from_const.rb
139
143
  - lib/syslog_tls/protocol.rb
@@ -146,7 +150,7 @@ files:
146
150
  - test/syslog_tls/test_logger.rb
147
151
  - test/syslog_tls/test_protocol.rb
148
152
  - test/syslog_tls/test_ssl_transport.rb
149
- homepage: https://github.com/zarqman/fluent-plugin-syslog-tls
153
+ homepage: https://github.com/Nordix/fluent-plugin-syslog-tls/tree/add-expo-backoff/adil
150
154
  licenses:
151
155
  - Apache v2
152
156
  metadata: {}