class Fluent::BigObjectOutput

Constants

DEFAULT_TAG_FORMAT

DEFAULT_TAG_FORMAT = /(?<table_name>+).(?<event>+).(?<primary_key>+)$/

Attributes

tables[RW]

Public Class Methods

new() click to toggle source
Calls superclass method
# File lib/fluent/plugin/out_bigobject.rb, line 177
def initialize
  super
  require 'rest-client'
  require 'json'
  log.info("bigobject initialize")
end

Public Instance Methods

configure(conf) click to toggle source
Calls superclass method
# File lib/fluent/plugin/out_bigobject.rb, line 184
  def configure(conf)
    super
    
    if remove_tag_prefix = conf['remove_tag_prefix']
      @remove_tag_prefix = Regexp.new('^' + Regexp.escape(remove_tag_prefix))
    end

    if @tag_format.nil? || @tag_format == DEFAULT_TAG_FORMAT
      @tag_format = DEFAULT_TAG_FORMAT
    else
      @tag_format = Regexp.new(conf['tag_format'])
    end
    
    @tables = []
    @default_table = nil
 
    conf.elements.select { |e|
      e.name == 'table'
    }.each { |e|
      te = TableElement.new(log, @bigobject_hostname, @bigobject_port, @tag_format)
      te.configure(e)
      @tables << te
    }
    
#    @tables.each {|t| puts t.to_s}
  end
emit(tag, es, chain) click to toggle source
Calls superclass method
# File lib/fluent/plugin/out_bigobject.rb, line 252
def emit(tag, es, chain)
  nt = format_tag(tag)
  super(nt, es, chain, nt)
end
format(tag, time, record) click to toggle source

This method is called when an event reaches to Fluentd.

# File lib/fluent/plugin/out_bigobject.rb, line 221
def format(tag, time, record)
  [tag, time, record].to_msgpack
end
format_tag(tag) click to toggle source
# File lib/fluent/plugin/out_bigobject.rb, line 244
def format_tag(tag)
  if @remove_tag_prefix
    tag.gsub(@remove_tag_prefix, '')
  else
    tag
  end
end
shutdown() click to toggle source
Calls superclass method
# File lib/fluent/plugin/out_bigobject.rb, line 216
def shutdown
  super
end
start() click to toggle source
Calls superclass method
# File lib/fluent/plugin/out_bigobject.rb, line 211
def start
  super
  log.info("bigobject start")
end
write(chunk) click to toggle source

This method is called every flush interval. Write the buffer chunk to files or databases here. ‘chunk’ is a buffer chunk that includes multiple formatted events.

# File lib/fluent/plugin/out_bigobject.rb, line 228
def write(chunk)
  unknownChunks = []
  tag = chunk.key
  tag_parts = tag.match(@tag_format)
  target_table = tag_parts['table_name']
    
  @tables.each { |table|
    if table.mpattern.match(target_table)
      return table.send(chunk)
    end
  }
  
  log.warn("unknown chunk #{chunk.key}")
    
end