class Fluent::RandomTagOutput
Public Instance Methods
check_valid_interval(lower, upper)
click to toggle source
# File lib/fluent/plugin/out_randomtag.rb, line 21 def check_valid_interval(lower, upper) if (lower >= upper) raise "random_tag: Bad interval for 'integer' (#{lower} >= #{upper})" end end
configure(conf)
click to toggle source
Calls superclass method
# File lib/fluent/plugin/out_randomtag.rb, line 28 def configure(conf) super if (integer.nil?) raise ConfigError, "random_tag: 'integer' is required to be set." end @integer_interval = parse_integer_field(integer) check_valid_interval(@integer_interval[0], @integer_interval[1]) @random = Random.new() end
emit(tag, es, chain)
click to toggle source
# File lib/fluent/plugin/out_randomtag.rb, line 40 def emit(tag, es, chain) es.each { |time, record| t = tag.dup r = process() #Create new tag with random number prefixed nT = "#{r}.#{t}" filter_record(nT, time, record) Engine.emit(nT, time, record) } chain.next end
parse_integer_field(interval)
click to toggle source
# File lib/fluent/plugin/out_randomtag.rb, line 13 def parse_integer_field(interval) lower_upper = interval.split("..", 2).map{|value| Integer(value) } if (lower_upper.length != 2 || !lower_upper[0].is_a?(Integer) || !lower_upper[1].is_a?(Integer)) raise "random_tag: Bad value for 'integer' (value: '#{interval}')" end return lower_upper end
Private Instance Methods
filter_record(tag, time, record)
click to toggle source
Calls superclass method
# File lib/fluent/plugin/out_randomtag.rb, line 55 def filter_record(tag, time, record) super(tag, time, record) end
generate_integer(lower, upper)
click to toggle source
# File lib/fluent/plugin/out_randomtag.rb, line 64 def generate_integer(lower, upper) return @random.rand(lower..upper) end
process()
click to toggle source
# File lib/fluent/plugin/out_randomtag.rb, line 59 def process() return generate_integer(@integer_interval[0], @integer_interval[1]) end