loggability 0.17.0 → 0.18.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 657ddfb25b87eccec0c814690fcc32056a5f0864d8e662f313b50a98cc44342e
4
- data.tar.gz: 0653afb117c71ef19153a1f4f2440436ad427c6b74c64d1d7d1d0edb2cde5b0b
3
+ metadata.gz: 1b2c4fcb2846387b2e46bb742c60358c79cad2569644325e3db8995bfc4f1367
4
+ data.tar.gz: 8ee45fa6eaf6cfea8d84d8410877bd90053d71a4d692f0a391209d14702430d7
5
5
  SHA512:
6
- metadata.gz: 10c6bc903e01021b38fcdabe55081e09c693ce54ebe388aef44752a17fec3e4e86a34d1bc40e7ae4c634f3d2a2ebf8c1be8e1813bdf9236b6eb29a6b5d50405e
7
- data.tar.gz: 642857455ee0f09e90278308c9fe3da3c19e07dbe0e9a9a4ad30671075d71bfdc292a23df2dc2cc2a2c22f0cc452283216f14beac16deb4fe8ee76a95938df80
6
+ metadata.gz: bcc3cc14f69340ca900ccd458c57e6a85d1b6b895614843ca9427e061f43320ccc7149034091afb0c4ff2bf3ada6a6dcbd05e4f94432224e3bd38b0a6ad1c6b1
7
+ data.tar.gz: c451e216cd87c63794169f0932650f34f78ae99a0eda842497fbef91df1eaf2564500a6160bdf10eb73f81d900cb320f81d4f207e03f0360c8b3df98a92345cb
checksums.yaml.gz.sig CHANGED
Binary file
data/History.rdoc CHANGED
@@ -2,6 +2,31 @@
2
2
 
3
3
  ---
4
4
 
5
+ == v0.18.2 [2020-12-28] Michael Granger <ged@faeriemud.org>
6
+
7
+ Improvements:
8
+
9
+ - Make the version spec even less specific.
10
+
11
+
12
+ == v0.18.1 [2020-12-28] Michael Granger <ged@faeriemud.org>
13
+
14
+ Improvements:
15
+
16
+ - Change version spec to work with Ruby 3 versions.
17
+
18
+
19
+ == v0.18.0 [2020-12-24] Michael Granger <ged@faeriemud.org>
20
+
21
+ Improvements:
22
+
23
+ - Add memory management to the http log device
24
+ - Add a dead-simple log server example
25
+ - Update for Ruby 3, add my updated gem cert
26
+
27
+ Thanks again to Mahmood Khan <mkhan1484@gmail.com> for the patch.
28
+
29
+
5
30
  == v0.17.0 [2020-02-27] Michael Granger <ged@faeriemud.org>
6
31
 
7
32
  Bugfixes:
data/Rakefile CHANGED
@@ -3,7 +3,7 @@
3
3
  require 'rake/deveiate'
4
4
 
5
5
  Rake::DevEiate.setup( 'loggability' ) do |project|
6
- project.required_ruby_version = '~> 2.5'
6
+ project.required_ruby_version = ['>= 2.5']
7
7
  project.publish_to = 'deveiate:/usr/local/www/public/code'
8
8
  end
9
9
 
@@ -33,6 +33,9 @@ class Loggability::LogDevice::Http < Loggability::LogDevice
33
33
  # The default Executor class to use for asynchronous tasks
34
34
  DEFAULT_EXECUTOR_CLASS = Concurrent::SingleThreadExecutor
35
35
 
36
+ # The default for the maximum bytesize of the queue (1 GB)
37
+ DEFAULT_MAX_QUEUE_BYTESIZE = ( 2 ** 10 ) * ( 2 ** 10 ) * ( 2 ** 10 )
38
+
36
39
  # The default options for new instances
