logstash-output-elasticsearch_java 2.0.2 → 2.1.1.beta1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +6 -0
  3. data/Gemfile +1 -1
  4. data/lib/logstash/outputs/elasticsearch_java.rb +37 -386
  5. data/lib/logstash/outputs/elasticsearch_java/protocol.rb +201 -228
  6. data/logstash-output-elasticsearch_java.gemspec +2 -1
  7. data/spec/integration/outputs/elasticsearch/node_spec.rb +0 -25
  8. data/spec/integration/outputs/index_spec.rb +2 -4
  9. data/spec/integration/outputs/retry_spec.rb +24 -14
  10. data/spec/integration/outputs/routing_spec.rb +1 -2
  11. data/spec/integration/outputs/secure_spec.rb +4 -4
  12. data/spec/integration/outputs/templates_spec.rb +13 -11
  13. data/spec/integration/outputs/transport_create_spec.rb +5 -6
  14. data/spec/integration/outputs/update_spec.rb +5 -6
  15. data/spec/unit/outputs/elasticsearch/protocol_spec.rb +6 -3
  16. data/spec/unit/outputs/elasticsearch_spec.rb +0 -1
  17. data/vendor/jar-dependencies/runtime-jars/{elasticsearch-2.0.0.jar → elasticsearch-2.1.0.jar} +0 -0
  18. data/vendor/jar-dependencies/runtime-jars/jackson-core-2.6.2.jar +0 -0
  19. data/vendor/jar-dependencies/runtime-jars/jackson-dataformat-cbor-2.6.2.jar +0 -0
  20. data/vendor/jar-dependencies/runtime-jars/jackson-dataformat-smile-2.6.2.jar +0 -0
  21. data/vendor/jar-dependencies/runtime-jars/jackson-dataformat-yaml-2.6.2.jar +0 -0
  22. data/vendor/jar-dependencies/runtime-jars/{lucene-analyzers-common-5.2.1.jar → lucene-analyzers-common-5.3.1.jar} +0 -0
  23. data/vendor/jar-dependencies/runtime-jars/{lucene-backward-codecs-5.2.1.jar → lucene-backward-codecs-5.3.1.jar} +0 -0
  24. data/vendor/jar-dependencies/runtime-jars/{lucene-core-5.2.1.jar → lucene-core-5.3.1.jar} +0 -0
  25. data/vendor/jar-dependencies/runtime-jars/{lucene-expressions-5.2.1.jar → lucene-expressions-5.3.1.jar} +0 -0
  26. data/vendor/jar-dependencies/runtime-jars/{lucene-grouping-5.2.1.jar → lucene-grouping-5.3.1.jar} +0 -0
  27. data/vendor/jar-dependencies/runtime-jars/{lucene-highlighter-5.2.1.jar → lucene-highlighter-5.3.1.jar} +0 -0
  28. data/vendor/jar-dependencies/runtime-jars/lucene-join-5.3.1.jar +0 -0
  29. data/vendor/jar-dependencies/runtime-jars/lucene-memory-5.3.1.jar +0 -0
  30. data/vendor/jar-dependencies/runtime-jars/{lucene-misc-5.2.1.jar → lucene-misc-5.3.1.jar} +0 -0
  31. data/vendor/jar-dependencies/runtime-jars/{lucene-queries-5.2.1.jar → lucene-queries-5.3.1.jar} +0 -0
  32. data/vendor/jar-dependencies/runtime-jars/{lucene-queryparser-5.2.1.jar → lucene-queryparser-5.3.1.jar} +0 -0
  33. data/vendor/jar-dependencies/runtime-jars/lucene-sandbox-5.3.1.jar +0 -0
  34. data/vendor/jar-dependencies/runtime-jars/{lucene-spatial-5.2.1.jar → lucene-spatial-5.3.1.jar} +0 -0
  35. data/vendor/jar-dependencies/runtime-jars/lucene-spatial3d-5.3.1.jar +0 -0
  36. data/vendor/jar-dependencies/runtime-jars/lucene-suggest-5.3.1.jar +0 -0
  37. data/vendor/jar-dependencies/runtime-jars/snakeyaml-1.15.jar +0 -0
  38. data/vendor/jar-dependencies/runtime-jars/spatial4j-0.5.jar +0 -0
  39. metadata +105 -91
  40. data/lib/logstash/outputs/elasticsearch_java/elasticsearch-template.json +0 -93
  41. data/vendor/jar-dependencies/runtime-jars/jackson-core-2.5.3.jar +0 -0
  42. data/vendor/jar-dependencies/runtime-jars/jackson-dataformat-cbor-2.5.3.jar +0 -0
  43. data/vendor/jar-dependencies/runtime-jars/jackson-dataformat-smile-2.5.3.jar +0 -0
  44. data/vendor/jar-dependencies/runtime-jars/jackson-dataformat-yaml-2.5.3.jar +0 -0
  45. data/vendor/jar-dependencies/runtime-jars/lucene-join-5.2.1.jar +0 -0
  46. data/vendor/jar-dependencies/runtime-jars/lucene-memory-5.2.1.jar +0 -0
  47. data/vendor/jar-dependencies/runtime-jars/lucene-sandbox-5.2.1.jar +0 -0
  48. data/vendor/jar-dependencies/runtime-jars/lucene-suggest-5.2.1.jar +0 -0
  49. data/vendor/jar-dependencies/runtime-jars/snakeyaml-1.12.jar +0 -0
  50. data/vendor/jar-dependencies/runtime-jars/spatial4j-0.4.1.jar +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a5467c0eb6987bbc644c21942c60480d27521b2a
