fluent-plugin-fluent-plugin-json-size-limit 0.1.13 → 0.1.15
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: 40f924059fcbebb4396efc9f677ffe7dd8b2d846a6b408c27023c604f5ac4eb7
|
4
|
+
data.tar.gz: 1f4ff05c3488fd48d1aacb5f1bf6f8087bb90d65e342f8569ca2590c2282594d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 118f7e2a31f67b792ad4b0470be2a783e4dcfa6a15330d6cf6af074e7f3fe3dac7ff0e6057edc0f425bd73bce5b7ca2d2b6f2162e58e3d400e6ebaa1ea2e255d
|
7
|
+
data.tar.gz: 01e25d11c7efea63c48d34e95b6ebba689d7793568c5910a2395212284a69a25c8706322579ed58f86fb8399f20afe997f8c52c66f7f9cbbb6de46183e09051c
|
@@ -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.15"
|
7
7
|
spec.authors = ["Mykola Panin"]
|
8
8
|
spec.email = ["mykola.panin@creatoriq.com"]
|
9
9
|
|
@@ -20,39 +20,37 @@ module Fluent
|
|
20
20
|
class JsonSizeLimitFilter < Filter
|
21
21
|
Fluent::Plugin.register_filter('jsonsizelimit', self)
|
22
22
|
|
23
|
+
config_param :max_size, :size, default: 250 * 1024
|
24
|
+
|
23
25
|
def configure(conf)
|
24
26
|
super
|
25
|
-
log.debug "Configuring JsonSizeLimitFilter"
|
27
|
+
log.debug "Configuring JsonSizeLimitFilter with max_size: #{@max_size}"
|
26
28
|
end
|
27
29
|
|
28
30
|
def filter(tag, time, record)
|
29
|
-
|
31
|
+
original_size = record.to_json.bytesize
|
30
32
|
json_str = record.to_json
|
31
|
-
|
33
|
+
|
34
|
+
if json_str.bytesize > @max_size
|
32
35
|
sorted_fields = record.sort_by { |k, v| v.to_s.length }.reverse
|
33
|
-
reduced = false
|
34
36
|
|
35
37
|
sorted_fields.each do |key, value|
|
36
38
|
next unless value.is_a?(String) && value.length > 10
|
37
39
|
|
38
40
|
current_size = json_str.bytesize
|
39
|
-
|
40
|
-
excess_size = current_size - target_size
|
41
|
+
excess_size = current_size - @max_size
|
41
42
|
|
42
43
|
new_length = [value.length - excess_size, 0].max
|
43
44
|
record[key] = value[0...new_length]
|
44
|
-
|
45
45
|
json_str = record.to_json
|
46
|
-
|
47
|
-
|
48
|
-
log.debug "Reduced size of field '#{key}' to fit size limit"
|
49
|
-
break
|
50
|
-
end
|
46
|
+
|
47
|
+
break if json_str.bytesize <= @max_size
|
51
48
|
end
|
52
49
|
|
53
|
-
|
54
|
-
log.debug "
|
50
|
+
final_size = json_str.bytesize
|
51
|
+
log.debug "Reduced record size from #{original_size} to #{final_size} bytes"
|
55
52
|
end
|
53
|
+
|
56
54
|
record
|
57
55
|
end
|
58
56
|
end
|