fluent-plugin-fluent-plugin-json-size-limit 0.1.29 → 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
|
|
@@ -31,14 +31,12 @@ module Fluent
|
|
31
31
|
end
|
32
32
|
|
33
33
|
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
34
|
original_size = record.to_json.bytesize
|
38
35
|
begin
|
39
36
|
reduce_size(record, @max_size)
|
40
37
|
rescue => e
|
41
38
|
log.error "Error during size reduction: #{e.message}"
|
39
|
+
return record # Return the original record in case of an error
|
42
40
|
end
|
43
41
|
final_size = record.to_json.bytesize
|
44
42
|
|
@@ -48,31 +46,29 @@ module Fluent
|
|
48
46
|
|
49
47
|
private
|
50
48
|
|
51
|
-
def reduce_size(obj, target_size
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
49
|
+
def reduce_size(obj, target_size)
|
50
|
+
attempts = 0
|
51
|
+
while obj.to_json.bytesize > target_size && attempts < @max_attempts
|
52
|
+
excess_size = obj.to_json.bytesize - target_size
|
53
|
+
perform_reduction(obj, excess_size, obj.to_json.bytesize)
|
54
|
+
attempts += 1
|
55
|
+
end
|
58
56
|
end
|
59
57
|
|
60
58
|
def perform_reduction(obj, excess_size, total_size)
|
61
|
-
|
62
|
-
when Hash
|
59
|
+
if obj.is_a?(Hash)
|
63
60
|
obj.each { |key, value| apply_reduction(value, excess_size, total_size) }
|
64
|
-
|
61
|
+
elsif obj.is_a?(Array)
|
65
62
|
obj.each { |element| apply_reduction(element, excess_size, total_size) }
|
66
|
-
|
63
|
+
elsif obj.is_a?(String)
|
67
64
|
reduce_string(obj, excess_size, total_size)
|
68
65
|
end
|
69
66
|
end
|
70
67
|
|
71
68
|
def apply_reduction(element, excess_size, total_size)
|
72
|
-
|
73
|
-
when String
|
69
|
+
if element.is_a?(String)
|
74
70
|
reduce_string(element, excess_size, total_size)
|
75
|
-
|
71
|
+
elsif element.is_a?(Hash) || element.is_a?(Array)
|
76
72
|
reduce_size(element, element.to_json.bytesize - (excess_size * (element.to_json.bytesize.to_f / total_size)))
|
77
73
|
end
|
78
74
|
end
|