Class: Fluent::Plugin::JsonSizeLimit::RecordMeasurer
- Inherits:
-
Object
- Object
- Fluent::Plugin::JsonSizeLimit::RecordMeasurer
- Defined in:
- lib/fluent/plugin/json_size_limit/record_measurer.rb
Overview
Performs a bounded, side-effect-free preflight before using the native JSON generator exactly once. The preflight prevents arbitrary Ruby serializers or traversal overrides from entering the hot path.
Constant Summary collapse
- EXIT_CONTAINER =
Object.new.freeze
- HASH_EACH_PAIR =
Hash.instance_method(:each_pair)
- HASH_LENGTH =
Hash.instance_method(:length)
- ARRAY_EACH =
Array.instance_method(:each)
- ARRAY_LENGTH =
Array.instance_method(:length)
- STRING_BYTESIZE =
String.instance_method(:bytesize)
- SINGLETON_METHODS =
Object.instance_method(:singleton_methods)
Instance Method Summary collapse
-
#initialize(guard) ⇒ RecordMeasurer
constructor
A new instance of RecordMeasurer.
- #measure(record) ⇒ Object
Constructor Details
#initialize(guard) ⇒ RecordMeasurer
Returns a new instance of RecordMeasurer.
22 23 24 |
# File 'lib/fluent/plugin/json_size_limit/record_measurer.rb', line 22 def initialize(guard) @guard = guard end |
Instance Method Details
#measure(record) ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/fluent/plugin/json_size_limit/record_measurer.rb', line 26 def measure(record) validate_record(record) @guard.checkpoint! json_bytes = JSON.generate(record).bytesize @guard.enforce_input_bytes!(json_bytes) @guard.checkpoint! json_bytes end |