logstash-output-elasticsearch_java 1.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +5 -0
  3. data/CHANGELOG.md +2 -0
  4. data/CONTRIBUTORS +31 -0
  5. data/Gemfile +3 -0
  6. data/LICENSE +13 -0
  7. data/NOTICE.TXT +5 -0
  8. data/README.md +98 -0
  9. data/Rakefile +1 -0
  10. data/lib/logstash/outputs/elasticsearch_java/elasticsearch-template.json +41 -0
  11. data/lib/logstash/outputs/elasticsearch_java/protocol.rb +258 -0
  12. data/lib/logstash/outputs/elasticsearch_java.rb +545 -0
  13. data/lib/logstash-output-elasticsearch_java_jars.rb +5 -0
  14. data/logstash-output-elasticsearch_java.gemspec +32 -0
  15. data/spec/es_spec_helper.rb +81 -0
  16. data/spec/integration/outputs/elasticsearch/node_spec.rb +36 -0
  17. data/spec/integration/outputs/index_spec.rb +90 -0
  18. data/spec/integration/outputs/retry_spec.rb +148 -0
  19. data/spec/integration/outputs/routing_spec.rb +60 -0
  20. data/spec/integration/outputs/secure_spec.rb +113 -0
  21. data/spec/integration/outputs/templates_spec.rb +97 -0
  22. data/spec/integration/outputs/transport_create_spec.rb +94 -0
  23. data/spec/integration/outputs/update_spec.rb +88 -0
  24. data/spec/unit/outputs/elasticsearch/protocol_spec.rb +32 -0
  25. data/spec/unit/outputs/elasticsearch_spec.rb +79 -0
  26. data/vendor/jar-dependencies/runtime-jars/antlr-runtime-3.5.jar +0 -0
  27. data/vendor/jar-dependencies/runtime-jars/asm-4.1.jar +0 -0
  28. data/vendor/jar-dependencies/runtime-jars/asm-commons-4.1.jar +0 -0
  29. data/vendor/jar-dependencies/runtime-jars/elasticsearch-1.7.0.jar +0 -0
  30. data/vendor/jar-dependencies/runtime-jars/lucene-analyzers-common-4.10.4.jar +0 -0
  31. data/vendor/jar-dependencies/runtime-jars/lucene-core-4.10.4.jar +0 -0
  32. data/vendor/jar-dependencies/runtime-jars/lucene-grouping-4.10.4.jar +0 -0
  33. data/vendor/jar-dependencies/runtime-jars/lucene-highlighter-4.10.4.jar +0 -0
  34. data/vendor/jar-dependencies/runtime-jars/lucene-join-4.10.4.jar +0 -0
  35. data/vendor/jar-dependencies/runtime-jars/lucene-memory-4.10.4.jar +0 -0
  36. data/vendor/jar-dependencies/runtime-jars/lucene-misc-4.10.4.jar +0 -0
  37. data/vendor/jar-dependencies/runtime-jars/lucene-queries-4.10.4.jar +0 -0
  38. data/vendor/jar-dependencies/runtime-jars/lucene-queryparser-4.10.4.jar +0 -0
  39. data/vendor/jar-dependencies/runtime-jars/lucene-sandbox-4.10.4.jar +0 -0
  40. data/vendor/jar-dependencies/runtime-jars/lucene-spatial-4.10.4.jar +0 -0
  41. data/vendor/jar-dependencies/runtime-jars/lucene-suggest-4.10.4.jar +0 -0
  42. data/vendor/jar-dependencies/runtime-jars/spatial4j-0.4.1.jar +0 -0
  43. metadata +241 -0
