15
15
require 'stringio'
16
16
17
17
module LogStash ; module Outputs ; class OpenSearch ;
18
- # This is a constant instead of a config option because
19
- # there really isn't a good reason to configure it.
20
- #
21
- # The criteria used are:
22
- # 1. We need a number that's less than 100MiB because OpenSearch
23
- # won't accept bulks larger than that.
24
- # 2. It must be large enough to amortize the connection constant
25
- # across multiple requests.
26
- # 3. It must be small enough that even if multiple threads hit this size
27
- # we won't use a lot of heap.
28
- #
29
- # We wound up agreeing that a number greater than 10 MiB and less than 100MiB
30
- # made sense. We picked one on the lowish side to not use too much heap.
31
- TARGET_BULK_BYTES = 20 * 1024 * 1024 # 20MiB
32
-
33
18
class HttpClient
34
- attr_reader :client , :options , :logger , :pool , :action_count , :recv_count
19
+ attr_reader :client , :options , :logger , :pool , :action_count , :recv_count , :target_bulk_bytes
20
+
35
21
# This is here in case we use DEFAULT_OPTIONS in the future
36
22
# DEFAULT_OPTIONS = {
37
23
# :setting => value
@@ -72,6 +58,8 @@ def initialize(options={})
72
58
# mutex to prevent requests and sniffing to access the
73
59
# connection pool at the same time
74
60
@bulk_path = @options [ :bulk_path ]
61
+
62
+ @target_bulk_bytes = @options [ :target_bulk_bytes ]
75
63
end
76
64
77
65
def build_url_template
@@ -104,7 +92,6 @@ def maximum_seen_major_version
104
92
def bulk ( actions )
105
93
@action_count ||= 0
106
94
@action_count += actions . size
107
-
108
95
return if actions . empty?
109
96
110
97
bulk_actions = actions . collect do |action , args , source |
@@ -131,7 +118,7 @@ def bulk(actions)
131
118
action . map { |line | LogStash ::Json . dump ( line ) } . join ( "\n " ) :
132
119
LogStash ::Json . dump ( action )
133
120
as_json << "\n "
134
- if ( stream_writer . pos + as_json . bytesize ) > TARGET_BULK_BYTES && stream_writer . pos > 0
121
+ if ( stream_writer . pos + as_json . bytesize ) > @target_bulk_bytes && stream_writer . pos > 0
135
122
stream_writer . flush # ensure writer has sync'd buffers before reporting sizes
136
123
logger . debug ( "Sending partial bulk request for batch with one or more actions remaining." ,
137
124
:action_count => batch_actions . size ,
0 commit comments