lib/fluent/plugin/out_solr.rb in fluent-plugin-output-solr-0.2.1 vs lib/fluent/plugin/out_solr.rb in fluent-plugin-output-solr-0.2.2

- old
+ new

@@ -7,10 +7,11 @@ class SolrOutput < BufferedOutput Fluent::Plugin.register_output('solr', self) DEFAULT_COLLECTION = 'collection1' DEFAULT_IGNORE_UNDEFINED_FIELDS = false + DEFAULT_TAG_FIELD = 'tag' DEFAULT_TIMESTAMP_FIELD = 'event_timestamp' DEFAULT_FLUSH_SIZE = 100 MODE_STANDALONE = 'Standalone' MODE_SOLRCLOUD = 'SolrCloud' @@ -34,10 +35,12 @@ config_param :ignore_undefined_fields, :bool, :default => DEFAULT_IGNORE_UNDEFINED_FIELDS, :desc => 'Ignore undefined fields in the Solr schema.xml.' config_param :unique_key_field, :string, :default => nil, :desc => 'A field name of unique key in the Solr schema.xml. If omitted, it will get unique key via Solr Schema API.' + config_param :tag_field, :string, :default => DEFAULT_TAG_FIELD, + :desc => 'A field name of fluentd tag in the Solr schema.xml (default event_timestamp).' config_param :timestamp_field, :string, :default => DEFAULT_TIMESTAMP_FIELD, :desc => 'A field name of event timestamp in the Solr schema.xml (default event_timestamp).' config_param :flush_size, :integer, :default => DEFAULT_FLUSH_SIZE, :desc => 'A number of events to queue up before writing to Solr (default 100).' @@ -56,10 +59,11 @@ @defined_fields = conf['defined_fields'] @ignore_undefined_field = conf.has_key?('ignore_undefined_field') ? conf['ignore_undefined_field'] : DEFAULT_IGNORE_UNDEFINED_FIELDS @unique_key_field = conf['unique_key_field'] + @tag_field = conf.has_key?('tag_field') ? conf['tag_field'] : DEFAULT_TAG_FIELD @timestamp_field = conf.has_key?('timestamp_field') ? conf['timestamp_field'] : DEFAULT_TIMESTAMP_FIELD @flush_size = conf.has_key?('flush_size') ? conf['flush_size'].to_i : DEFAULT_FLUSH_SIZE end @@ -102,15 +106,20 @@ @fields = @defined_fields.nil? ? get_fields : @defined_fields @unique_key = @unique_key_field.nil? ? get_unique_key : @unique_key_field chunk.msgpack_each do |tag, time, record| - unless record.has_key?(@unique_key) then record.merge!({@unique_key => SecureRandom.uuid}) end - record.merge!({@timestamp_field => Time.at(time).utc.strftime('%FT%TZ')}) + unless record.has_key?(@tag_field) then + record.merge!({@tag_field => tag}) + end + + unless record.has_key?(@timestamp_field) then + record.merge!({@timestamp_field => Time.at(time).utc.strftime('%FT%TZ')}) + end if @ignore_undefined_fields then record.each_key do |key| unless @fields.include?(key) then record.delete(key)