Class: Fluent::CloudSearchOutput
- Inherits:
-
BufferedOutput
- Object
- BufferedOutput
- Fluent::CloudSearchOutput
- Defined in:
- lib/fluent/plugin/out_cloudsearch.rb
Constant Summary collapse
- MAX_SIZE_LIMIT =
message packをJSONにした時に5MBを超えないように
4.5 * 1024 * 1024
Instance Method Summary collapse
- #configure(conf) ⇒ Object
- #format(tag, time, record) ⇒ Object
-
#initialize ⇒ CloudSearchOutput
constructor
A new instance of CloudSearchOutput.
- #setup_credentials ⇒ Object
- #shutdown ⇒ Object
- #start ⇒ Object
- #write(chunk) ⇒ Object
Constructor Details
#initialize ⇒ CloudSearchOutput
Returns a new instance of CloudSearchOutput.
18 19 20 21 22 23 |
# File 'lib/fluent/plugin/out_cloudsearch.rb', line 18 def initialize super require 'aws-sdk' require 'json' end |
Instance Method Details
#configure(conf) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/fluent/plugin/out_cloudsearch.rb', line 25 def configure(conf) # override config. (config_set_default can't override it) conf['buffer_chunk_limit'] ||= MAX_SIZE_LIMIT super 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) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/fluent/plugin/out_cloudsearch.rb', line 50 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 "#{record.to_json}\n" end |
#setup_credentials ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/fluent/plugin/out_cloudsearch.rb', line 81 def setup_credentials = {} if @access_key_id && @secret_access_key [:credentials] = Aws::Credentials.new(@access_key_id, @secret_access_key) elsif @profile_name [:credentials] = Aws::SharedCredentials.new( :profile_name => @profile_name ) end end |
#shutdown ⇒ Object
45 46 47 48 |
# File 'lib/fluent/plugin/out_cloudsearch.rb', line 45 def shutdown super end |
#start ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/fluent/plugin/out_cloudsearch.rb', line 37 def start super = setup_credentials [:endpoint] = @endpoint if @endpoint [:region] = @region if @region @client = Aws::CloudSearchDomain::Client.new() end |
#write(chunk) ⇒ Object
70 71 72 73 74 75 76 77 78 |
# File 'lib/fluent/plugin/out_cloudsearch.rb', line 70 def write(chunk) documents = '[' documents << chunk.read.split("\n").join(",") documents << ']' resp = @client.upload_documents( :documents => documents, :content_type => "application/json" ) end |