logstash-output-elasticsearch 1.1.0-java → 2.0.0.beta4-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/CHANGELOG.md +10 -3
  4. data/README.md +4 -4
  5. data/lib/logstash/outputs/elasticsearch/http_client.rb +144 -0
  6. data/lib/logstash/outputs/elasticsearch.rb +93 -319
  7. data/logstash-output-elasticsearch.gemspec +1 -3
  8. data/spec/es_spec_helper.rb +38 -34
  9. data/spec/integration/outputs/create_spec.rb +56 -0
  10. data/spec/integration/outputs/index_spec.rb +5 -7
  11. data/spec/integration/outputs/retry_spec.rb +118 -126
  12. data/spec/integration/outputs/routing_spec.rb +5 -33
  13. data/spec/integration/outputs/secure_spec.rb +4 -9
  14. data/spec/integration/outputs/templates_spec.rb +85 -91
  15. data/spec/integration/outputs/update_spec.rb +41 -46
  16. data/spec/unit/outputs/elasticsearch/protocol_spec.rb +45 -36
  17. data/spec/unit/outputs/elasticsearch_proxy_spec.rb +3 -4
  18. data/spec/unit/outputs/elasticsearch_spec.rb +2 -151
  19. data/spec/unit/outputs/elasticsearch_ssl_spec.rb +38 -63
  20. metadata +67 -101
  21. data/lib/logstash/outputs/elasticsearch/protocol.rb +0 -333
  22. data/lib/logstash-output-elasticsearch_jars.rb +0 -5
  23. data/spec/integration/outputs/elasticsearch/node_spec.rb +0 -36
  24. data/spec/integration/outputs/transport_create_spec.rb +0 -94
  25. data/vendor/jar-dependencies/runtime-jars/antlr-runtime-3.5.jar +0 -0
  26. data/vendor/jar-dependencies/runtime-jars/asm-4.1.jar +0 -0
  27. data/vendor/jar-dependencies/runtime-jars/asm-commons-4.1.jar +0 -0
  28. data/vendor/jar-dependencies/runtime-jars/elasticsearch-1.7.0.jar +0 -0
  29. data/vendor/jar-dependencies/runtime-jars/lucene-analyzers-common-4.10.4.jar +0 -0
  30. data/vendor/jar-dependencies/runtime-jars/lucene-core-4.10.4.jar +0 -0
  31. data/vendor/jar-dependencies/runtime-jars/lucene-grouping-4.10.4.jar +0 -0
  32. data/vendor/jar-dependencies/runtime-jars/lucene-highlighter-4.10.4.jar +0 -0
  33. data/vendor/jar-dependencies/runtime-jars/lucene-join-4.10.4.jar +0 -0
  34. data/vendor/jar-dependencies/runtime-jars/lucene-memory-4.10.4.jar +0 -0
  35. data/vendor/jar-dependencies/runtime-jars/lucene-misc-4.10.4.jar +0 -0
  36. data/vendor/jar-dependencies/runtime-jars/lucene-queries-4.10.4.jar +0 -0
  37. data/vendor/jar-dependencies/runtime-jars/lucene-queryparser-4.10.4.jar +0 -0
  38. data/vendor/jar-dependencies/runtime-jars/lucene-sandbox-4.10.4.jar +0 -0
  39. data/vendor/jar-dependencies/runtime-jars/lucene-spatial-4.10.4.jar +0 -0
  40. data/vendor/jar-dependencies/runtime-jars/lucene-suggest-4.10.4.jar +0 -0
  41. 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: 21f30a9fb4fae09d20c43211c4a47a38a99892d0
4
- data.tar.gz: c8a82c32a338ecc12109b251efab824707770429
3
+ metadata.gz: f3ed085b4e52cb51518cbcb5329a304fad4a33de
4
+ data.tar.gz: 028096af0d9e7e78c244e1234671e7424bfeefb6
5
5
  SHA512:
