Class: Fluent::Plugin::ConditionalTagRewriteOutput

Inherits:
Output
  • Object
show all
Defined in:
lib/fluent/plugin/out_conditional_tag_rewrite.rb

Overview

Plugin ‘@type conditional_tag_rewrite’

Instance Method Summary collapse

Constructor Details

#initializeConditionalTagRewriteOutput

Returns a new instance of ConditionalTagRewriteOutput.



47
48
49
50
51
52
# File 'lib/fluent/plugin/out_conditional_tag_rewrite.rb', line 47

def initialize
  super

  @router = router
  @and_conditions = []
end

Instance Method Details

#configure(conf) ⇒ Object



54
55
56
57
58
59
60
61
62
# File 'lib/fluent/plugin/out_conditional_tag_rewrite.rb', line 54

def configure(conf)
  super

  # create objects from configuration
  @ands.each do |and_condition|
    condition_list = and_condition.conditions.map { |c| Condition.new(record_accessor_create(c.key), c.pattern) }
    @and_conditions.append(And.new(and_condition.tag, condition_list))
  end
end

#process(tag, es) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/fluent/plugin/out_conditional_tag_rewrite.rb', line 64

def process(tag, es)
  multi_event_streams = Hash.new { |hash, key| hash[key] = MultiEventStream.new }

  es.each do |time, record|
    should_rewrite, rewritten_tag = rewrite?(record)
    multi_event_streams[rewritten_tag].add(time, record) if should_rewrite
  end

  # re-emit all event streams / records with rewritten tags
  multi_event_streams.each do |rewritten_tag, event_stream|
    @router.emit_stream(rewritten_tag, event_stream)
  end
end

#rewrite?(record) ⇒ Boolean

Returns:

  • (Boolean)


78
79
80
81
82
83
84
85
86
# File 'lib/fluent/plugin/out_conditional_tag_rewrite.rb', line 78

def rewrite?(record)
  @and_conditions.each do |and_condition|
    next unless and_condition.match?(record)

    return true, and_condition.tag
  end

  [!@fallback_tag.nil?, @fallback_tag]
end