fluent-plugin-fluent-plugin-json-size-limit 0.1.30 → 0.1.31
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 05e23baa812f5f389f8632c11f7793ce3bbeb9fb147d2f59f581d12a7d360d15
|
4
|
+
data.tar.gz: 8aea346b7c77227efff34fc70917f714ab7201268916bbdfe9ea5c92b64caf74
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
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
|
-
|
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 <
|
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
|
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)
|