Class: LogStash::Outputs::Dynatrace::Batcher
- Inherits:
-
Object
- Object
- LogStash::Outputs::Dynatrace::Batcher
- Defined in:
- lib/logstash/outputs/dynatrace.rb
Instance Method Summary collapse
- #drain_and_serialize ⇒ Object
- #empty? ⇒ Boolean
-
#initialize(max_batch_size) ⇒ Batcher
constructor
A new instance of Batcher.
- #offer(serialized_event) ⇒ Object
Constructor Details
#initialize(max_batch_size) ⇒ Batcher
Returns a new instance of Batcher.
117 118 119 120 121 |
# File 'lib/logstash/outputs/dynatrace.rb', line 117 def initialize(max_batch_size) @max_batch_size = max_batch_size @batch_events_size = 0 @serialized_events = [] end |
Instance Method Details
#drain_and_serialize ⇒ Object
133 134 135 136 137 138 |
# File 'lib/logstash/outputs/dynatrace.rb', line 133 def drain_and_serialize out = "[#{@serialized_events.join(',')}]\n" @batch_events_size = 0 @serialized_events = [] out end |
#empty? ⇒ Boolean
140 141 142 |
# File 'lib/logstash/outputs/dynatrace.rb', line 140 def empty? @serialized_events.empty? end |
#offer(serialized_event) ⇒ Object
123 124 125 126 127 128 129 130 131 |
# File 'lib/logstash/outputs/dynatrace.rb', line 123 def offer(serialized_event) # 2 square brackets, the length of all previously serialized strings, commas, and the current event size batch_size_bytes = 2 + @batch_events_size + @serialized_events.length + serialized_event.bytesize return false if batch_size_bytes > @max_batch_size @serialized_events.push(serialized_event) @batch_events_size += serialized_event.bytesize true end |