fluent-plugin-fluent-plugin-json-size-limit 0.1.30 → 0.1.31

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: 73d82be0721ff66686b415ed8264f699b7ec5943c343442246591d7ffff2a691
4
- data.tar.gz: 0c7373794b14bb31a8378a5095959f29baba102a28c7060d5b5dbc59e62a48ee
3
+ metadata.gz: 05e23baa812f5f389f8632c11f7793ce3bbeb9fb147d2f59f581d12a7d360d15
4
+ data.tar.gz: 8aea346b7c77227efff34fc70917f714ab7201268916bbdfe9ea5c92b64caf74
5
5
  SHA512:
6
- metadata.gz: 2e59c251899fdc1172ab144af0cc4d5aaa53b1c667d0b2ed7f22cbdf11d1b3f02992ce6e930ac604c8418108b5eec77502aee1272ab2261cf475769e19e7f635
7
- data.tar.gz: e05efd4111d3a46ac60bd2b0b856359b408b98b1daf7cb831138ff64e76d456397670eaea83652980f428206cbc091dd5e2b6fbf24d453b58ee75d316f0f27d1
6
+ metadata.gz: 025716c4860daf3a0184f62b4909984a31b184e45c362308873a8175d23cb882a9c59aaa38184d221ab791c62b2daa98f20bbc435c57e9f96c138accdd60c6eb
7
+ data.tar.gz: 01aa3a00a0a4eac6f888652e7d6be9bc7ad66b1e74b3d4d641c02e3a7eaa0ceb32d1e2b4c17c484f91ff4cd054476f5e25b542e9bb0be79d73d180942e68939a
@@ -3,7 +3,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
3
 
4
4
  Gem::Specification.new do |spec|
5
5
  spec.name = "fluent-plugin-fluent-plugin-json-size-limit"
6
- spec.version = "0.1.30"
6
+ spec.version = "0.1.31"
7
7
  spec.authors = ["Mykola Panin"]
8
8
  spec.email = ["mykola.panin@creatoriq.com"]
9
9
 
@@ -20,16 +20,24 @@ module Fluent
20
20
  class JsonSizeLimitFilter < Filter
21
21
  Fluent::Plugin.register_filter('jsonsizelimit', self)
22
22
 
23
+ # Configuration parameter for maximum JSON size
23
24
  config_param :max_size, :size, default: 250 * 1024
25
+ # Configuration parameter for maximum attempts to reduce JSON size
26
+ config_param :max_attempts, :integer, default: 100
24
27
 
25
28
  def configure(conf)
26
29
  super
27
- log.debug "Configuring JsonSizeLimitFilter with max_size: #{@max_size}"
30
+ log.debug "Configuring JsonSizeLimitFilter with max_size: #{@max_size} and max_attempts: #{@max_attempts}"
28
31
  end
29
32
 
30
33
  def filter(tag, time, record)
31
34
  original_size = record.to_json.bytesize
32
- reduce_size(record, @max_size)
35
+ begin
36
+ reduce_size(record, @max_size)
37
+ rescue => e
38
+ log.error "Error during size reduction: #{e.message}"
39
+ return record # Return the original record in case of an error
40
+ end
33
41
  final_size = record.to_json.bytesize
34
42
 
35
43
  log.debug "Reduced record size from #{original_size} to #{final_size} bytes" if original_size != final_size
@@ -40,7 +48,7 @@ module Fluent
40
48
 
41
49
  def reduce_size(obj, target_size)
42
50
  attempts = 0
43
- while obj.to_json.bytesize > target_size && attempts < 100
51
+ while obj.to_json.bytesize > target_size && attempts < @max_attempts
44
52
  excess_size = obj.to_json.bytesize - target_size
45
53
  perform_reduction(obj, excess_size, obj.to_json.bytesize)
46
54
  attempts += 1
@@ -49,9 +57,7 @@ module Fluent
49
57
 
50
58
  def perform_reduction(obj, excess_size, total_size)
51
59
  if obj.is_a?(Hash)
52
- obj.each do |key, value|
53
- apply_reduction(value, excess_size, total_size)
54
- end
60
+ obj.each { |key, value| apply_reduction(value, excess_size, total_size) }
55
61
  elsif obj.is_a?(Array)
56
62
  obj.each { |element| apply_reduction(element, excess_size, total_size) }
57
63
  elsif obj.is_a?(String)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-fluent-plugin-json-size-limit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.30
4
+ version: 0.1.31
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mykola Panin