Module: Fluent::ParseMap::Mixin

Included in:
Fluent::Plugin::MapFilter, Fluent::Plugin::MapOutput
Defined in:
lib/fluent/plugin/parse_map_mixin.rb

Constant Summary collapse

MMAP_MAX_NUM =
50

Instance Method Summary collapse

Instance Method Details

#check_mmap_range(conf) ⇒ Object



48
49
50
51
52
53
54
55
56
# File 'lib/fluent/plugin/parse_map_mixin.rb', line 48

def check_mmap_range(conf)
  invalid_mmap = conf.keys.select { |k|
    m = k.match(/^mmap(\d+)$/)
    m ? !((1..MMAP_MAX_NUM).include?(m[1].to_i)) : false
  }
  unless invalid_mmap.empty?
    raise Fluent::ConfigError, "Invalid mmapN found. N should be 1 - #{MMAP_MAX_NUM}: " + invalid_mmap.join(",")
  end
end

#parse_mapObject



23
24
25
26
27
28
29
# File 'lib/fluent/plugin/parse_map_mixin.rb', line 23

def parse_map()
  if @multi
    @map
  else
    "[#{@map}]"
  end
end

#parse_multimap(conf) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/fluent/plugin/parse_map_mixin.rb', line 31

def parse_multimap(conf)
  check_mmap_range(conf)

  prev_mmap = nil
  result_mmaps = (1..MMAP_MAX_NUM).map { |i|
    mmap = conf["mmap#{i}"]
    if (i > 1) && prev_mmap.nil? && !mmap.nil?
      raise Fluent::ConfigError, "Jump of mmap index found. mmap#{i - 1} is missing."
    end
    prev_mmap = mmap
    next if mmap.nil?

    mmap
  }.compact.join(',')
  "[#{result_mmaps}]"
end