fluent-plugin-fluent-plugin-json-size-limit 0.1.29 → 0.1.30
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 73d82be0721ff66686b415ed8264f699b7ec5943c343442246591d7ffff2a691
|
4
|
+
data.tar.gz: 0c7373794b14bb31a8378a5095959f29baba102a28c7060d5b5dbc59e62a48ee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2e59c251899fdc1172ab144af0cc4d5aaa53b1c667d0b2ed7f22cbdf11d1b3f02992ce6e930ac604c8418108b5eec77502aee1272ab2261cf475769e19e7f635
|
7
|
+
data.tar.gz: e05efd4111d3a46ac60bd2b0b856359b408b98b1daf7cb831138ff64e76d456397670eaea83652980f428206cbc091dd5e2b6fbf24d453b58ee75d316f0f27d1
|
@@ -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.30"
|
7
7
|
spec.authors = ["Mykola Panin"]
|
8
8
|
spec.email = ["mykola.panin@creatoriq.com"]
|
9
9
|
|
@@ -20,26 +20,16 @@ module Fluent
|
|
20
20
|
class JsonSizeLimitFilter < Filter
|
21
21
|
Fluent::Plugin.register_filter('jsonsizelimit', self)
|
22
22
|
|
23
|
-
# Configuration parameter for maximum JSON size
|
24
23
|
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
|
27
24
|
|
28
25
|
def configure(conf)
|
29
26
|
super
|
30
|
-
log.debug "Configuring JsonSizeLimitFilter with max_size: #{@max_size}
|
27
|
+
log.debug "Configuring JsonSizeLimitFilter with max_size: #{@max_size}"
|
31
28
|
end
|
32
29
|
|
33
30
|
def filter(tag, time, record)
|
34
|
-
# Ensure that the record is a Hash before processing
|
35
|
-
return record unless record.is_a?(Hash)
|
36
|
-
|
37
31
|
original_size = record.to_json.bytesize
|
38
|
-
|
39
|
-
reduce_size(record, @max_size)
|
40
|
-
rescue => e
|
41
|
-
log.error "Error during size reduction: #{e.message}"
|
42
|
-
end
|
32
|
+
reduce_size(record, @max_size)
|
43
33
|
final_size = record.to_json.bytesize
|
44
34
|
|
45
35
|
log.debug "Reduced record size from #{original_size} to #{final_size} bytes" if original_size != final_size
|
@@ -48,31 +38,31 @@ module Fluent
|
|
48
38
|
|
49
39
|
private
|
50
40
|
|
51
|
-
def reduce_size(obj, target_size
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
41
|
+
def reduce_size(obj, target_size)
|
42
|
+
attempts = 0
|
43
|
+
while obj.to_json.bytesize > target_size && attempts < 100
|
44
|
+
excess_size = obj.to_json.bytesize - target_size
|
45
|
+
perform_reduction(obj, excess_size, obj.to_json.bytesize)
|
46
|
+
attempts += 1
|
47
|
+
end
|
58
48
|
end
|
59
49
|
|
60
50
|
def perform_reduction(obj, excess_size, total_size)
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
51
|
+
if obj.is_a?(Hash)
|
52
|
+
obj.each do |key, value|
|
53
|
+
apply_reduction(value, excess_size, total_size)
|
54
|
+
end
|
55
|
+
elsif obj.is_a?(Array)
|
65
56
|
obj.each { |element| apply_reduction(element, excess_size, total_size) }
|
66
|
-
|
57
|
+
elsif obj.is_a?(String)
|
67
58
|
reduce_string(obj, excess_size, total_size)
|
68
59
|
end
|
69
60
|
end
|
70
61
|
|
71
62
|
def apply_reduction(element, excess_size, total_size)
|
72
|
-
|
73
|
-
when String
|
63
|
+
if element.is_a?(String)
|
74
64
|
reduce_string(element, excess_size, total_size)
|
75
|
-
|
65
|
+
elsif element.is_a?(Hash) || element.is_a?(Array)
|
76
66
|
reduce_size(element, element.to_json.bytesize - (excess_size * (element.to_json.bytesize.to_f / total_size)))
|
77
67
|
end
|
78
68
|
end
|