4
- data.tar.gz: 5bbd2ada48fffbfa2594875177982b9245c5b233
3
+ metadata.gz: 5cebb6798c2db7392cf7a8a7957e37b7290306d5
4
+ data.tar.gz: ad5f55d2a1b7de142b35c7b69262f7d501867b0f
5
5
  SHA512:
6
- metadata.gz: 4ebcd346bdd78df297791ec1e2c2f65f80894f8996f53eee0439717fd9a80ffc5acbeb2bbb25bb390c87a55115a786316b2ae02f6c29e38bbd16f9a7a60907bb
7
- data.tar.gz: f3b04dade1f983bb2bf358ae80a9d08dc622c7b5504aa519bbb6bf46f5c18c420d217fb0c63396e5d9c5a52ff5e30c413338bea73057fa930c8ccf7acb438528
6
+ metadata.gz: 220a4b40f8bf0294b3e2ecdba3d7647fa72fbb1e1f0d7e0ecf22ad27c823aefeef3dd584227193e0e24781b881a4545227c70691f458bcecc695aafc47d63740
7
+ data.tar.gz: b7db119540b418fb3602be6e86909eb4675cc340e56b546bd2b4e8bfa22b0c61f9ec7cdbe42b65a3a1b243b6d271c3402e15805dea1cc2d7d3bc3bb1e679f1c6
@@ -1,3 +1,9 @@
1
+ ## 2.1.1
2
+ - Support Elasticsearch 2.1.0
3
+ - Fix issue where transport client w/o port specified breaks
4
+ ## 2.1.0
5
+ - Port option no longer allowed
6
+ - Majority of code now shared with logstash-output-elasticsearch
1
7
  ## 2.0.2
2
8
  - Update loading of addons to conform with new naming scheme (replaced - with _)
3
9
  ## 2.0.1
data/Gemfile CHANGED
@@ -1,3 +1,3 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gemspec
3
+ gemspec
@@ -4,11 +4,11 @@ require "logstash/environment"
4
4
  require "logstash/outputs/base"
5
5
  require "logstash/json"
6
6
  require "concurrent"
7
- require "stud/buffer"
8
7
  require "socket" # for Socket.gethostname
9
8
  require "thread" # for safe queueing
10
9
  require "uri" # for escaping user input