37
40
  DEFAULT_OPTIONS = {
38
41
  execution_interval: DEFAULT_BATCH_INTERVAL,
@@ -69,6 +72,8 @@ class Loggability::LogDevice::Http < Loggability::LogDevice
69
72
  @endpoint = URI( endpoint ).freeze
70
73
  @logs_queue = Queue.new
71
74
 
75
+ @logs_queue_bytesize = 0
76
+ @max_queue_bytesize = opts[:max_queue_bytesize] || DEFAULT_MAX_QUEUE_BYTESIZE
72
77
  @batch_interval = opts[:batch_interval] || DEFAULT_BATCH_INTERVAL
73
78
  @write_timeout = opts[:write_timeout] || DEFAULT_WRITE_TIMEOUT
74
79
  @max_batch_size = opts[:max_batch_size] || DEFAULT_MAX_BATCH_SIZE
@@ -97,6 +102,14 @@ class Loggability::LogDevice::Http < Loggability::LogDevice
97
102
  # logging service.
98
103
  attr_reader :logs_queue
99
104
 
105
+ ##
106
+ # The max bytesize of the queue. Will not queue more messages if this threshold is hit
107
+ attr_reader :max_queue_bytesize
108
+
109
+ ##
110
+ # The size of +logs_queue+ in bytes
111
+ attr_accessor :logs_queue_bytesize
112
+
100
113
  ##
101
114
  # The monotonic clock time when the last batch of logs were sent
102
115
  attr_accessor :last_send_time
@@ -133,6 +146,13 @@ class Loggability::LogDevice::Http < Loggability::LogDevice
133
146
  ### LogDevice API -- write a message to the HTTP device.
134
147
  def write( message )
135
148
  self.start unless self.running?
149
+ if message.is_a?( Hash )
150
+ message_size = message.to_json.bytesize
151
+ else
152
+ message_size = message.bytesize
153
+ end
154
+ return if ( self.logs_queue_bytesize + message_size ) >= self.max_queue_bytesize
155
+ self.logs_queue_bytesize += message_size
136
156
  self.logs_queue.enq( message )
137
157
  self.send_logs
138
158
  end
@@ -246,7 +266,9 @@ class Loggability::LogDevice::Http < Loggability::LogDevice
246
266
  max_size = self.max_batch_bytesize - self.max_message_bytesize - 2 # for the outer Array
247
267
 
248
268
  while count < self.max_batch_size && bytes < max_size && !self.logs_queue.empty?
249
- formatted_message = self.format_log_message( self.logs_queue.deq )
269
+ message = self.logs_queue.deq
270
+ formatted_message = self.format_log_message( message )
271
+ self.logs_queue_bytesize -= message.bytesize
250
272
 
251
273
  count += 1
252
274
  bytes += formatted_message.bytesize + 3 # comma and delimiters
@@ -38,9 +38,9 @@ class Loggability::LogDevice
38
38
  ### * "data_dog_api_key" is the argument that will be passed onto the datadog
39
39
  ### log device's constructor
40
40
  def self::parse_device_spec( target_spec )
41
- targets = target_spec.split( ':' ).compact
41
+ targets = target_spec.split( ';' ).compact
42
42
  return targets.map do |t|
43
- target_subclass = t[ DEVICE_TARGET_REGEX, 1 ]&.strip().to_sym
43
+ target_subclass = t[ DEVICE_TARGET_REGEX, 1 ]&.strip.to_sym
44
44
  target_subclass_args = t[ DEVICE_TARGET_REGEX, 2 ]
45
45
 
46
46
  self.create( target_subclass, target_subclass_args )
data/lib/loggability.rb CHANGED
@@ -9,7 +9,7 @@ require 'date'
9
9
  module Loggability
10
10
 
11
11
  # Package version constant
12
- VERSION = '0.17.0'
12
+ VERSION = '0.18.2'
13
13
 
14
14
  # The key for the global logger (Loggability's own logger)
15
15
  GLOBAL_KEY = :__global__
@@ -166,4 +166,52 @@ describe Loggability::LogDevice::Http do
166
166
  expect( http.verify_mode ).to eq( OpenSSL::SSL::VERIFY_PEER )
167
167
  end
168
168
 
169
+
170
+ it "stops queuing more messages if max queue size is reached" do
171
+ device = described_class.new(
172
+ max_batch_bytesize: 1024,
173
+ batch_interval: 100,
174
+ max_queue_bytesize: 100,
175
+ executor_class: Concurrent::ImmediateExecutor )
176
+ device.instance_variable_set( :@http_client, http_client )
177
+
178
+ expect( device ).to receive( :send_logs ).at_least( :once )
179
+
180
+ msg = "test message"
181
+ device.write(msg)
182
+ expect( device.logs_queue_bytesize == msg.bytesize )
183
+
184
+ hash_msg = { message: "This is a test log message", tags: ["tag1", "tag2"] }
185
+ device.write( hash_msg )
186
+ previous_bytesize = device.logs_queue_bytesize - hash_msg.to_json.bytesize
187
+ expect( device.logs_queue_bytesize ).to eq( hash_msg.to_json.bytesize + previous_bytesize )
188
+
189
+ queue_current_bytesize = device.logs_queue_bytesize
190
+ hash_msg = { message: "This is a test log message", tags: ["tag1", "tag2"] }
191
+ device.write( hash_msg )
192
+ expect( device.logs_queue_bytesize ).to eq( queue_current_bytesize )
193
+ end
194
+
195
+
196
+ it "reduces the queue bytesize once messages are sent" do
197
+ device = described_class.new(
198
+ max_batch_bytesize: 1024,
199
+ batch_interval: 100,
200
+ max_queue_bytesize: 100,
201
+ executor_class: Concurrent::ImmediateExecutor )
202
+ device.instance_variable_set( :@http_client, http_client )
203
+
204
+ expect( device ).to receive( :send_logs ).at_least( :once )
205
+ msg = "test message"
206
+ device.write(msg)
207
+ expect( device.logs_queue_bytesize == msg.bytesize )
208
+
209
+ msg = "this is just a test message"
210
+ device.write( msg )
211
+ previous_bytesize = device.logs_queue_bytesize - msg.bytesize
212
+ expect( device.logs_queue_bytesize ).to eq( msg.bytesize + previous_bytesize )
213
+
214
+ expect { device.get_next_log_payload }.to change { device.logs_queue_bytesize }.to( 0 )
215
+ end
216
+
169
217
  end
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,18 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: loggability
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.17.0
4
+ version: 0.18.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Granger
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain:
11
11
  - |
12
12
  -----BEGIN CERTIFICATE-----
13
- MIIENDCCApygAwIBAgIBATANBgkqhkiG9w0BAQsFADAiMSAwHgYDVQQDDBdnZWQv
14
- REM9RmFlcmllTVVEL0RDPW9yZzAeFw0xOTEwMDkwMDM2NTdaFw0yMDEwMDgwMDM2
15
- NTdaMCIxIDAeBgNVBAMMF2dlZC9EQz1GYWVyaWVNVUQvREM9b3JnMIIBojANBgkq
13
+ MIID+DCCAmCgAwIBAgIBAzANBgkqhkiG9w0BAQsFADAiMSAwHgYDVQQDDBdnZWQv
14
+ REM9RmFlcmllTVVEL0RDPW9yZzAeFw0yMDEyMjQyMDU1MjlaFw0yMTEyMjQyMDU1
15
+ MjlaMCIxIDAeBgNVBAMMF2dlZC9EQz1GYWVyaWVNVUQvREM9b3JnMIIBojANBgkq
16
16
  hkiG9w0BAQEFAAOCAY8AMIIBigKCAYEAvyVhkRzvlEs0fe7145BYLfN6njX9ih5H
17
17
  L60U0p0euIurpv84op9CNKF9tx+1WKwyQvQP7qFGuZxkSUuWcP/sFhDXL1lWUuIl
18
18
  M4uHbGCRmOshDrF4dgnBeOvkHr1fIhPlJm5FO+Vew8tSQmlDsosxLUx+VB7DrVFO
@@ -21,20 +21,19 @@ cert_chain:
21
21
  vQ66lts4alKC69TE5cuKasWBm+16A4aEe3XdZBRNmtOu/g81gvwA7fkJHKllJuaI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26
+ 9w0BAQsFAAOCAYEAMYegZanJi8zq7QKPT7wqXefX4C88I5JWeBHR3PvvWK0CwyMV
27
+ peyiu5I13w/lYX+HUZjE4qsSpJMJFXWl4WZCOo+AMprOcf0PxfuJpxCej5D4tavf
28
+ vRfhahSw7XJrcZih/3J+/UgoH7R05MJ+8LTcy3HGrB3a0vTafjm8OY7Xpa0LJDoN
29
+ JDqxK321VIHyTibbKeA1hWSE6ljlQDvFbTqiCj3Ulp1jTv3TOlvRl8fqcfhxUJI0
30
+ +5Q82jJODjEN+GaWs0V+NlrbU94cXwS2PH5dXogftB5YYA5Ex8A0ikZ73xns4Hdo
31
+ XxdLdd92F5ovxA23j/rKe/IDwqr6FpDkU3nPXH/Qp0TVGv9zZnVJc/Z6ChkuWj8z
32
+ pW7JAyyiiHZgKKDReDrA2LA7Zs3o/7KA6UtUH0FHf8LYhcK+pfHk6RtjRe65ffw+
33
+ MCh97sQ/Z/MOusb5+QddBmB+k8EicXyGNl4b5L4XpL7fIQu+Y96TB3JEJlShxFD9
34
+ k9FjI4d9EP54gS/4
36
35
  -----END CERTIFICATE-----
37
- date: 2020-02-27 00:00:00.000000000 Z
36
+ date: 2020-12-28 00:00:00.000000000 Z
38
37
  dependencies:
39
38
  - !ruby/object:Gem::Dependency
40
39
  name: rake-deveiate
@@ -167,14 +166,19 @@ files:
167
166
  homepage: https://hg.sr.ht/~ged/Loggability
168
167
  licenses:
169
168
  - BSD-3-Clause
170
- metadata: {}
171
- post_install_message:
169
+ metadata:
170
+ homepage_uri: https://hg.sr.ht/~ged/Loggability
171
+ documentation_uri: https://deveiate.org/code/loggability
172
+ changelog_uri: https://deveiate.org/code/loggability/History_md.html
173
+ source_uri: https://hg.sr.ht/~ged/Loggability/browse
174
+ bug_tracker_uri: https://todo.sr.ht/~ged/Loggability/browse
175
+ post_install_message:
172
176
  rdoc_options: []
173
177
  require_paths:
174
178
  - lib
175
179
  required_ruby_version: !ruby/object:Gem::Requirement
176
180
  requirements:
177
- - - "~>"
181
+ - - ">="
178
182
  - !ruby/object:Gem::Version
179
183
  version: '2.5'
180
184
  required_rubygems_version: !ruby/object:Gem::Requirement
@@ -183,8 +187,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
183
187
  - !ruby/object:Gem::Version
184
188
  version: '0'
185
189
  requirements: []
186
- rubygems_version: 3.1.2
187
- signing_key:
190
+ rubygems_version: 3.2.3
191
+ signing_key:
188
192
  specification_version: 4
189
193
  summary: A composable logging system built on the standard Logger library.
190
194
  test_files: []
metadata.gz.sig CHANGED
Binary file