Class: Fluent::RandomTagOutput
- Inherits:
-
Output
- Object
- Output
- Fluent::RandomTagOutput
- Includes:
- HandleTagNameMixin
- Defined in:
- lib/fluent/plugin/out_randomtag.rb
Instance Method Summary collapse
- #check_valid_interval(lower, upper) ⇒ Object
- #configure(conf) ⇒ Object
- #emit(tag, es, chain) ⇒ Object
- #parse_integer_field(interval) ⇒ Object
Instance Method Details
#check_valid_interval(lower, upper) ⇒ Object
21 22 23 24 25 |
# 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) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 |
# 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) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 |
# 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) ⇒ Object
13 14 15 16 17 18 19 |
# 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 |