fluent-plugin-elasticsearch 1.7.0 → 1.8.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e1ce21e5b836181cdc5f32e97e4d3a91bfc31da7
4
- data.tar.gz: 77c81ab19d4749da338f481404983f1bcf8b069e
3
+ metadata.gz: f279ccf2181eb8582234fb5b417439dfd8f22ac9
4
+ data.tar.gz: e3b8e02a2aa972ac0e07971369dd9381b58401e3
5
5
  SHA512:
6
- metadata.gz: dd36dacfb1b9c7fe7c860ffe4b2ed0e7bbdd3c5803c2faef0879c7898d8d9f732860e4b54e63125b1dabf8bb7fdc66868babaec7c199b896fbb913b644ae778a
7
- data.tar.gz: 90d3c5c2b9c4af19d4c5c19d48288c92aebcb4d80cc83343a2502377f85dfef0e9ca1bf39c3de5a6065456e0a2bdc985a4f312372af2e3ad40fcd05f8df46225
6
+ metadata.gz: a576bf1cd9ff05130d1f71cabfc6b264ffc53f86cb9780af42ee0aa4f647a24905e5d41c22dd446474896bf2ee17b7ad942011bc2f6dd10cf4231fde348e35aa
7
+ data.tar.gz: b938736ba3ed0fbf8846e864c5f7273c1b059a930a4b91165d2513e6038de6bdf48968570479047dce33a7ad3fa727a02f48215d3be724a6d60414c024010ae4
data/History.md CHANGED
@@ -1,6 +1,9 @@
1
1
  ## Changelog [[tags]](https://github.com/uken/fluent-plugin-elasticsearch/tags)
2
2
 