11
10
  require "logstash/outputs/elasticsearch_java/protocol"
11
+ require "logstash/outputs/elasticsearch"
12
12
 
13
13
  # This output lets you store logs in Elasticsearch using the native 'node' and 'transport'
14
14
  # protocols. It is highly recommended to use the regular 'logstash-output-elasticsearch' output
@@ -67,66 +67,25 @@ require "logstash/outputs/elasticsearch_java/protocol"
67
67
  class LogStash::Outputs::ElasticSearchJava < LogStash::Outputs::Base
68
68
  attr_reader :client
69
69
 
70
- include Stud::Buffer
70
+ include LogStash::Outputs::ElasticSearch::CommonConfigs
71
+ include LogStash::Outputs::ElasticSearch::Common
72
+
71
73
  RETRYABLE_CODES = [409, 429, 503]
72
74
  SUCCESS_CODES = [200, 201]
73
75
 
74
76
  config_name "elasticsearch_java"
75
77
 
76
- # The index to write events to. This can be dynamic using the `%{foo}` syntax.
77
- # The default value will partition your indices by day so you can more easily
78
- # delete old data or only search specific date ranges.
79
- # Indexes may not contain uppercase characters.
80
- # For weekly indexes ISO 8601 format is recommended, eg. logstash-%{+xxxx.ww}
81
- config :index, :validate => :string, :default => "logstash-%{+YYYY.MM.dd}"
82
-
83
- # The index type to write events to. Generally you should try to write only
84
- # similar events to the same 'type'. String expansion `%{foo}` works here.
85
- #
86
- # Deprecated in favor of `document_type` field.
87
- config :index_type, :validate => :string, :deprecated => "Please use the 'document_type' setting instead. It has the same effect, but is more appropriately named."
88
-
89
- # The document type to write events to. Generally you should try to write only
90
- # similar events to the same 'type'. String expansion `%{foo}` works here.
91
- # Unless you set 'document_type', the event 'type' will be used if it exists
92
- # otherwise the document type will be assigned the value of 'logs'
93
- config :document_type, :validate => :string
94
-
95
- # Starting in Logstash 1.3 (unless you set option `manage_template` to false)
96
- # a default mapping template for Elasticsearch will be applied, if you do not
97
- # already have one set to match the index pattern defined (default of
98
- # `logstash-%{+YYYY.MM.dd}`), minus any variables. For example, in this case
99
- # the template will be applied to all indices starting with `logstash-*`
78
+ # The Elasticsearch action to perform. Valid actions are:
100
79
  #
101
- # If you have dynamic templating (e.g. creating indices based on field names)
102
- # then you should set `manage_template` to false and use the REST API to upload
103
- # your templates manually.
104
- config :manage_template, :validate => :boolean, :default => true
105
-
106
- # This configuration option defines how the template is named inside Elasticsearch.
107
- # Note that if you have used the template management features and subsequently
108
- # change this, you will need to prune the old template manually, e.g.
109
- #
110
- # `curl -XDELETE <http://localhost:9200/_template/OldTemplateName?pretty>`
80
+ # - index: indexes a document (an event from Logstash).
81
+ # - delete: deletes a document by id (An id is required for this action)
82
+ # - create: indexes a document, fails if a document by that id already exists in the index.
83
+ # - update: updates a document by id. Update has a special case where you can upsert -- update a
84
+ # document if not already present. See the `upsert` option
85
+ # - create_unless_exists: create the document unless it already exists, in which case do nothing.
111
86
  #
