fluent-plugin-fluent-plugin-json-size-limit 0.1.27 → 0.1.29
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: 591d68308d420614aa3ea9c6c4379a77f489afa72b42adaa22356686f403ee9e
|
4
|
+
data.tar.gz: 600efc817220c04458478cd2d1b44025f17a01eb77f2fadf43a650f382437938
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2c865638c22f747a6f42c9f0a2a6469463d85567837c6381858fcc569f8cffd5a46e55b65142bba9d00f4f7fa629e3a1870821bcc3c27c0556c947e0b6f6c29e
|
7
|
+
data.tar.gz: b285917dba21b70b9b2937b89d91da7273b33bbd4f3f2855ee4a6eef541ff2f8657266ba81be3bc26e932702b7376b68f432170bd3936e605db4a6ad0d9c0a19
|
@@ -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.29"
|
7
7
|
spec.authors = ["Mykola Panin"]
|
8
8
|
spec.email = ["mykola.panin@creatoriq.com"]
|
9
9
|
|
@@ -20,16 +20,26 @@ 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)
|
34
|
+
# Ensure that the record is a Hash before processing
|
35
|
+
return record unless record.is_a?(Hash)
|
36
|
+
|
31
37
|
original_size = record.to_json.bytesize
|
32
|
-
|
38
|
+
begin
|
39
|
+
reduce_size(record, @max_size)
|
40
|
+
rescue => e
|
41
|
+
log.error "Error during size reduction: #{e.message}"
|
42
|
+
end
|
33
43
|
final_size = record.to_json.bytesize
|
34
44
|
|
35
45
|
log.debug "Reduced record size from #{original_size} to #{final_size} bytes" if original_size != final_size
|
@@ -38,37 +48,37 @@ module Fluent
|
|
38
48
|
|
39
49
|
private
|
40
50
|
|
41
|
-
def reduce_size(obj, target_size)
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
51
|
+
def reduce_size(obj, target_size, attempts = 0)
|
52
|
+
json_str = obj.to_json
|
53
|
+
return if json_str.bytesize <= target_size || attempts >= @max_attempts
|
54
|
+
|
55
|
+
excess_size = json_str.bytesize - target_size
|
56
|
+
perform_reduction(obj, excess_size, json_str.bytesize)
|
57
|
+
reduce_size(obj, target_size, attempts + 1) # Recursive call with incremented attempts
|
48
58
|
end
|
49
59
|
|
50
|
-
def perform_reduction(obj, excess_size)
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
reduce_string(obj, excess_size)
|
60
|
+
def perform_reduction(obj, excess_size, total_size)
|
61
|
+
case obj
|
62
|
+
when Hash
|
63
|
+
obj.each { |key, value| apply_reduction(value, excess_size, total_size) }
|
64
|
+
when Array
|
65
|
+
obj.each { |element| apply_reduction(element, excess_size, total_size) }
|
66
|
+
when String
|
67
|
+
reduce_string(obj, excess_size, total_size)
|
59
68
|
end
|
60
69
|
end
|
61
70
|
|
62
|
-
def apply_reduction(element, excess_size)
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
71
|
+
def apply_reduction(element, excess_size, total_size)
|
72
|
+
case element
|
73
|
+
when String
|
74
|
+
reduce_string(element, excess_size, total_size)
|
75
|
+
when Hash, Array
|
76
|
+
reduce_size(element, element.to_json.bytesize - (excess_size * (element.to_json.bytesize.to_f / total_size)))
|
67
77
|
end
|
68
78
|
end
|
69
79
|
|
70
|
-
def reduce_string(str, excess_size)
|
71
|
-
reduction_amount = (str.length.to_f /
|
80
|
+
def reduce_string(str, excess_size, total_size)
|
81
|
+
reduction_amount = (str.length.to_f / total_size) * excess_size
|
72
82
|
new_length = [str.length - reduction_amount, 0].max
|
73
83
|
str.replace(str[0...new_length])
|
74
84
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.
|
4
|
+
version: 0.1.29
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mykola Panin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-12-
|
11
|
+
date: 2023-12-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|