3
- ### Future
3
+ ### [Unreleased]
4
+ - fix typo in defaults for ssl_verify on elasticsearch_dynamic (#202)
5
+ - add support for `templates` (#196)
6
+ - rename `send` method to `send_bulk` (#206)
4
7
 
5
8
  ### 1.7.0
6
9
  - add support for `template_name` and `template_file` (#194)
data/README.md CHANGED
@@ -28,6 +28,7 @@ Note: For Amazon Elasticsearch Service please consider using [fluent-plugin-aws-
28
28
  + [target_type_key](#target_type_key)
29
29
  + [template_name](#template_name)
30
30
  + [template_file](#template_file)
31
+ + [templates](#templates)
31
32
  + [request_timeout](#request_timeout)
32
33
  + [reload_connections](#reload_connections)
33
34
  + [reload_on_failure](#reload_on_failure)
@@ -240,6 +241,16 @@ The path to the file containing the template to install.
240
241
 
241
242
  [template_name](#template_name) must also be specified.
242
243
 
244
+ ### templates
245
+
246
+ Specify index templates in form of hash. Can contain multiple templates.
247
+
248
+ ```
249
+ templates { "templane_name_1": "path_to_template_1_file", "templane_name_2": "path_to_template_2_file"}
250
+ ```
251
+
252
+ If `template_file` and `template_name` are set, then this parameter will be ignored.
253
+
243
254
  ### request_timeout
244
255
 
245
256
  You can specify HTTP request timeout.
@@ -3,7 +3,7 @@ $:.push File.expand_path('../lib', __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = 'fluent-plugin-elasticsearch'
6
- s.version = '1.7.0'
6
+ s.version = '1.8.0'
7
7
  s.authors = ['diogo', 'pitr']
8
8
  s.email = ['pitr.vern@gmail.com', 'me@diogoterror.com']
9
9
  s.description = %q{ElasticSearch output plugin for Fluent event collector}
@@ -28,4 +28,10 @@ module Fluent::ElasticsearchIndexTemplate
28
28
  end
29
29
  end
30
30
 
31
+ def templates_hash_install (templates)
32
+ templates.each do |key, value|
33
+ template_install(key, value)
34
+ end
35
+ end
36
+
31
37
  end
@@ -54,6 +54,7 @@ class Fluent::ElasticsearchOutput < Fluent::BufferedOutput
54
54
  config_param :flatten_hashes_separator, :string, :default => "_"
55
55
  config_param :template_name, :string, :default => nil
56
56
  config_param :template_file, :string, :default => nil
57
+ config_param :templates, :hash, :default => nil
57
58
 
58
59
  include Fluent::SetTagKeyMixin
59
60
  include Fluent::ElasticsearchIndexTemplate
@@ -86,7 +87,10 @@ class Fluent::ElasticsearchOutput < Fluent::BufferedOutput
86
87
 
87
88
  if @template_name && @template_file
88
89
  template_install(@template_name, @template_file)
90
+ elsif @templates
91
+ templates_hash_install (@templates)
89
92
  end
93
+
90
94
  end
91
95
 
92
96
  def start
@@ -315,7 +319,7 @@ class Fluent::ElasticsearchOutput < Fluent::BufferedOutput
315
319
  append_record_to_messages(@write_operation, meta, record, bulk_message)
316
320
  end
317
321
 
318
- send(bulk_message) unless bulk_message.empty?
322
+ send_bulk(bulk_message) unless bulk_message.empty?
319
323
  bulk_message.clear
320
324
  end
321
325
 
@@ -328,7 +332,7 @@ class Fluent::ElasticsearchOutput < Fluent::BufferedOutput
328
332
  [parent_object, path[-1]]
329
333
  end
330
334
 
331
- def send(data)
335
+ def send_bulk(data)
332
336
  retries = 0
333
337
  begin
334
338
  client.bulk body: data
@@ -15,7 +15,7 @@ class Fluent::ElasticsearchOutputDynamic < Fluent::ElasticsearchOutput
15
15
  config_param :reload_connections, :string, :default => "true"
16
16
  config_param :reload_on_failure, :string, :default => "false"
17
17
  config_param :resurrect_after, :string, :default => "60"
18
- config_param :ssl_verify, :string, :dfeault => "true"
18
+ config_param :ssl_verify, :string, :default => "true"
19
19
 
20
20
  def configure(conf)
21
21
  super
@@ -178,12 +178,12 @@ class Fluent::ElasticsearchOutputDynamic < Fluent::ElasticsearchOutput
178
178
  end
179
179
 
180
180
  bulk_message.each do | hKey, array |
181
- send(array, hKey) unless array.empty?
181
+ send_bulk(array, hKey) unless array.empty?
182
182
  array.clear
183
183
  end
184
184
  end
185
185
 
186
- def send(data, host)
186
+ def send_bulk(data, host)
187
187
  retries = 0
188
188
  begin
189
189
  client(host).bulk body: data
@@ -113,7 +113,8 @@ class ElasticsearchOutput < Test::Unit::TestCase
113
113
  to_return(:status => 200, :body => "", :headers => {})
114
114
 
115
115
  driver('test', config)
116
- end
116
+ end
117
+
117
118
 
118
119
  def test_template_create_invalid_filename
119
120
  config = %{
@@ -139,6 +140,118 @@ class ElasticsearchOutput < Test::Unit::TestCase
139
140
  }
140
141
  end
141
142
 
143
+ def test_templates_create
144
+ cwd = File.dirname(__FILE__)
145
+ template_file = File.join(cwd, 'test_template.json')
146
+ config = %{
147
+ host logs.google.com
148
+ port 777
149
+ scheme https
150
+ path /es/
151
+ user john
152
+ password doe
153
+ templates {"logstash1":"#{template_file}", "logstash2":"#{template_file}","logstash3":"#{template_file}" }
154
+ }
155
+
156
+ stub_request(:head, "https://john:doe@logs.google.com:777/es//").
157
+ to_return(:status => 200, :body => "", :headers => {})
158
+ # check if template exists
159
+ stub_request(:get, "https://john:doe@logs.google.com:777/es//_template/logstash1").
160
+ to_return(:status => 404, :body => "", :headers => {})
161
+ stub_request(:get, "https://john:doe@logs.google.com:777/es//_template/logstash2").
162
+ to_return(:status => 404, :body => "", :headers => {})
163
+
164
+ stub_request(:get, "https://john:doe@logs.google.com:777/es//_template/logstash3").
165
+ to_return(:status => 200, :body => "", :headers => {}) #exists
166
+
167
+ stub_request(:put, "https://john:doe@logs.google.com:777/es//_template/logstash1").
168
+ to_return(:status => 200, :body => "", :headers => {})
169
+ stub_request(:put, "https://john:doe@logs.google.com:777/es//_template/logstash2").
170
+ to_return(:status => 200, :body => "", :headers => {})
171
+ stub_request(:put, "https://john:doe@logs.google.com:777/es//_template/logstash3").
172
+ to_return(:status => 200, :body => "", :headers => {})
173
+
174
+ driver('test', config)
175
+
176
+ assert_requested( :put, "https://john:doe@logs.google.com:777/es//_template/logstash1", times: 1)
177
+ assert_requested( :put, "https://john:doe@logs.google.com:777/es//_template/logstash2", times: 1)
178
+ assert_not_requested(:put, "https://john:doe@logs.google.com:777/es//_template/logstash3") #exists
179
+ end
180
+
181
+ def test_templates_not_used
182
+ cwd = File.dirname(__FILE__)
183
+ template_file = File.join(cwd, 'test_template.json')
184
+
185
+ config = %{
186
+ host logs.google.com
187
+ port 777
188
+ scheme https
189
+ path /es/
190
+ user john
191
+ password doe
192
+ template_name logstash
193
+ template_file #{template_file}
194
+ templates {"logstash1":"#{template_file}", "logstash2":"#{template_file}" }
195
+ }
196
+ # connection start
197
+ stub_request(:head, "https://john:doe@logs.google.com:777/es//").
198
+ to_return(:status => 200, :body => "", :headers => {})
199
+ # check if template exists
200
+ stub_request(:get, "https://john:doe@logs.google.com:777/es//_template/logstash").
201
+ to_return(:status => 404, :body => "", :headers => {})
202
+ stub_request(:get, "https://john:doe@logs.google.com:777/es//_template/logstash1").
203
+ to_return(:status => 404, :body => "", :headers => {})
204
+ stub_request(:get, "https://john:doe@logs.google.com:777/es//_template/logstash2").
205
+ to_return(:status => 404, :body => "", :headers => {})
206
+ #creation
207
+ stub_request(:put, "https://john:doe@logs.google.com:777/es//_template/logstash").
208
+ to_return(:status => 200, :body => "", :headers => {})
209
+ stub_request(:put, "https://john:doe@logs.google.com:777/es//_template/logstash1").
210
+ to_return(:status => 200, :body => "", :headers => {})
211
+ stub_request(:put, "https://john:doe@logs.google.com:777/es//_template/logstash2").
212
+ to_return(:status => 200, :body => "", :headers => {})
213
+
214
+ driver('test', config)
215
+
216
+ assert_requested(:put, "https://john:doe@logs.google.com:777/es//_template/logstash", times: 1)
217
+
218
+ assert_not_requested(:put, "https://john:doe@logs.google.com:777/es//_template/logstash1")
219
+ assert_not_requested(:put, "https://john:doe@logs.google.com:777/es//_template/logstash2")
220
+ end
221
+
222
+ def test_templates_can_be_partially_created_if_error_occurs
223
+ cwd = File.dirname(__FILE__)
224
+ template_file = File.join(cwd, 'test_template.json')
225
+ config = %{
226
+ host logs.google.com
227
+ port 777
228
+ scheme https
229
+ path /es/
230
+ user john
231
+ password doe
232
+ templates {"logstash1":"#{template_file}", "logstash2":"/abc" }
233
+ }
234
+ stub_request(:head, "https://john:doe@logs.google.com:777/es//").
235
+ to_return(:status => 200, :body => "", :headers => {})
236
+ # check if template exists
237
+ stub_request(:get, "https://john:doe@logs.google.com:777/es//_template/logstash1").
238
+ to_return(:status => 404, :body => "", :headers => {})
239
+ stub_request(:get, "https://john:doe@logs.google.com:777/es//_template/logstash2").
240
+ to_return(:status => 404, :body => "", :headers => {})
241
+
242
+ stub_request(:put, "https://john:doe@logs.google.com:777/es//_template/logstash1").
243
+ to_return(:status => 200, :body => "", :headers => {})
244
+ stub_request(:put, "https://john:doe@logs.google.com:777/es//_template/logstash2").
245
+ to_return(:status => 200, :body => "", :headers => {})
246
+
247
+ assert_raise(RuntimeError) {
248
+ driver('test', config)
249
+ }
250
+
251
+ assert_requested(:put, "https://john:doe@logs.google.com:777/es//_template/logstash1", times: 1)
252
+ assert_not_requested(:put, "https://john:doe@logs.google.com:777/es//_template/logstash2")
253
+ end
254
+
142
255
  def test_legacy_hosts_list
143
256
  config = %{
144
257
  hosts host1:50,host2:100,host3
@@ -63,6 +63,26 @@ class ElasticsearchOutputDynamic < Test::Unit::TestCase
63
63
  assert_equal 'doe', instance.password
64
64
  end
65
65
 
66
+ def test_defaults
67
+ config = %{
68
+ host logs.google.com
69
+ scheme https
70
+ path /es/
71
+ user john
72
+ password doe
73
+ }
74
+ instance = driver('test', config).instance
75
+
76
+ assert_equal "9200", instance.port
77
+ assert_equal "false", instance.logstash_format
78
+ assert_equal "true", instance.utc_index
79
+ assert_equal false, instance.time_key_exclude_timestamp
80
+ assert_equal "true", instance.reload_connections
81
+ assert_equal "false", instance.reload_on_failure
82
+ assert_equal "60", instance.resurrect_after
83
+ assert_equal "true", instance.ssl_verify
84
+ end
85
+
66
86
  def test_legacy_hosts_list
67
87
  config = %{
68
88
  hosts host1:50,host2:100,host3
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-elasticsearch
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.0
4
+ version: 1.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - diogo
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-09-12 00:00:00.000000000 Z
12
+ date: 2016-10-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: fluentd