112
- # where `OldTemplateName` is whatever the former setting was.
113
- config :template_name, :validate => :string, :default => "logstash"
114
-
115
- # You can set the path to your own template here, if you so desire.
116
- # If not set, the included template will be used.
117
- config :template, :validate => :path
118
-
119
- # Overwrite the current template with whatever is configured
120
- # in the `template` and `template_name` directives.
121
- config :template_overwrite, :validate => :boolean, :default => false
122
-
123
- # The document ID for the index. Useful for overwriting existing entries in
124
- # Elasticsearch with the same ID.
125
- config :document_id, :validate => :string
126
-
127
- # A routing override to be applied to all processed events.
128
- # This can be dynamic using the `%{foo}` syntax.
129
- config :routing, :validate => :string
87
+ # For more details on actions, check out the http://www.elastic.co/guide/en/elasticsearch/reference/current/docs-bulk.html[Elasticsearch bulk API documentation]
88
+ config :action, :validate => %w(index delete create update create_unless_exists), :default => "index"
130
89
 
131
90
  # The name of your cluster if you set it on the Elasticsearch side. Useful
132
91
  # for discovery when using `node` or `transport` protocols.
@@ -134,53 +93,6 @@ class LogStash::Outputs::ElasticSearchJava < LogStash::Outputs::Base
134
93
  # Equivalent to the Elasticsearch option 'cluster.name'
135
94
  config :cluster, :validate => :string
136
95
 
137
- # For the `node` protocol, if you do not specify `host`, it will attempt to use
138
- # multicast discovery to connect to Elasticsearch. If http://www.elastic.co/guide/en/elasticsearch/guide/current/_important_configuration_changes.html#_prefer_unicast_over_multicast[multicast is disabled] in Elasticsearch,
139
- # you must include the hostname or IP address of the host(s) to use for Elasticsearch unicast discovery.
140
- # Remember the `node` protocol uses the http://www.elastic.co/guide/en/elasticsearch/reference/current/modules-transport.html#modules-transport[transport] address (eg. 9300, not 9200).
141
- # `"127.0.0.1"`
142
- # `["127.0.0.1:9300","127.0.0.2:9300"]`
143
- # When setting hosts for `node` protocol, it is important to confirm that at least one non-client
144
- # node is listed in the `host` list. Also keep in mind that the `host` parameter when used with
145
- # the `node` protocol is for *discovery purposes only* (not for load balancing). When multiple hosts
146
- # are specified, it will contact the first host to see if it can use it to discover the cluster. If not,
147
- # then it will contact the second host in the list and so forth. With the `node` protocol,
148
- # Logstash will join the Elasticsearch cluster as a node client (which has a copy of the cluster
149
- # state) and this node client is the one that will automatically handle the load balancing of requests
150
- # across data nodes in the cluster.
151
- # If you are looking for a high availability setup, our recommendation is to use the `transport` protocol (below),
152
- # set up multiple http://www.elastic.co/guide/en/elasticsearch/reference/current/modules-node.html[client nodes] and list the client nodes in the `host` parameter.
153
- #
154
- # For the `transport` protocol, it will load balance requests across the hosts specified in the `host` parameter.
155
- # Remember the `transport` protocol uses the http://www.elastic.co/guide/en/elasticsearch/reference/current/modules-transport.html#modules-transport[transport] address (eg. 9300, not 9200).
156
- # `"127.0.0.1"`
157
- # `["127.0.0.1:9300","127.0.0.2:9300"]`
158
- # There is also a `sniffing` option (see below) that can be used with the transport protocol to instruct it to use the host to sniff for
159
- # "alive" nodes in the cluster and automatically use it as the hosts list (but will skip the dedicated master nodes).
160
- # If you do not use the sniffing option, it is important to exclude http://www.elastic.co/guide/en/elasticsearch/reference/current/modules-node.html[dedicated master nodes] from the `host` list
161
- # to prevent Logstash from sending bulk requests to the master nodes. So this parameter should only reference either data or client nodes.
162
- #
163
- # For the `http` protocol, it will load balance requests across the hosts specified in the `host` parameter.
164
- # Remember the `http` protocol uses the http://www.elastic.co/guide/en/elasticsearch/reference/current/modules-http.html#modules-http[http] address (eg. 9200, not 9300).
165
- # `"127.0.0.1"`
166
- # `["127.0.0.1:9200","127.0.0.2:9200"]`
167
- # It is important to exclude http://www.elastic.co/guide/en/elasticsearch/reference/current/modules-node.html[dedicated master nodes] from the `host` list
168
- # to prevent LS from sending bulk requests to the master nodes. So this parameter should only reference either data or client nodes.
169
- config :hosts, :validate => :array, :default => ["127.0.0.1"]
170
-
171
- # The port for Elasticsearch transport to use.
172
- #
173
- # If you do not set this, the following defaults are used:
174
- # * `protocol => transport` - port 9300-9305
175
- # * `protocol => node` - port 9300-9305
176
- config :port, :validate => :string, :default => "9300-9305"
177
-
178
- # The name/address of the host to bind to for Elasticsearch clustering. Equivalent to the Elasticsearch option 'network.host'
179
- # option.
180
- # This MUST be set for either protocol to work (node or transport)! The internal Elasticsearch node
181
- # will bind to this ip. This ip MUST be reachable by all nodes in the Elasticsearch cluster
182
- config :network_host, :validate => :string, :required => true
183
-
184
96
  # This sets the local port to bind to. Equivalent to the Elasticsrearch option 'transport.tcp.port'
