Class: Fluent::Plugin::LabelRouterOutput

Inherits:
BareOutput
  • Object
show all
Defined in:
lib/fluent/plugin/out_label_router.rb

Defined Under Namespace

Classes: Route

Instance Method Summary collapse

Instance Method Details

#configure(conf) ⇒ Object



112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/fluent/plugin/out_label_router.rb', line 112

def configure(conf)
  super
  @route_map = Hash.new { |h, k| h[k] = Array.new }
  @routers = []
  @routes.each do |rule|
    route_router = event_emitter_router(rule['@label'])
    @routers << Route.new(rule.labels, rule.namespace.to_s, rule.tag.to_s, route_router)
  end

  @access_to_labels = record_accessor_create("$.kubernetes.labels")
  @access_to_namespace = record_accessor_create("$.kubernetes.namespace_name")

  @batch = @emit_mode == :batch
end

#process(tag, es) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/fluent/plugin/out_label_router.rb', line 78

def process(tag, es)
  if @sticky_tags
    if @route_map.has_key?(tag)
      # We already matched with this tag send events to the routers
      @route_map[tag].each do |r|
        r.emit_es(tag, es.dup)
      end
      return
    end
  end
  event_stream = Hash.new {|h, k| h[k] = Fluent::MultiEventStream.new }
  es.each do |time, record|
    input_labels = @access_to_labels.call(record).to_h
    input_namespace = @access_to_namespace.call(record).to_s
    @routers.each do |r|
      if r.match?(input_labels, input_namespace)
        if @sticky_tags
          @route_map[tag].push(r)
        end
        if @batch
          event_stream[r].add(time, record)
        else
          r.emit(tag, time, record.dup)
        end
      end
    end
    if @batch
      event_stream.each do |r, es|
        r.emit_es(tag, es.dup)
      end
    end
  end
end