Class: Fluent::Plugin::JsonSizeLimitFilter

Inherits:
Filter
  • Object
show all
Includes:
Fluent::Plugin::JsonSizeLimit::FilterConfiguration
Defined in:
lib/fluent/plugin/json_size_limit/filter.rb

Constant Summary collapse

UnreducibleRecordError =

Compatibility constant for callers that referenced the earlier class.

JsonSizeLimit::UnreducibleRecordError

Constants included from Fluent::Plugin::JsonSizeLimit::FilterConfiguration

Fluent::Plugin::JsonSizeLimit::FilterConfiguration::DEFAULT_MAX_INPUT_SIZE

Instance Method Summary collapse

Methods included from Fluent::Plugin::JsonSizeLimit::FilterConfiguration

included

Instance Method Details

#configure(conf) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/fluent/plugin/json_size_limit/filter.rb', line 16

def configure(conf)
  super
  validate_json_size_limit_configuration!

  @telemetry = JsonSizeLimit::Telemetry.new { |name, help_text| create_metric(name, help_text) }
  @record_processor = JsonSizeLimit::RecordProcessor.new(
    max_json_bytes: @max_size,
    safety_options: processing_safety_options
  )
  @operational_log = JsonSizeLimit::RateLimitedLogger.new(log, @warning_interval)

  log.on_debug do
    log.debug(
      "Configured JsonSizeLimitFilter",
      max_size: @max_size,
      enabled: @enabled,
      overflow_action: @overflow_action,
      error_action: @error_action,
      processing_timeout: @processing_timeout,
      max_record_nodes: @max_record_nodes,
      max_input_size: @max_input_size,
      max_nesting: @max_nesting
    )
  end
end

#filter(_tag, _time, record) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/fluent/plugin/json_size_limit/filter.rb', line 48

def filter(_tag, _time, record)
  return record unless @enabled

  result = @record_processor.call(record)

  case result.status
  when :within_limit
    record
  when :reduced
    handle_reduced(record, result)
  when :overflow
    handle_overflow(record, result)
  else
    raise JsonSizeLimit::UnexpectedProcessorStatusError, result.status
  end
rescue UnreducibleRecordError
  raise
rescue => error
  handle_error(record, error)
end

#multi_workers_ready?Boolean

The processor has no mutable cross-record state. Fluentd automatically invokes the same implementation from every configured worker/thread.

Returns:

  • (Boolean)


44
45
46
# File 'lib/fluent/plugin/json_size_limit/filter.rb', line 44

def multi_workers_ready?
  true
end

#shutdownObject



73
74
75
76
77
# File 'lib/fluent/plugin/json_size_limit/filter.rb', line 73

def shutdown
  @operational_log&.flush
ensure
  super
end

#statisticsObject



69
70
71
# File 'lib/fluent/plugin/json_size_limit/filter.rb', line 69

def statistics
  super.merge("json_size_limit" => @telemetry&.statistics || {})
end