185
97
  config :transport_tcp_port, :validate => :number
186
98
 
@@ -193,24 +105,6 @@ class LogStash::Outputs::ElasticSearchJava < LogStash::Outputs::Base
193
105
  # By default, this is generated internally by the ES client.
194
106
  config :node_name, :validate => :string
195
107
 
196
- # This plugin uses the bulk index api for improved indexing performance.
197
- # To make efficient bulk api calls, we will buffer a certain number of
198
- # events before flushing that out to Elasticsearch. This setting
199
- # controls how many events will be buffered before sending a batch
200
- # of events.
201
- config :flush_size, :validate => :number, :default => 500
202
-
203
- # The amount of time since last flush before a flush is forced.
204
- #
205
- # This setting helps ensure slow event rates don't get stuck in Logstash.
206
- # For example, if your `flush_size` is 100, and you have received 10 events,
207
- # and it has been more than `idle_flush_time` seconds since the last flush,
208
- # Logstash will flush those 10 events automatically.
209
- #
210
- # This helps keep both fast and slow log streams moving along in
211
- # near-real-time.
212
- config :idle_flush_time, :validate => :number, :default => 1
213
-
214
108
  # Choose the protocol used to talk to Elasticsearch.
215
109
  #
216
110
  # The 'node' protocol (default) will connect to the cluster as a normal Elasticsearch
@@ -231,132 +125,16 @@ class LogStash::Outputs::ElasticSearchJava < LogStash::Outputs::Base
231
125
  # All protocols will use bulk requests when talking to Elasticsearch.
232
126
  config :protocol, :validate => [ "node", "transport"], :default => "transport"
233
127
 
234
- # The Elasticsearch action to perform. Valid actions are: `index`, `delete`.
235
- #
236
- # Use of this setting *REQUIRES* you also configure the `document_id` setting
237
- # because `delete` actions all require a document id.
238
- #
239
- # What does each action do?
240
- #
241
- # - index: indexes a document (an event from Logstash).
242
- # - delete: deletes a document by id
243
- # - create: indexes a document, fails if a document by that id already exists in the index.
244
- # - update: updates a document by id
245
- # following action is not supported by HTTP protocol
246
- # - create_unless_exists: creates a document, fails if no id is provided
247
- #
248
- # For more details on actions, check out the http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/docs-bulk.html[Elasticsearch bulk API documentation]
249
- config :action, :validate => :string, :default => "index"
250
-
251
- # Validate the server's certificate
252
- # Disabling this severely compromises security
253
- # For more information read https://www.cs.utexas.edu/~shmat/shmat_ccs12.pdf
254
- config :ssl_certificate_verification, :validate => :boolean, :default => true
255
-
256
- # The .cer or .pem file to validate the server's certificate
257
- config :cacert, :validate => :path
258
-
259
- # The JKS truststore to validate the server's certificate
260
- # Use either `:truststore` or `:cacert`
261
- config :truststore, :validate => :path
262
-
263
- # Set the truststore password
264
- config :truststore_password, :validate => :password
265
-
266
- # The keystore used to present a certificate to the server
267
- # It can be either .jks or .p12
268
- config :keystore, :validate => :path
269
-
270
- # Set the truststore password
271
- config :keystore_password, :validate => :password
272
-
273
128
  # Enable cluster sniffing (transport only).
