fluent-plugin-fluent-plugin-json-size-limit 0.1.27 → 0.1.28

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: fc2d0b868e3e3879068c4c4adb44caf832379ad4d927f09e72f02223cc9efe9b
4
- data.tar.gz: cfa85d22a6b21b41ff7541f6040ca22c4ed5fbf20b13f818392928e1f5d5624a
3
+ metadata.gz: 1e24f82280ef078291ee109be79150cfc9789676643ed84b87e2c32e472b6afe
4
+ data.tar.gz: d862ce1033e2a3e443ed32c9571502edc5373c1b3851936e108aeba01f47f49a
5
5
  SHA512:
6
- metadata.gz: 18f99e8b8e7841be35f024b481676e7cb0da6b9f045d4ff67479c6cb6325a8ca74452f469f8d3631878c3bf2dbaa179af6dd4ab76392e912656cd44a70c9fc23
7
- data.tar.gz: b3eae5c689ed71874327ba01d30803321b19f5848f8977f8e2b57862650adf1504deb263181ad13232ee97dcc6fa1a5c396c5014cb30a0257ddd8865d9b759bc
6
+ metadata.gz: 1f747939411789f6c8102fa5d7f7a47f6728b6e6337e61740efdb5ae69fc5bc2d210e0711f693f2afe06f66fe068446b205e9b0288765bb2b03b66ee5a9eb4d8
7
+ data.tar.gz: 692f8c2b477084a14963f8cf25920f6265aafc90bcc942a693eb435bd929b37516f42555e2832d008a813338c6ae38864424e0d4b6f138706bac691059e119e3
@@ -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.27"
6
+ spec.version = "0.1.28"
7
7
  spec.authors = ["Mykola Panin"]
8
8
  spec.email = ["mykola.panin@creatoriq.com"]
9
9
 
@@ -42,33 +42,33 @@ module Fluent
42
42
  attempts = 0
43
43
  while obj.to_json.bytesize > target_size && attempts < 100
44
44
  excess_size = obj.to_json.bytesize - target_size
45
- perform_reduction(obj, excess_size)
45
+ perform_reduction(obj, excess_size, obj.to_json.bytesize)
46
46
  attempts += 1
47
47
  end
48
48
  end
49
49
 
50
- def perform_reduction(obj, excess_size)
50
+ def perform_reduction(obj, excess_size, total_size)
51
51
  if obj.is_a?(Hash)
52
52
  obj.each do |key, value|
53
- apply_reduction(value, excess_size)
53
+ apply_reduction(value, excess_size, total_size)
54
54
  end
55
55
  elsif obj.is_a?(Array)
56
- obj.each { |element| apply_reduction(element, excess_size) }
56
+ obj.each { |element| apply_reduction(element, excess_size, total_size) }
57
57
  elsif obj.is_a?(String)
58
- reduce_string(obj, excess_size)
58
+ reduce_string(obj, excess_size, total_size)
59
59
  end
60
60
  end
61
61
 
62
- def apply_reduction(element, excess_size)
62
+ def apply_reduction(element, excess_size, total_size)
63
63
  if element.is_a?(String)
64
- reduce_string(element, excess_size)
64
+ reduce_string(element, excess_size, total_size)
65
65
  elsif element.is_a?(Hash) || element.is_a?(Array)
66
- reduce_size(element, element.to_json.bytesize - excess_size)
66
+ reduce_size(element, element.to_json.bytesize - (excess_size * (element.to_json.bytesize.to_f / total_size)))
67
67
  end
68
68
  end
69
69
 
70
- def reduce_string(str, excess_size)
71
- reduction_amount = (str.length.to_f / str.to_json.bytesize) * excess_size
70
+ def reduce_string(str, excess_size, total_size)
71
+ reduction_amount = (str.length.to_f / total_size) * excess_size
72
72
  new_length = [str.length - reduction_amount, 0].max
73
73
  str.replace(str[0...new_length])
74
74
  end
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.27
4
+ version: 0.1.28
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mykola Panin