Class: Fluent::Plugin::Filter

Inherits:
Base
  • Object
show all
Includes:
Fluent::PluginHelper::Mixin, Fluent::PluginId, Fluent::PluginLoggerMixin
Defined in:
lib/fluent/plugin/filter.rb

Constant Summary

Constants included from Configurable

Configurable::CONFIG_TYPE_REGISTRY

Instance Attribute Summary collapse

Attributes included from Fluent::PluginLoggerMixin

#log

Attributes inherited from Base

#under_plugin_development

Instance Method Summary collapse

Methods included from Fluent::PluginHelper::Mixin

included

Methods included from Fluent::PluginLoggerMixin

included, #terminate

Methods included from Fluent::PluginId

#plugin_id, #plugin_id_configured?, #plugin_id_for_test?, #plugin_root_dir, #stop

Methods inherited from Base

#acquire_worker_lock, #after_shutdown, #after_shutdown?, #after_start, #after_started?, #before_shutdown, #before_shutdown?, #called_in_test?, #close, #closed?, #configured?, #context_router, #context_router=, #fluentd_worker_id, #get_lock_path, #has_router?, #inspect, #multi_workers_ready?, #plugin_root_dir, #reloadable_plugin?, #shutdown, #shutdown?, #start, #started?, #stop, #stopped?, #string_safe_encoding, #terminate, #terminated?

Methods included from SystemConfig::Mixin

#system_config, #system_config_override

Methods included from Configurable

#config, #configure_proxy_generate, #configured_section_create, included, lookup_type, register_type

Constructor Details

#initializeFilter

Returns a new instance of Filter.



35
36
37
38
39
40
41
42
# File 'lib/fluent/plugin/filter.rb', line 35

def initialize
  super
  @has_filter_with_time = has_filter_with_time?
  @emit_records_metrics = nil
  @emit_size_metrics = nil
  @counter_mutex = Mutex.new
  @enable_size_metrics = false
end

Instance Attribute Details

#has_filter_with_timeObject (readonly)

Returns the value of attribute has_filter_with_time.



33
34
35
# File 'lib/fluent/plugin/filter.rb', line 33

def has_filter_with_time
  @has_filter_with_time
end

Instance Method Details

#configure(conf) ⇒ Object



52
53
54
55
56
57
58
# File 'lib/fluent/plugin/filter.rb', line 52

def configure(conf)
  super

  @emit_records_metrics = metrics_create(namespace: "fluentd", subsystem: "filter", name: "emit_records", help_text: "Number of count emit records")
  @emit_size_metrics = metrics_create(namespace: "fluentd", subsystem: "filter", name: "emit_size", help_text: "Total size of emit events")
  @enable_size_metrics = !!system_config.enable_size_metrics
end

#emit_recordsObject



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

def emit_records
  @emit_records_metrics.get
end

#emit_sizeObject



48
49
50
# File 'lib/fluent/plugin/filter.rb', line 48

def emit_size
  @emit_size_metrics.get
end

#filter(tag, time, record) ⇒ Object

Raises:

  • (NotImplementedError)


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

def filter(tag, time, record)
  raise NotImplementedError, "BUG: filter plugins MUST implement this method"
end

#filter_stream(tag, es) ⇒ Object



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/fluent/plugin/filter.rb', line 82

def filter_stream(tag, es)
  new_es = MultiEventStream.new
  if @has_filter_with_time
    es.each do |time, record|
      begin
        filtered_time, filtered_record = filter_with_time(tag, time, record)
        new_es.add(filtered_time, filtered_record) if filtered_time && filtered_record
      rescue => e
        router.emit_error_event(tag, time, record, e)
      end
    end
  else
    es.each do |time, record|
      begin
        filtered_record = filter(tag, time, record)
        new_es.add(time, filtered_record) if filtered_record
      rescue => e
        router.emit_error_event(tag, time, record, e)
      end
    end
  end
  new_es
end

#filter_with_time(tag, time, record) ⇒ Object

Raises:

  • (NotImplementedError)


78
79
80
# File 'lib/fluent/plugin/filter.rb', line 78

def filter_with_time(tag, time, record)
  raise NotImplementedError, "BUG: filter plugins MUST implement this method"
end

#measure_metrics(es) ⇒ Object



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

def measure_metrics(es)
  @emit_records_metrics.add(es.size)
  @emit_size_metrics.add(es.to_msgpack_stream.bytesize) if @enable_size_metrics
end

#statisticsObject



60
61
62
63
64
65
66
67
# File 'lib/fluent/plugin/filter.rb', line 60

def statistics
  stats = {
    'emit_records' => @emit_records_metrics.get,
    'emit_size' => @emit_size_metrics.get,
  }

  { 'filter' => stats }
end