274
129
  # Asks host for the list of all cluster nodes and adds them to the hosts list
275
130
  # Equivalent to the Elasticsearch option 'client.transport.sniff'
276
131
  config :sniffing, :validate => :boolean, :default => false
277
132
 
278
- # Set max retry for each event
279
- config :max_retries, :validate => :number, :default => 3
280
-
281
- # Set retry policy for events that failed to send
282
- config :retry_max_items, :validate => :number, :default => 5000
283
-
284
- # Set max interval between bulk retries
285
- config :retry_max_interval, :validate => :number, :default => 5
286
-
287
- # Enable doc_as_upsert for update mode
288
- # create a new document with source if document_id doesn't exists
289
- config :doc_as_upsert, :validate => :boolean, :default => false
290
-
291
- # Set upsert content for update mode
292
- # create a new document with this parameter as json string if document_id doesn't exists
293
- config :upsert, :validate => :string, :default => ""
294
-
295
- public
296
- def register
297
- @submit_mutex = Mutex.new
298
- # retry-specific variables
299
- @retry_flush_mutex = Mutex.new
300
- @retry_teardown_requested = Concurrent::AtomicBoolean.new(false)
301
- # needs flushing when interval
302
- @retry_queue_needs_flushing = ConditionVariable.new
303
- @retry_queue_not_full = ConditionVariable.new
304
- @retry_queue = Queue.new
305
-
306
-
307
- if @protocol =='node' && !@network_host
308
- raise LogStash::ConfigurationError, "network_host MUST be set if the 'node' protocol is in use! If this is set incorrectly Logstash will hang attempting to connect!"
309
- end
310
-
311
- if (@hosts.nil? || @hosts.empty?) && @protocol != "node" # node can use zen discovery
312
- @logger.info("No 'hosts' set in elasticsearch output. Defaulting to localhost")
313
- @hosts = ["localhost"]
314
- end
315
-
316
- client_class = case @protocol
317
- when "transport"
318
- LogStash::Outputs::ElasticSearchJavaPlugins::Protocols::TransportClient
319
- when "node"
320
- LogStash::Outputs::ElasticSearchJavaPlugins::Protocols::NodeClient
321
- end
322
-
323
- @client = client_class.new(client_options)
324
-
325
- if @manage_template
326
- begin
327
- @logger.info("Automatic template management enabled", :manage_template => @manage_template.to_s)
328
- client.template_install(@template_name, get_template, @template_overwrite)
329
- rescue => e
330
- @logger.error("Failed to install template",
331
- :message => e.message,
332
- :error_class => e.class.name,
333
- )
334
- end
335
- end
336
-
337
- @logger.info("New Elasticsearch output", :cluster => @cluster,
338
- :hosts => @host, :port => @port, :protocol => @protocol)
339
-
340
- buffer_initialize(
341
- :max_items => @flush_size,
342
- :max_interval => @idle_flush_time,
343
- :logger => @logger
344
- )
345
-
346
- @retry_timer_thread = Thread.new do
347
- loop do
348
- sleep(@retry_max_interval)
349
- @retry_flush_mutex.synchronize { @retry_queue_needs_flushing.signal }
350
- end
351
- end
352
-
353
- @retry_thread = Thread.new do
354
- while @retry_teardown_requested.false?
355
- @retry_flush_mutex.synchronize { @retry_queue_needs_flushing.wait(@retry_flush_mutex) }
356
- retry_flush
357
- end
358
- end
359
- end # def register
133
+ # The name/address of the host to bind to for Elasticsearch clustering. Equivalent to the Elasticsearch option 'network.host'
134
+ # option.
135
+ # This MUST be set for either protocol to work (node or transport)! The internal Elasticsearch node
136
+ # will bind to this ip. This ip MUST be reachable by all nodes in the Elasticsearch cluster
137
+ config :network_host, :validate => :string, :required => true
360
138
 