@@ -0,0 +1,88 @@
1
+ require_relative "../../../spec/es_spec_helper"
2
+
3
+ describe "all protocols update actions", :integration => true do
4
+ require "logstash/outputs/elasticsearch_java"
5
+ require "elasticsearch"
6
+
7
+ def get_es_output( protocol, id = nil, upsert = nil, doc_as_upsert=nil)
8
+ settings = {
9
+ "manage_template" => true,
10
+ "index" => "logstash-update",
11
+ "template_overwrite" => true,
12
+ "protocol" => protocol,
13
+ "hosts" => get_host(),
14
+ "port" => get_port(protocol),
15
+ "action" => "update"
16
+ }
17
+ settings['upsert'] = upsert unless upsert.nil?
18
+ settings['document_id'] = id unless id.nil?
19
+ settings['doc_as_upsert'] = doc_as_upsert unless doc_as_upsert.nil?
20
+
21
+ LogStash::Outputs::ElasticSearchJava.new(settings)
22
+ end
23
+
24
+ before :each do
25
+ @es = get_client
26
+ # Delete all templates first.
27
+ # Clean ES of data before we start.
28
+ @es.indices.delete_template(:name => "*")
29
+ # This can fail if there are no indexes, ignore failure.
30
+ @es.indices.delete(:index => "*") rescue nil
31
+ @es.index(
32
+ :index => 'logstash-update',
33
+ :type => 'logs',
34
+ :id => "123",
35
+ :body => { :message => 'Test' }
36
+ )
37
+ @es.indices.refresh
38
+ end
39
+
40
+ ["node", "transport"].each do |protocol|
41
+ context "update only with #{protocol} protocol" do
42
+ it "should failed without a document_id" do
43
+ event = LogStash::Event.new("somevalue" => 100, "@timestamp" => "2014-11-17T20:37:17.223Z", "@metadata" => {"retry_count" => 0})
44
+ action = ["update", {:_id=>nil, :_index=>"logstash-2014.11.17", :_type=>"logs"}, event]
45
+ subject = get_es_output(protocol)
46
+ subject.register
47
+ expect { subject.flush([action]) }.to raise_error
48
+ end
49
+
50
+ it "should not create new document" do
51
+ subject = get_es_output(protocol, "456")
52
+ subject.register
53
+ subject.receive(LogStash::Event.new("message" => "sample message here"))
54
+ subject.buffer_flush(:final => true)
55
+ expect {@es.get(:index => 'logstash-update', :type => 'logs', :id => "456", :refresh => true)}.to raise_error(Elasticsearch::Transport::Transport::Errors::NotFound)
56
+ end
57
+
58
+ it "should update existing document" do
59
+ subject = get_es_output(protocol, "123")
60
+ subject.register
61
+ subject.receive(LogStash::Event.new("message" => "updated message here"))
62
+ subject.buffer_flush(:final => true)
63
+ r = @es.get(:index => 'logstash-update', :type => 'logs', :id => "123", :refresh => true)
64
+ insist { r["_source"]["message"] } == 'updated message here'
65
+ end
66
+ end
67
+
68
+ context "upsert with #{protocol} protocol" do
69
+ it "should create new documents with upsert content" do
70
+ subject = get_es_output(protocol, "456", '{"message": "upsert message"}')
71
+ subject.register
72
+ subject.receive(LogStash::Event.new("message" => "sample message here"))
73
+ subject.buffer_flush(:final => true)
74
+ r = @es.get(:index => 'logstash-update', :type => 'logs', :id => "456", :refresh => true)
75
+ insist { r["_source"]["message"] } == 'upsert message'
76
+ end
77
+
78
+ it "should create new documents with event/doc as upsert" do
79
+ subject = get_es_output(protocol, "456", nil, true)
80
+ subject.register
81
+ subject.receive(LogStash::Event.new("message" => "sample message here"))
82
+ subject.buffer_flush(:final => true)
83
+ r = @es.get(:index => 'logstash-update', :type => 'logs', :id => "456", :refresh => true)
84
+ insist { r["_source"]["message"] } == 'sample message here'
85
+ end
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,32 @@
1
+ require "logstash/devutils/rspec/spec_helper"
2
+ require "logstash/outputs/elasticsearch_java/protocol"
3
+ require "java"
4
+
5
+ describe LogStash::Outputs::ElasticSearchJavaPlugins::Protocols::NodeClient do
6
+ context "successful" do
7
+ it "should map correctly" do
8
+ index_response = org.elasticsearch.action.index.IndexResponse.new("my_index", "my_type", "my_id", 123, true)
9
+ update_response = org.elasticsearch.action.update.UpdateResponse.new("my_index", "my_type", "my_id", 123, false)
10
+ delete_response = org.elasticsearch.action.delete.DeleteResponse.new("my_index", "my_type", "my_id", 123, true)
11
+ bulk_item_response_index = org.elasticsearch.action.bulk.BulkItemResponse.new(32, "index", index_response)
12
+ bulk_item_response_update = org.elasticsearch.action.bulk.BulkItemResponse.new(32, "update", update_response)
13
+ bulk_item_response_delete = org.elasticsearch.action.bulk.BulkItemResponse.new(32, "delete", delete_response)
14
+ bulk_response = org.elasticsearch.action.bulk.BulkResponse.new([bulk_item_response_index, bulk_item_response_update, bulk_item_response_delete], 0)
15
+ ret = LogStash::Outputs::ElasticSearchJavaPlugins::Protocols::NodeClient.normalize_bulk_response(bulk_response)
16
+ insist { ret } == {"errors" => false}
17
+ end
18
+ end
19
+
20
+ context "contains failures" do
21
+ it "should map correctly" do
22
+ failure = org.elasticsearch.action.bulk.BulkItemResponse::Failure.new("my_index", "my_type", "my_id", java.lang.IllegalArgumentException.new("bad_request"))
23
+ failure_code = failure.get_status.status
24
+ bulk_item_response_index = org.elasticsearch.action.bulk.BulkItemResponse.new(32, "index", failure)
25
+ bulk_item_response_update = org.elasticsearch.action.bulk.BulkItemResponse.new(32, "update", failure)
26
+ bulk_item_response_delete = org.elasticsearch.action.bulk.BulkItemResponse.new(32, "delete", failure)
27
+ bulk_response = org.elasticsearch.action.bulk.BulkResponse.new([bulk_item_response_index, bulk_item_response_update, bulk_item_response_delete], 0)
28
+ actual = LogStash::Outputs::ElasticSearchJavaPlugins::Protocols::NodeClient.normalize_bulk_response(bulk_response)
29
+ insist { actual } == {"errors" => true, "statuses" => [failure_code, failure_code, failure_code]}
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,79 @@
1
+ require_relative "../../../spec/es_spec_helper"
2
+
3
+ describe "outputs/elasticsearch_java" do
4
+ context "registration" do
5
+ it "should register" do
6
+ output = LogStash::Plugin.lookup("output", "elasticsearch_java").new("protocol" => "transport", "manage_template" => "false")
7
+ # register will try to load jars and raise if it cannot find jars
8
+ expect {output.register}.to_not raise_error
9
+ end
10
+ end
11
+
12
+ describe "transport protocol" do
13
+ context "host not configured" do
14
+ subject do
15
+ require "logstash/outputs/elasticsearch_java"
16
+ settings = {
17
+ "protocol" => "transport",
18
+ "node_name" => "mynode"
19
+ }
20
+ next LogStash::Outputs::ElasticSearchJava.new(settings)
21
+ end
22
+
23
+ it "should set host to localhost" do
24
+ expect(LogStash::Outputs::ElasticSearchJavaPlugins::Protocols::TransportClient).to receive(:new).with({
25
+ :hosts => ["127.0.0.1"],
26
+ :port => "9300-9305",
27
+ :protocol => "transport",
28
+ :client_settings => {
29
+ "client.transport.sniff" => false,
30
+ "node.name" => "mynode"
31
+ }
32
+ })
33
+ subject.register
34
+ end
35
+ end
36
+
37
+ context "sniffing => true" do
38
+ subject do
39
+ require "logstash/outputs/elasticsearch_java"
40
+ settings = {
41
+ "hosts" => "node01",
42
+ "protocol" => "transport",
43
+ "sniffing" => true
44
+ }
45
+ next LogStash::Outputs::ElasticSearchJava.new(settings)
46
+ end
47
+
48
+ it "should set the sniffing property to true" do
49
+ allow_any_instance_of(LogStash::Outputs::ElasticSearchJavaPlugins::Protocols::NodeClient).to receive(:client).and_return(nil)
50
+ subject.register
51
+ client = subject.instance_eval("@client")
52
+ settings = client.instance_eval("@settings")
53
+
54
+ expect(settings.build.get("client.transport.sniff")).to eq("true")
55
+ end
56
+ end
57
+
58
+ context "sniffing => false" do
59
+ subject do
60
+ require "logstash/outputs/elasticsearch_java"
61
+ settings = {
62
+ "hosts" => "node01",
63
+ "protocol" => "transport",
64
+ "sniffing" => false
65
+ }
66
+ next LogStash::Outputs::ElasticSearchJava.new(settings)
67
+ end
68
+
69
+ it "should set the sniffing property to true" do
70
+ allow_any_instance_of(LogStash::Outputs::ElasticSearchJavaPlugins::Protocols::NodeClient).to receive(:client).and_return(nil)
71
+ subject.register
72
+ client = subject.instance_eval("@client")
73
+ settings = client.instance_eval("@settings")
74
+
75
+ expect(settings.build.getAsMap["client.transport.sniff"]).to eq("false")
76
+ end
77
+ end
78
+ end
79
+ end
metadata ADDED
@@ -0,0 +1,241 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: logstash-output-elasticsearch_java
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0.beta1
5
+ platform: ruby
6
+ authors:
7
+ - Elastic
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-09-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '0'
19
+ name: concurrent-ruby
20
+ prerelease: false
21
+ type: :runtime
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 1.0.10
33
+ - - "~>"
34
+ - !ruby/object:Gem::Version
35
+ version: '1.0'
36
+ name: elasticsearch
37
+ prerelease: false
38
+ type: :runtime
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 1.0.10
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '1.0'
47
+ - !ruby/object:Gem::Dependency
48
+ requirement: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 0.0.17
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '0.0'
56
+ name: stud
57
+ prerelease: false
58
+ type: :runtime
59
+ version_requirements: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: 0.0.17
64
+ - - "~>"
65
+ - !ruby/object:Gem::Version
66
+ version: '0.0'
67
+ - !ruby/object:Gem::Dependency
68
+ requirement: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - "~>"
71
+ - !ruby/object:Gem::Version
72
+ version: '0.6'
73
+ name: cabin
74
+ prerelease: false
75
+ type: :runtime
76
+ version_requirements: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - "~>"
79
+ - !ruby/object:Gem::Version
80
+ version: '0.6'
81
+ - !ruby/object:Gem::Dependency
82
+ requirement: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: 1.4.0
87
+ - - "<"
88
+ - !ruby/object:Gem::Version
89
+ version: 2.0.0
90
+ name: logstash-core
91
+ prerelease: false
92
+ type: :runtime
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: 1.4.0
98
+ - - "<"
99
+ - !ruby/object:Gem::Version
100
+ version: 2.0.0
101
+ - !ruby/object:Gem::Dependency
102
+ requirement: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - "~>"
105
+ - !ruby/object:Gem::Version
106
+ version: 0.0.42
107
+ name: ftw
108
+ prerelease: false
109
+ type: :development
110
+ version_requirements: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - "~>"
113
+ - !ruby/object:Gem::Version
114
+ version: 0.0.42
115
+ - !ruby/object:Gem::Dependency
116
+ requirement: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ name: logstash-input-generator
122
+ prerelease: false
123
+ type: :development
124
+ version_requirements: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ - !ruby/object:Gem::Dependency
130
+ requirement: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ name: logstash-devutils
136
+ prerelease: false
137
+ type: :development
138
+ version_requirements: !ruby/object:Gem::Requirement
139
+ requirements:
140
+ - - ">="
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
143
+ - !ruby/object:Gem::Dependency
144
+ requirement: !ruby/object:Gem::Requirement
145
+ requirements:
146
+ - - ">="
147
+ - !ruby/object:Gem::Version
148
+ version: '0'
149
+ name: longshoreman
150
+ prerelease: false
151
+ type: :development
152
+ version_requirements: !ruby/object:Gem::Requirement
153
+ requirements:
154
+ - - ">="
155
+ - !ruby/object:Gem::Version
156
+ version: '0'
157
+ description: Output events to elasticsearch using the java client
158
+ email: info@elastic.co
159
+ executables: []
160
+ extensions: []
161
+ extra_rdoc_files: []
162
+ files:
163
+ - ".gitignore"
164
+ - CHANGELOG.md
165
+ - CONTRIBUTORS
166
+ - Gemfile
167
+ - LICENSE
168
+ - NOTICE.TXT
169
+ - README.md
170
+ - Rakefile
171
+ - lib/logstash-output-elasticsearch_java_jars.rb
172
+ - lib/logstash/outputs/elasticsearch_java.rb
173
+ - lib/logstash/outputs/elasticsearch_java/elasticsearch-template.json
174
+ - lib/logstash/outputs/elasticsearch_java/protocol.rb
175
+ - logstash-output-elasticsearch_java.gemspec
176
+ - spec/es_spec_helper.rb
177
+ - spec/integration/outputs/elasticsearch/node_spec.rb
178
+ - spec/integration/outputs/index_spec.rb
179
+ - spec/integration/outputs/retry_spec.rb
180
+ - spec/integration/outputs/routing_spec.rb
181
+ - spec/integration/outputs/secure_spec.rb
182
+ - spec/integration/outputs/templates_spec.rb
183
+ - spec/integration/outputs/transport_create_spec.rb
184
+ - spec/integration/outputs/update_spec.rb
185
+ - spec/unit/outputs/elasticsearch/protocol_spec.rb
186
+ - spec/unit/outputs/elasticsearch_spec.rb
187
+ - vendor/jar-dependencies/runtime-jars/antlr-runtime-3.5.jar
188
+ - vendor/jar-dependencies/runtime-jars/asm-4.1.jar
189
+ - vendor/jar-dependencies/runtime-jars/asm-commons-4.1.jar
190
+ - vendor/jar-dependencies/runtime-jars/elasticsearch-1.7.0.jar
191
+ - vendor/jar-dependencies/runtime-jars/lucene-analyzers-common-4.10.4.jar
192
+ - vendor/jar-dependencies/runtime-jars/lucene-core-4.10.4.jar
193
+ - vendor/jar-dependencies/runtime-jars/lucene-grouping-4.10.4.jar
194
+ - vendor/jar-dependencies/runtime-jars/lucene-highlighter-4.10.4.jar
195
+ - vendor/jar-dependencies/runtime-jars/lucene-join-4.10.4.jar
196
+ - vendor/jar-dependencies/runtime-jars/lucene-memory-4.10.4.jar
197
+ - vendor/jar-dependencies/runtime-jars/lucene-misc-4.10.4.jar
198
+ - vendor/jar-dependencies/runtime-jars/lucene-queries-4.10.4.jar
199
+ - vendor/jar-dependencies/runtime-jars/lucene-queryparser-4.10.4.jar
200
+ - vendor/jar-dependencies/runtime-jars/lucene-sandbox-4.10.4.jar
201
+ - vendor/jar-dependencies/runtime-jars/lucene-spatial-4.10.4.jar
202
+ - vendor/jar-dependencies/runtime-jars/lucene-suggest-4.10.4.jar
203
+ - vendor/jar-dependencies/runtime-jars/spatial4j-0.4.1.jar
204
+ homepage: http://logstash.net/
205
+ licenses:
206
+ - apache-2.0
207
+ metadata:
208
+ logstash_plugin: 'true'
209
+ logstash_group: output
210
+ post_install_message:
211
+ rdoc_options: []
212
+ require_paths:
213
+ - lib
214
+ required_ruby_version: !ruby/object:Gem::Requirement
215
+ requirements:
216
+ - - ">="
217
+ - !ruby/object:Gem::Version
218
+ version: '0'
219
+ required_rubygems_version: !ruby/object:Gem::Requirement
220
+ requirements:
221
+ - - ">"
222
+ - !ruby/object:Gem::Version
223
+ version: 1.3.1
224
+ requirements: []
225
+ rubyforge_project:
226
+ rubygems_version: 2.4.8
227
+ signing_key:
228
+ specification_version: 4
229
+ summary: Logstash Output to Elasticsearch using Java node/transport client
230
+ test_files:
231
+ - spec/es_spec_helper.rb
232
+ - spec/integration/outputs/elasticsearch/node_spec.rb
233
+ - spec/integration/outputs/index_spec.rb
234
+ - spec/integration/outputs/retry_spec.rb
235
+ - spec/integration/outputs/routing_spec.rb
236
+ - spec/integration/outputs/secure_spec.rb
237
+ - spec/integration/outputs/templates_spec.rb
238
+ - spec/integration/outputs/transport_create_spec.rb
239
+ - spec/integration/outputs/update_spec.rb
240
+ - spec/unit/outputs/elasticsearch/protocol_spec.rb
241
+ - spec/unit/outputs/elasticsearch_spec.rb