Class: Fluent::RouteOutput

Inherits:
MultiOutput
  • Object
show all
Includes:
Mixin::ConfigPlaceholders
Defined in:
lib/fluent/plugin/out_route.rb

Defined Under Namespace

Classes: Route

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRouteOutput

Returns a new instance of RouteOutput.



82
83
84
85
86
87
# File 'lib/fluent/plugin/out_route.rb', line 82

def initialize
  super
  @routes = []
  @tag_cache = {}
  @match_cache = {}
end

Instance Attribute Details

#routesObject (readonly)

TODO tag_transform regexp



93
94
95
# File 'lib/fluent/plugin/out_route.rb', line 93

def routes
  @routes
end

Instance Method Details

#configure(conf) ⇒ Object



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/fluent/plugin/out_route.rb', line 100

def configure(conf)
  super

  if @remove_tag_prefix
    @prefix_match = /^#{Regexp.escape(@remove_tag_prefix)}\.?/
  else
    @prefix_match = //
  end
  if @add_tag_prefix
    @tag_prefix = "#{@add_tag_prefix}."
  else
    @tag_prefix = ""
  end

  conf.elements.select {|e|
    e.name == 'route'
  }.each {|e|
    route = Route.new(e.arg)
    route.configure(e)
    @routes << route
  }
end

#emit(tag, es, chain) ⇒ Object



123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/fluent/plugin/out_route.rb', line 123

def emit(tag, es, chain)
  ntag, targets = @match_cache[tag]
  unless targets
    ntag = tag.sub(@prefix_match, @tag_prefix)
    targets = []
    @routes.each {|r|
      if r.match?(ntag)
        targets << r
        break unless r.copy?
      end
    }
    if @match_cache.size < 1024  # TODO size limit
      @match_cache[tag] = [ntag, targets]
    end
  end

  case targets.size
  when 0
    return
  when 1
    targets.first.emit(ntag, es)
    chain.next
  else
    unless es.repeatable?
      m = MultiEventStream.new
      es.each {|time,record|
        m.add(time, record)
      }
      es = m
    end
    targets.each {|t|
      t.emit(ntag, es)
    }
    chain.next
  end
end