361
139
  def client_options
362
140
  client_settings = {}
@@ -371,16 +149,10 @@ class LogStash::Outputs::ElasticSearchJava < LogStash::Outputs::Base
371
149
  client_settings["node.name"] = "logstash-#{Socket.gethostname}-#{$$}-#{object_id}"
372
150
  end
373
151
 
374
- @@plugins.each do |plugin|
375
- name = plugin.name.split('_')[-1]
376
- client_settings.merge!(LogStash::Outputs::ElasticSearchJava.const_get(name.capitalize).create_client_config(self))
377
- end
378
-
379
- common_options = {
152
+ options = {
380
153
  :protocol => @protocol,
381
154
  :client_settings => client_settings,
382
- :hosts => @hosts,
383
- :port => @port
155
+ :hosts => @hosts
384
156
  }
385
157
 
386
158
  # Update API setup
@@ -388,155 +160,34 @@ class LogStash::Outputs::ElasticSearchJava < LogStash::Outputs::Base
388
160
  :upsert => @upsert,
389
161
  :doc_as_upsert => @doc_as_upsert
390
162
  }
391
- common_options.merge! update_options if @action == 'update'
163
+ options.merge! update_options if @action == 'update'
392
164
 
393
- common_options
165
+ options
394
166
  end
395
167
 
396
-
397
- public
398
- def get_template
399
- if @template.nil?
400
- @template = ::File.expand_path('elasticsearch_java/elasticsearch-template.json', ::File.dirname(__FILE__))
401
- if !File.exists?(@template)
402
- raise "You must specify 'template => ...' in your elasticsearch output (I looked for '#{@template}')"
403
- end
404
- end
405
- template_json = IO.read(@template).gsub(/\n/,'')
406
- template = LogStash::Json.load(template_json)
407
- @logger.info("Using mapping template", :template => template)
408
- return template
409
- end # def get_template
410
-
411
- public
412
- def receive(event)
413
-
414
-
415
- # block until we have not maxed out our
416
- # retry queue. This is applying back-pressure
417
- # to slow down the receive-rate
418
- @retry_flush_mutex.synchronize {
419
- @retry_queue_not_full.wait(@retry_flush_mutex) while @retry_queue.size > @retry_max_items
420
- }
421
-
422
- event['@metadata']['retry_count'] = 0
423
-
424
- # Set the 'type' value for the index.
425
- type = if @document_type
426
- event.sprintf(@document_type)
427
- elsif @index_type # deprecated
428
- event.sprintf(@index_type)
429
- else
430
- event["type"] || "logs"
431
- end
432
-
433
- params = {
434
- :_id => @document_id ? event.sprintf(@document_id) : nil,
435
- :_index => event.sprintf(@index),
436
- :_type => type,
437
- :_routing => @routing ? event.sprintf(@routing) : nil
438
- }
439
-
440
- params[:_upsert] = LogStash::Json.load(event.sprintf(@upsert)) if @action == 'update' && @upsert != ""
441
-
442
- buffer_receive([event.sprintf(@action), params, event])
443
- end # def receive
444
-
445
- public
446
- # The submit method can be called from both the
447
- # Stud::Buffer flush thread and from our own retry thread.
448
- def submit(actions)
449
- es_actions = actions.map { |a, doc, event| [a, doc, event.to_hash] }
450
- @submit_mutex.lock
451
- begin
452
- bulk_response = @client.bulk(es_actions)
453
- ensure
454
- @submit_mutex.unlock
455
- end
456
- if bulk_response["errors"]
457
- actions_with_responses = actions.zip(bulk_response['statuses'])
458
- actions_to_retry = []
459
- actions_with_responses.each do |action, resp_code|
460
- if RETRYABLE_CODES.include?(resp_code)
461
- @logger.warn "retrying failed action with response code: #{resp_code}"
462
- actions_to_retry << action
463
- elsif not SUCCESS_CODES.include?(resp_code)
464
- @logger.warn "failed action with response of #{resp_code}, dropping action: #{action}"
465
- end
466
- end
467
- retry_push(actions_to_retry) unless actions_to_retry.empty?
468
- end
168
+ def build_client
169
+ @client = client_class.new(client_options)
469
170
  end
