class Fluent::CloudSearchOutput
Constants
- INVALID_CHAR_REGEX
docs.aws.amazon.com/en_us/cloudsearch/latest/developerguide/preparing-data.html
- MAX_SIZE_LIMIT
message packをJSONにした時に5MBを超えないように
Public Class Methods
new()
click to toggle source
Calls superclass method
# File lib/fluent/plugin/out_cloudsearch.rb, line 21 def initialize super require 'aws-sdk' require 'json' end
Public Instance Methods
configure(conf)
click to toggle source
Calls superclass method
# File lib/fluent/plugin/out_cloudsearch.rb, line 28 def configure(conf) # override config. (config_set_default can't override it) conf['buffer_chunk_limit'] ||= MAX_SIZE_LIMIT super unless @endpoint raise ConfigError, "'endpoint' parameter is required" end if @buffer.buffer_chunk_limit > MAX_SIZE_LIMIT raise ConfigError, "buffer_chunk_limit must be less than #{MAX_SIZE_LIMIT}" end end
format(tag, time, record)
click to toggle source
# File lib/fluent/plugin/out_cloudsearch.rb, line 56 def format(tag, time, record) if !record.key?('id') then log.warn "id is required #{record.to_s}" return '' elsif !record.key?('type') then log.warn "type is required #{record.to_s}" return '' elsif record['type'] == 'add' then if !record.key?('fields') then log.warn "fields is required when type is add. #{record.to_s}" return '' end elsif record['type'] != 'delete' then log.warn "type is add or delete #{record.to_s}" return '' end r = record.dup f = r['fields'] if f.kind_of? Hash # replace invalid char to white space f.each do |key, value| if value.kind_of? String f[key] = value.gsub(INVALID_CHAR_REGEX, ' ') else f[key] = value end end end return "#{r.to_json}," end
setup_credentials()
click to toggle source
docs.aws.amazon.com/sdkforruby/api/Aws/CloudSearchDomain/Client.html#initialize-instance_method
# File lib/fluent/plugin/out_cloudsearch.rb, line 100 def setup_credentials options = {} if @access_key_id && @secret_access_key options[:credentials] = Aws::Credentials.new(@access_key_id, @secret_access_key) elsif @profile_name options[:credentials] = Aws::SharedCredentials.new( :profile_name => @profile_name ) end options end
shutdown()
click to toggle source
Calls superclass method
# File lib/fluent/plugin/out_cloudsearch.rb, line 51 def shutdown super end
start()
click to toggle source
Calls superclass method
# File lib/fluent/plugin/out_cloudsearch.rb, line 43 def start super options = setup_credentials options[:endpoint] = @endpoint options[:region] = @region if @region @client = Aws::CloudSearchDomain::Client.new(options) end
write(chunk)
click to toggle source
# File lib/fluent/plugin/out_cloudsearch.rb, line 89 def write(chunk) documents = '[' documents << chunk.read.chop # chop last ',' documents << ']' resp = @client.upload_documents( :documents => documents, :content_type => "application/json" ) end