Class: Fluent::AddInsertIdsFilter
- Inherits:
-
Filter
- Object
- Filter
- Fluent::AddInsertIdsFilter
- Includes:
- selfself::ConfigConstants
- Defined in:
- lib/fluent/plugin/filter_add_insert_ids.rb
Overview
Fluentd filter plugin for adding insertIds to guarantee log entry order and uniqueness. Sample log entries enriched by this plugin:
"timestamp": "2017-08-22 13:35:28",
"message": "1",
"logging.googleapis.com/insertId": "aye7eakuf23h41aef0"
"timestamp": "2017-08-22 13:35:28",
"message": "2",
"logging.googleapis.com/insertId": "aye7eakuf23h41aef1"
"timestamp": "2017-08-22 13:35:28",
"message": "3",
"logging.googleapis.com/insertId": "aye7eakuf23h41aef2"
Defined Under Namespace
Modules: ConfigConstants
Instance Attribute Summary collapse
-
#insert_id_key ⇒ Object
readonly
Expose attr_readers for testing.
Instance Method Summary collapse
- #configure(conf) ⇒ Object
-
#filter(tag, time, record) ⇒ Object
rubocop:disable Lint/UnusedMethodArgument.
- #shutdown ⇒ Object
- #start ⇒ Object
Instance Attribute Details
#insert_id_key ⇒ Object (readonly)
Expose attr_readers for testing.
55 56 57 |
# File 'lib/fluent/plugin/filter_add_insert_ids.rb', line 55 def insert_id_key @insert_id_key end |
Instance Method Details
#configure(conf) ⇒ Object
68 69 70 |
# File 'lib/fluent/plugin/filter_add_insert_ids.rb', line 68 def configure(conf) super end |
#filter(tag, time, record) ⇒ Object
rubocop:disable Lint/UnusedMethodArgument
77 78 79 80 81 82 83 84 |
# File 'lib/fluent/plugin/filter_add_insert_ids.rb', line 77 def filter(tag, time, record) # Only generate and add an insertId field if the record is a hash and # the insert ID field is not already set (or set to an empty string). if record.is_a?(Hash) && record[@insert_id_key].to_s.empty? record[@insert_id_key] = increment_insert_id end record end |
#shutdown ⇒ Object
72 73 74 |
# File 'lib/fluent/plugin/filter_add_insert_ids.rb', line 72 def shutdown super end |
#start ⇒ Object
57 58 59 60 61 62 63 64 65 66 |
# File 'lib/fluent/plugin/filter_add_insert_ids.rb', line 57 def start super @log = $log # rubocop:disable Style/GlobalVars # Initialize the insertID. @log.info "Started the add_insert_ids plugin with #{@insert_id_key}" \ ' as the insert ID key.' @insert_id = generate_initial_insert_id @log.info "Initialized the insert ID key to #{@insert_id}." end |