lib/fluent/plugin/out_mongo.rb in fluent-plugin-mongo-1.0.0.rc1 vs lib/fluent/plugin/out_mongo.rb in fluent-plugin-mongo-1.0.0.rc2
- old
+ new
@@ -17,12 +17,14 @@
DEFAULT_BUFFER_TYPE = "memory"
config_set_default :include_tag_key, false
config_set_default :include_time_key, true
+ desc "MongoDB connection string"
+ config_param :connection_string, :default => nil
desc "MongoDB database"
- config_param :database, :string
+ config_param :database, :string, :default => nil
desc "MongoDB collection"
config_param :collection, :string, default: 'untagged'
desc "MongoDB host"
config_param :host, :string, default: 'localhost'
desc "MongoDB port"
@@ -36,13 +38,15 @@
desc "Replace dollar with specified string"
config_param :replace_dollar_in_key_with, :string, default: nil
# tag mapping mode
desc "Use tag_mapped mode"
- config_param :tag_mapped, :bool, default: false
+ config_param :tag_mapped, :bool, default: false,
+ deprecated: "use '${tag}' placeholder in collection parameter."
desc "Remove tag prefix"
- config_param :remove_tag_prefix, :string, default: nil
+ config_param :remove_tag_prefix, :string, default: nil,
+ deprecated: "use @label instead for event routing."
# SSL connection
config_param :ssl, :bool, default: false
config_param :ssl_cert, :string, default: nil
config_param :ssl_key, :string, default: nil
@@ -58,10 +62,11 @@
attr_reader :client_options, :collection_options
def initialize
super
+ @nodes = nil
@client_options = {}
@collection_options = {capped: false}
end
# Following limits are heuristic. BSON is sometimes bigger than MessagePack and JSON.
@@ -90,10 +95,14 @@
end
compat_parameters_convert(conf, :inject)
super
+ if @connection_string.nil? && @database.nil?
+ raise Fluent::ConfigError, "connection_string or database parameter is required"
+ end
+
unless @ignore_invalid_record
log.warn "Since v0.8, invalid record detection will be removed because mongo driver v2.x and API spec don't provide it. You may lose invalid records, so you should not send such records to mongo plugin"
end
if conf.has_key?('tag_mapped')
@@ -122,10 +131,11 @@
@client_options[:ssl_key] = @ssl_key
@client_options[:ssl_key_pass_phrase] = @ssl_key_pass_phrase
@client_options[:ssl_verify] = @ssl_verify
@client_options[:ssl_ca_cert] = @ssl_ca_cert
end
+ @nodes = ["#{@host}:#{@port}"] if @nodes.nil?
configure_logger(@mongo_log_level)
log.debug "Setup mongo configuration: mode = #{@tag_mapped ? 'tag mapped' : 'normal'}"
end
@@ -167,13 +177,17 @@
end
private
def client
- @client_options[:database] = @database
- @client_options[:user] = @user if @user
- @client_options[:password] = @password if @password
- Mongo::Client.new(["#{@host}:#{@port}"], @client_options)
+ if @connection_string
+ Mongo::Client.new(@connection_string)
+ else
+ @client_options[:database] = @database
+ @client_options[:user] = @user if @user
+ @client_options[:password] = @password if @password
+ Mongo::Client.new(@nodes, @client_options)
+ end
end
def collect_records(chunk)
records = []
time_key = @inject_config.time_key