Class: Fluent::Plugin::MapFilter

Inherits:
Filter
  • Object
show all
Includes:
Fluent::ParseMap::Mixin, MapConfigParam
Defined in:
lib/fluent/plugin/filter_map.rb

Constant Summary

Constants included from Fluent::ParseMap::Mixin

Fluent::ParseMap::Mixin::MMAP_MAX_NUM

Instance Method Summary collapse

Methods included from Fluent::ParseMap::Mixin

#check_mmap_range, #parse_map, #parse_multimap

Methods included from MapConfigParam

included

Instance Method Details

#configure(conf) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/fluent/plugin/filter_map.rb', line 29

def configure(conf)
  super
  @format = determine_format()
  configure_format()
  @map = create_map(conf)
  @map_support = Fluent::Plugin::MapSupport.new(@map, self)
end

#configure_formatObject



55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/fluent/plugin/filter_map.rb', line 55

def configure_format()
  case @format
  when "map"
    # pass
  when "record"
    raise Fluent::ConfigError, "multi and 2 parameters(time, and record) are not compatible" if @multi
  when "multimap"
    # pass.
  else
    raise Fluent::ConfigError, "format #{@format} is invalid."
  end
end

#create_map(conf) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
# File 'lib/fluent/plugin/filter_map.rb', line 68

def create_map(conf)
  # return string like double array.
  case @format
  when "map"
    parse_map()
  when "record"
    "[[#{@time}, #{@record}]]"
  when "multimap"
    parse_multimap(conf)
  end
end

#determine_formatObject



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/fluent/plugin/filter_map.rb', line 43

def determine_format()
  if @format
    @format
  elsif @map
    "map"
  elsif @time && @record
    "record"
  else
    raise Fluent::ConfigError, "Any of map, 2 parameters(time, and record) or format is required "
  end
end

#filter_stream(tag, es) ⇒ Object



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/fluent/plugin/filter_map.rb', line 80

def filter_stream(tag, es)
  begin
    new_es = Fluent::MultiEventStream.new
    tag_output_es = @map_support.do_map(tag, es)
    tag_output_es.each_pair do |tag, output_es|
      output_es.each{|time, record|
        new_es.add(time, record)
      }
    end
    new_es
  rescue SyntaxError => e
    log.error "map command is syntax error: #{@map}"
    e #for test
  end
end

#stopObject



37
38
39
40
41
# File 'lib/fluent/plugin/filter_map.rb', line 37

def stop
  @map_support.stop

  super
end