470
171
 
471
- # When there are exceptions raised upon submission, we raise an exception so that
472
- # Stud::Buffer will retry to flush
473
- public
474
- def flush(actions, teardown = false)
475
- begin
476
- submit(actions)
477
- rescue => e
478
- @logger.error "Got error to send bulk of actions: #{e.message}"
479
- raise e
480
- end
481
- end # def flush
482
-
483
- public
484
172
  def close
485
- @retry_teardown_requested.make_true
486
- # First, make sure retry_timer_thread is stopped
487
- # to ensure we do not signal a retry based on
488
- # the retry interval.
489
- Thread.kill(@retry_timer_thread)
490
- @retry_timer_thread.join
491
- # Signal flushing in the case that #retry_flush is in
492
- # the process of waiting for a signal.
493
- @retry_flush_mutex.synchronize { @retry_queue_needs_flushing.signal }
494
- # Now, #retry_flush is ensured to not be in a state of
495
- # waiting and can be safely joined into the main thread
496
- # for further final execution of an in-process remaining call.
497
- @retry_thread.join
498
-
499
- # execute any final actions along with a proceeding retry for any
500
- # final actions that did not succeed.
501
- buffer_flush(:final => true)
502
- retry_flush
173
+ @stopping.make_true
174
+ @buffer.stop
503
175
  end
504
176
 
505
- private
506
- # in charge of submitting any actions in @retry_queue that need to be
507
- # retried
508
- #
509
- # This method is not called concurrently. It is only called by @retry_thread
510
- # and once that thread is ended during the teardown process, a final call
511
- # to this method is done upon teardown in the main thread.
512
- def retry_flush()
513
- unless @retry_queue.empty?
514
- buffer = @retry_queue.size.times.map do
515
- next_action, next_doc, next_event = @retry_queue.pop
516
- next_event['@metadata']['retry_count'] += 1
517
-
518
- if next_event['@metadata']['retry_count'] > @max_retries
519
- @logger.error "too many attempts at sending event. dropping: #{next_event}"
520
- nil
521
- else
522
- [next_action, next_doc, next_event]
523
- end
524
- end.compact
525
-
526
- submit(buffer) unless buffer.empty?
177
+ def get_plugin_options
178
+ @@plugins.each do |plugin|
179
+ name = plugin.name.split('-')[-1]
180
+ client_settings.merge!(LogStash::Outputs::ElasticSearchJava.const_get(name.capitalize).create_client_config(self))
527
181
  end
528
-
529
- @retry_flush_mutex.synchronize {
530
- @retry_queue_not_full.signal if @retry_queue.size < @retry_max_items
531
- }
532
182
  end
533
183
 
534
- private
535
- def retry_push(actions)
536
- Array(actions).each{|action| @retry_queue << action}
537
- @retry_flush_mutex.synchronize {
538
- @retry_queue_needs_flushing.signal if @retry_queue.size >= @retry_max_items
539
- }
184
+ def client_class
185
+ case @protocol
186
+ when "transport"
187
+ LogStash::Outputs::ElasticSearchJavaPlugins::Protocols::TransportClient
188
+ when "node"
189
+ LogStash::Outputs::ElasticSearchJavaPlugins::Protocols::NodeClient
190
+ end
540
191
  end
541
192
 
542
193
  @@plugins = Gem::Specification.find_all{|spec| spec.name =~ /logstash-output-elasticsearch_java_/ }