6
- metadata.gz: 1db3b07141dd557c7fcd34dfcfe64fb7705c9c776faf5a9455c6417be00cd23b20e2e267dbcbdbd7477d3c54ac80ea30a65cfe69482722c98ad3505d934ef97b
7
- data.tar.gz: cc2c42fd9b8af5caab9b6b15d957d988c7f0c748da737d9449abcd8202ef6f41ac8148c7f77c32a5b92641e43b3a334654f636a0541230f21375aab5820d4c67
6
+ metadata.gz: bd51e7fa9bcbcb2abd77f0cc8ddffba9231204a02c229e4a3ec041f9d5b88bed41c9752669807c18896030627dc70acf8af08c877cad9573ddca383992774bc3
7
+ data.tar.gz: 6556604b6d5303874ae953a1ddc5c74409f523811e888a67ebd00b7f1fd3a4a54c14bf51aa9f37dab5e309f71f28f19c692beeffe2b5d3c104215016c4376043
data/.gitignore CHANGED
@@ -3,3 +3,4 @@ Gemfile.lock
3
3
  .bundle
4
4
  .idea
5
5
  *~
6
+ .ruby-version
data/CHANGELOG.md CHANGED
@@ -1,6 +1,13 @@
1
- ## 1.1.0
2
- - Add timeout setting.
3
-
1
+ ## 2.0.0-beta2
2
+ - Massive internal refactor of client handling
3
+ - Background HTTP sniffing support
4
+ - Reduced bulk request size to 500 from 5000 (better memory utilization)
5
+ - Removed 'host' config option. Now use 'hosts'
6
+
7
+ ## 2.0.0-beta
8
+ - Only support HTTP Protocol
9
+ - Removed support for node and transport protocols (now in logstash-output-elasticsearch_java)
10
+
4
11
  ## 1.0.7
5
12
  - Add update API support
6
13
 
data/README.md CHANGED
@@ -1,15 +1,15 @@
1
1
  # Logstash Plugin
2
2
 
