Class: Plugin::InfluxdbDeduplicationFilter
- Inherits:
-
Filter
- Object
- Filter
- Plugin::InfluxdbDeduplicationFilter
- Defined in:
- lib/fluent/plugin/filter_influxdb_deduplication.rb
Instance Method Summary collapse
- #configure(conf) ⇒ Object
- #filter(tag, time, record) ⇒ Object
- #start ⇒ Object
- #tag_deduplication(time, record) ⇒ Object
- #time_deduplication(time, record) ⇒ Object
Instance Method Details
#configure(conf) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/fluent/plugin/filter_influxdb_deduplication.rb', line 20 def configure(conf) super if @time == nil and @tag == nil raise Fluent::ConfigError, "one of tag or time deduplication needs to be set." elsif @time != nil and @tag != nil raise Fluent::ConfigError, "tag and time deduplication are mutually exclusive." elsif @time != nil and (@time.key == nil or @time.key == "") raise Fluent::ConfigError, "an output 'key' field is required for time deduplication" elsif @tag != nil and (@tag == nil or @tag.key == "") raise Fluent::ConfigError, "an output 'key' field is required for tag deduplication" end end |
#filter(tag, time, record) ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/fluent/plugin/filter_influxdb_deduplication.rb', line 41 def filter(tag, time, record) if @time time_deduplication(time, record) else tag_deduplication(time, record) end end |
#start ⇒ Object
34 35 36 37 38 39 |
# File 'lib/fluent/plugin/filter_influxdb_deduplication.rb', line 34 def start super @last_timestamp = 0 @sequence = 0 end |
#tag_deduplication(time, record) ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/fluent/plugin/filter_influxdb_deduplication.rb', line 91 def tag_deduplication(time, record) if time.is_a?(Integer) input_time = time elsif time.is_a?(Fluent::EventTime) input_time = time.sec * 1000000000 + time.nsec else @log.error("unreadable time") return nil end if input_time < @last_timestamp @log.debug("out of sequence timestamp") if @order_key record[@order_key] = false else @log.debug("out of order record dropped") return nil end elsif input_time == @last_timestamp @sequence = @sequence + 1 record[@tag.key] = @sequence if @order_key record[@order_key] = true end else @sequence = 0 @last_timestamp = input_time record[@tag.key] = 0 if @order_key record[@order_key] = true end end record end |
#time_deduplication(time, record) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/fluent/plugin/filter_influxdb_deduplication.rb', line 49 def time_deduplication(time, record) if time.is_a?(Integer) input_time = Fluent::EventTime.new(time) elsif time.is_a?(Fluent::EventTime) input_time = time else @log.error("unreadable time") return nil end nano_time = input_time.sec * 1000000000 if input_time.sec < @last_timestamp @log.debug("out of sequence timestamp") if @order_key record[@order_key] = false record[@time.key] = nano_time else @log.debug("out of order record dropped") return nil end elsif input_time.sec == @last_timestamp and @sequence < 999999999 @sequence = @sequence + 1 record[@time.key] = nano_time + @sequence if @order_key record[@order_key] = true end elsif input_time.sec == @last_timestamp and @sequence == 999999999 @log.error("received more then 999999999 records in a second") return nil else @sequence = 0 @last_timestamp = input_time.sec record[@time.key] = nano_time if @order_key record[@order_key] = true end end record end |