3
- This is a plugin for [Logstash](https://github.com/elasticsearch/logstash).
3
+ This is a plugin for [Logstash](https://github.com/elastic/logstash).
4
4
 
5
5
  It is fully free and fully open source. The license is Apache 2.0, meaning you are pretty much free to use it however you want in whatever way.
6
6
 
7
7
  ## Documentation
8
8
 
9
- Logstash provides infrastructure to automatically generate documentation for this plugin. We use the asciidoc format to write documentation so any comments in the source code will be first converted into asciidoc and then into html. All plugin documentation are placed under one [central location](http://www.elasticsearch.org/guide/en/logstash/current/).
9
+ Logstash provides infrastructure to automatically generate documentation for this plugin. We use the asciidoc format to write documentation so any comments in the source code will be first converted into asciidoc and then into html. All plugin documentation are placed under one [central location](http://www.elastic.co/guide/en/logstash/current/).
10
10
 
11
11
  - For formatting code or config example, you can use the asciidoc `[source,ruby]` directive
12
- - For more asciidoc formatting tips, see the excellent reference here https://github.com/elasticsearch/docs#asciidoc-guide
12
+ - For more asciidoc formatting tips, see the excellent reference here https://github.com/elastic/docs#asciidoc-guide
13
13
 
14
14
  ## Need Help?
15
15
 
@@ -95,4 +95,4 @@ Programming is not a required skill. Whatever you've seen about open source and
95
95
 
96
96
  It is more important to the community that you are able to contribute.
97
97
 
98
- For more information about contributing, see the [CONTRIBUTING](https://github.com/elasticsearch/logstash/blob/master/CONTRIBUTING.md) file.
98
+ For more information about contributing, see the [CONTRIBUTING](https://github.com/elastic/logstash/blob/master/CONTRIBUTING.md) file.
@@ -0,0 +1,144 @@
1
+ require "logstash/outputs/elasticsearch"
2
+ require "cabin"
3
+ require "base64"
4
+ require "elasticsearch"
5
+ require "elasticsearch/transport/transport/http/manticore"
6
+
7
+ module LogStash::Outputs::Elasticsearch
8
+ class HttpClient
9
+ attr_reader :client, :options, :client_options, :sniffer_thread
10
+ DEFAULT_OPTIONS = {
11
+ :port => 9200
12
+ }
13
+
14
+ def initialize(options={})
15
+ @logger = Cabin::Channel.get
16
+ @options = DEFAULT_OPTIONS.merge(options)
17
+ @client = build_client(@options)
18
+ start_sniffing!
19
+ end
20
+
21
+ def template_install(name, template, force=false)
22
+ if template_exists?(name) && !force
23
+ @logger.debug("Found existing Elasticsearch template. Skipping template management", :name => name)
24
+ return
25
+ end
26
+ template_put(name, template)
27
+ end
28
+
29
+ def bulk(actions)
30
+ bulk_body = actions.collect do |action, args, source|
31
+ if action == 'update'
32
+ if args[:_id]
33
+ source = { 'doc' => source }
34
+ if @options[:doc_as_upsert]
35
+ source['doc_as_upsert'] = true
36
+ else
37
+ source['upsert'] = args[:_upsert] if args[:_upsert]
38
+ end
39
+ else
40
+ raise(LogStash::ConfigurationError, "Specifying action => 'update' without a document '_id' is not supported.")
41
+ end
42
+ end
43
+
44
+ args.delete(:_upsert)
45
+
46
+ if source
47
+ next [ { action => args }, source ]
48
+ else
49
+ next { action => args }
50
+ end
51
+ end.flatten
52
+
53
+ bulk_response = @client.bulk(:body => bulk_body)
54
+
55
+ self.class.normalize_bulk_response(bulk_response)
56
+ end
57
+
58
+ def start_sniffing!
59
+ if options[:sniffing]
60
+ @sniffer_thread = Thread.new do
61
+ loop do
62
+ sniff!
63
+ sleep (options[:sniffing_delay].to_f || 30)
64
+ end
65
+ end
66
+ end
67
+ end
68
+
69
+ def stop_sniffing!
70
+ @sniffer_thread.kill() if @sniffer_thread
71
+ end
72
+
73
+ def sniff!
74
+ client.transport.reload_connections! if options[:sniffing]
75
+ rescue StandardError => e
76
+ @logger.error("Error while sniffing connection",
77
+ :message => e.message,
78
+ :class => e.class.name)
79
+ end
80
+
81
+ private
82
+
83
+ def build_client(options)
84
+ hosts = options[:hosts] || ["127.0.0.1"]
85
+ port = options[:port] || 9200
86
+ client_settings = options[:client_settings] || {}
87
+
88
+ uris = hosts.map do |host|
89
+ "http://#{host}:#{port}#{client_settings[:path]}"
90
+ end
91
+
92
+ @client_options = {
93
+ :hosts => uris,
94
+ :ssl => client_settings[:ssl],
95
+ :transport_options => { # manticore settings so we
96
+ :socket_timeout => 0, # do not timeout socket reads
97
+ :request_timeout => 0, # and requests
98
+ :proxy => client_settings[:proxy]
99
+ },
100
+ :transport_class => ::Elasticsearch::Transport::Transport::HTTP::Manticore
101
+ }
102
+
103
+ if options[:user] && options[:password] then
104
+ token = Base64.strict_encode64(options[:user] + ":" + options[:password])
105
+ @client_options[:headers] = { "Authorization" => "Basic #{token}" }
106
+ end
107
+
108
+ Elasticsearch::Client.new(client_options)
109
+ end
110
+
111
+ def self.normalize_bulk_response(bulk_response)
112
+ if bulk_response["errors"]
113
+ # The structure of the response from the REST Bulk API is follows:
114
+ # {"took"=>74, "errors"=>true, "items"=>[{"create"=>{"_index"=>"logstash-2014.11.17",
115
+ # "_type"=>"logs",
116
+ # "_id"=>"AUxTS2C55Jrgi-hC6rQF",
117
+ # "_version"=>1,
118
+ # "status"=>400,
119
+ # "error"=>"MapperParsingException[failed to parse]..."}}]}
120
+ # where each `item` is a hash of {OPTYPE => Hash[]}. calling first, will retrieve
121
+ # this hash as a single array with two elements, where the value is the second element (i.first[1])
122
+ # then the status of that item is retrieved.
123
+ {
124
+ "errors" => true,
125
+ "statuses" => bulk_response["items"].map { |i| i.first[1]['status'] },
126
+ "details" => bulk_response["items"].select {|i| i.first[1]["error"] }.map {|i| i.first[1]}
127
+ }
128
+ else
129
+ {"errors" => false}
130
+ end
131
+ end
132
+
133
+ def template_exists?(name)
134
+ @client.indices.get_template(:name => name)
135
+ return true
136
+ rescue Elasticsearch::Transport::Transport::Errors::NotFound
137
+ return false
138
+ end
139
+
140
+ def template_put(name, template)
141
+ @client.indices.put_template(:name => name, :body => template)
142
+ end
143
+ end
144
+ end