fluent-plugin-elasticsearch 2.12.2 → 2.12.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6d97d7d622a14ab5bf55b08dfb20792ce7893988b9f47abc013d33afbb735166
4
- data.tar.gz: 4e585b0c87f929d083e9c20c137f22da6f5260d24032bfd9baf4c8fc8c109287
3
+ metadata.gz: dbe9d45b32f6a3db242d3f41dfa7c9c56ee425c9f36bbea1866c8fe61795f214
4
+ data.tar.gz: 7070955261a6a34a2d27d97fd7c2b040d03d8ec725d7d58fedcda863a4aaa083
5
5
  SHA512:
6
- metadata.gz: 1a5c1b5b7b27575c92350f9338a39f684d5f7facfb3f4ad182642c9a210e5dea912d575e8a35b763c14f7d019ecf3cb9982bc95434436b9fe378a2fdf30704cb
7
- data.tar.gz: 573c3b6c23ddbe42173952f914f3e702c3a8eb9ff839e78e108bb372b786351bd47383d05fa7628a065de8a10718fba1e4c5220d624ae4cdf831abd106ff4031
6
+ metadata.gz: 220580fb2c1405e355f49a30249ec1c5cb3f3774789d440057f3377f6493e26ca46569cd3081c7dc16493ea8056eb7fd12919d0c11137439e8bff55eb0749611
7
+ data.tar.gz: c90e537194d8986180fa183c757a19694c638dc324e9edc9b8fb46a355991f06efc08acfac7af47bb3587a3c66fb3b1a969361ae64cf5c9fa589d6aa00f6c7bd
data/History.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  ### [Unreleased]
4
4
 
5
+ ### 2.12.3
6
+ - Added log_es_400_reason configuration item (#511)
7
+ - Allow a user to specify the rollover index date pattern (#510)
8
+
5
9
  ### 2.12.2
6
10
  - Verify connection at startup (#504)
7
11
  - Add faq for glob pattern tag routing (#502)
data/README.md CHANGED
@@ -36,6 +36,7 @@ Current maintainers: @cosmo0920
36
36
  + [template_overwrite](#template_overwrite)
37
37
  + [customize_template](#customize_template)
38
38
  + [rollover_index](#rollover_index)
39
+ + [index_date_pattern](#index_date_pattern)
39
40
  + [deflector_alias](#deflector_alias)
40
41
  + [application_name](#application_name)
41
42
  + [index_prefix](#index_prefix)
@@ -76,6 +77,7 @@ Current maintainers: @cosmo0920
76
77
  + [Dynamic configuration](#dynamic-configuration)
77
78
  + [Placeholders](#placeholders)
78
79
  + [Multi workers](#multi-workers)
80
+ + [log_es_400_reason](#log-es-400-reason)
79
81
  * [Troubleshooting](#troubleshooting)
80
82
  + [Cannot send events to elasticsearch](#cannot-send-events-to-elasticsearch)
81
83
  + [Cannot see detailed failure log](#cannot-see-detailed-failure-log)
@@ -367,6 +369,19 @@ rollover_index true # defaults to false
367
369
 
368
370
  If [customize_template](#customize_template) is set, then this parameter will be in effect otherwise ignored.
369
371
 
372
+ ### index_date_pattern
373
+
374
+ Specify this to override the index date pattern for creating a rollover index. The default is to use "now/d",
375
+ for example: <logstash-default-{now/d}-000001>. Overriding this changes the rollover time period. Setting
376
+ "now/w{xxxx.ww}" would create weekly rollover indexes instead of daily.
377
+
378
+ This setting only takes effect when combined with the [rollover_index](#rollover_index) setting.
379
+ ```
380
+ index_date_pattern "now/w{xxxx.ww}" # defaults to "now/d"
381
+ ```
382
+
383
+ If [customize_template](#customize_template) is set, then this parameter will be in effect otherwise ignored.
384
+
370
385
  ### deflector_alias
371
386
 
372
387
  Specify the deflector alias which would be assigned to the rollover index created. This is useful in case of using the Elasticsearch rollover API
@@ -970,6 +985,12 @@ Since Fluentd v0.14, multi workers feature had been implemented to increase thro
970
985
  </system>
971
986
  ```
972
987
 
988
+ ## log_es_400_reason
989
+
990
+ By default, the error logger won't record the reason for a 400 error from the Elasticsearch API unless you set log_level to debug. However, this results in a lot of log spam, which isn't desirable if all you want is the 400 error reasons. You can set this `true` to capture the 400 error reasons without all the other debug logs.
991
+
992
+ Default value is `false`.
993
+
973
994
  ## Troubleshooting
974
995
 
975
996
  ### Cannot send events to Elasticsearch
@@ -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 = '2.12.2'
6
+ s.version = '2.12.3'
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}
@@ -23,6 +23,14 @@ class Fluent::Plugin::ElasticsearchErrorHandler
23
23
  unrecoverable_error_types.include?(type)
24
24
  end
25
25
 
26
+ def log_es_400_reason(&block)
27
+ if @plugin.log_es_400_reason
28
+ block.call
29
+ else
30
+ @plugin.log.on_debug &block
31
+ end
32
+ end
33
+
26
34
  def handle_error(response, tag, chunk, bulk_message_count, extracted_values)
27
35
  items = response['items']
28
36
  if items.nil? || !items.is_a?(Array)
@@ -74,7 +82,7 @@ class Fluent::Plugin::ElasticsearchErrorHandler
74
82
  when 400 == status
75
83
  stats[:bad_argument] += 1
76
84
  reason = ""
77
- @plugin.log.on_debug do
85
+ log_es_400_reason do
78
86
  if item[write_operation].has_key?('error') && item[write_operation]['error'].has_key?('type')
79
87
  reason = " [error type]: #{item[write_operation]['error']['type']}"
80
88
  end
@@ -68,7 +68,7 @@ module Fluent::ElasticsearchIndexTemplate
68
68
  end
69
69
  end
70
70
 
71
- def template_custom_install(template_name, template_file, overwrite, customize_template, index_prefix, rollover_index, deflector_alias_name, app_name)
71
+ def template_custom_install(template_name, template_file, overwrite, customize_template, index_prefix, rollover_index, deflector_alias_name, app_name, index_date_pattern)
72
72
  template_custom_name=template_name.downcase
73
73
  if overwrite
74
74
  template_put(template_custom_name, get_custom_template(template_file, customize_template))
@@ -83,7 +83,7 @@ module Fluent::ElasticsearchIndexTemplate
83
83
  end
84
84
  if rollover_index
85
85
  if !client.indices.exists_alias(:name => deflector_alias_name)
86
- index_name_temp='<'+index_prefix.downcase+'-'+app_name.downcase+'-{now/d}-000001>'
86
+ index_name_temp='<'+index_prefix.downcase+'-'+app_name.downcase+'-{'+index_date_pattern+'}-000001>'
87
87
  indexcreation(index_name_temp)
88
88
  client.indices.put_alias(:index => index_name_temp, :name => deflector_alias_name)
89
89
  log.info("The alias '#{deflector_alias_name}' is created for the index '#{index_name_temp}'")
@@ -100,6 +100,7 @@ EOC
100
100
  config_param :template_overwrite, :bool, :default => false
101
101
  config_param :customize_template, :hash, :default => nil
102
102
  config_param :rollover_index, :string, :default => false
103
+ config_param :index_date_pattern, :string, :default => "now/d"
103
104
  config_param :deflector_alias, :string, :default => nil
104
105
  config_param :index_prefix, :string, :default => "logstash"
105
106
  config_param :application_name, :string, :default => "default"
@@ -126,6 +127,7 @@ EOC
126
127
  config_param :unrecoverable_error_types, :array, :default => ["out_of_memory_error", "es_rejected_execution_exception"]
127
128
  config_param :verify_es_version_at_startup, :bool, :default => true
128
129
  config_param :default_elasticsearch_version, :integer, :default => DEFAULT_ELASTICSEARCH_VERSION
130
+ config_param :log_es_400_reason, :bool, :default => false
129
131
 
130
132
  config_section :buffer do
131
133
  config_set_default :@type, DEFAULT_BUFFER_TYPE
@@ -166,14 +168,14 @@ EOC
166
168
  end
167
169
 
168
170
  raise Fluent::ConfigError, "'max_retry_putting_template' must be positive number." if @max_retry_putting_template < 0
169
-
171
+
170
172
  if @template_name && @template_file
171
173
  retry_install(@max_retry_putting_template) do
172
174
  if @customize_template
173
175
  if @rollover_index
174
176
  raise Fluent::ConfigError, "'deflector_alias' must be provided if 'rollover_index' is set true ." if not @deflector_alias
175
177
  end
176
- template_custom_install(@template_name, @template_file, @template_overwrite, @customize_template, @index_prefix, @rollover_index, @deflector_alias, @application_name)
178
+ template_custom_install(@template_name, @template_file, @template_overwrite, @customize_template, @index_prefix, @rollover_index, @deflector_alias, @application_name, @index_date_pattern)
177
179
  else
178
180
  template_install(@template_name, @template_file, @template_overwrite)
179
181
  end
@@ -9,11 +9,13 @@ class TestElasticsearchErrorHandler < Test::Unit::TestCase
9
9
  attr_reader :log
10
10
  attr_reader :write_operation, :error_events
11
11
  attr_accessor :unrecoverable_error_types
12
- def initialize(log)
12
+ attr_accessor :log_es_400_reason
13
+ def initialize(log, log_es_400_reason = false)
13
14
  @log = log
14
15
  @write_operation = 'index'
15
16
  @error_events = []
16
17
  @unrecoverable_error_types = ["out_of_memory_error", "es_rejected_execution_exception"]
18
+ @log_es_400_reason = log_es_400_reason
17
19
  end
18
20
 
19
21
  def router
@@ -101,6 +103,48 @@ class TestElasticsearchErrorHandler < Test::Unit::TestCase
101
103
  end
102
104
  end
103
105
 
106
+ class TEST400ResponseReasonNoDebug < self
107
+ def setup
108
+ Fluent::Test.setup
109
+ @log_device = Fluent::Test::DummyLogDevice.new
110
+ dl_opts = {:log_level => ServerEngine::DaemonLogger::INFO}
111
+ logger = ServerEngine::DaemonLogger.new(@log_device, dl_opts)
112
+ @log = Fluent::Log.new(logger)
113
+ @plugin = TestPlugin.new(@log)
114
+ @handler = Fluent::Plugin::ElasticsearchErrorHandler.new(@plugin)
115
+ @plugin.log_es_400_reason = true
116
+ end
117
+
118
+ def test_400_responses_reason_log
119
+ records = [{time: 123, record: {"foo" => "bar", '_id' => 'abc'}}]
120
+ response = parse_response(%({
121
+ "took" : 0,
122
+ "errors" : true,
123
+ "items" : [
124
+ {
125
+ "create" : {
126
+ "_index" : "foo",
127
+ "status" : 400,
128
+ "error" : {
129
+ "type" : "mapper_parsing_exception",
130
+ "reason" : "failed to parse"
131
+ }
132
+ }
133
+ }
134
+ ]
135
+ }))
136
+ chunk = MockChunk.new(records)
137
+ dummy_extracted_values = []
138
+ @handler.handle_error(response, 'atag', chunk, records.length, dummy_extracted_values)
139
+ assert_equal(1, @plugin.error_events.size)
140
+ expected_log = "failed to parse"
141
+ exception_message = @plugin.error_events.first[:error].message
142
+ assert_true(exception_message.include?(expected_log),
143
+ "Exception do not contain '#{exception_message}' '#{expected_log}'")
144
+ assert_true(@plugin.error_events[0][:error].respond_to?(:backtrace))
145
+ end
146
+ end
147
+
104
148
  def test_dlq_400_responses
105
149
  records = [{time: 123, record: {"foo" => "bar", '_id' => 'abc'}}]
106
150
  response = parse_response(%({
@@ -220,6 +220,7 @@ class ElasticsearchOutput < Test::Unit::TestCase
220
220
  assert_equal ["out_of_memory_error", "es_rejected_execution_exception"], instance.unrecoverable_error_types
221
221
  assert_true instance.verify_es_version_at_startup
222
222
  assert_equal Fluent::Plugin::ElasticsearchOutput::DEFAULT_ELASTICSEARCH_VERSION, instance.default_elasticsearch_version
223
+ assert_false instance.log_es_400_reason
223
224
  end
224
225
 
225
226
  test 'configure Content-Type' do
@@ -418,6 +419,7 @@ class ElasticsearchOutput < Test::Unit::TestCase
418
419
  template_file #{template_file}
419
420
  customize_template {"--appid--": "myapp-logs","--index_prefix--":"mylogs"}
420
421
  rollover_index true
422
+ index_date_pattern now/w{xxxx.ww}
421
423
  deflector_alias myapp_deflector
422
424
  index_prefix mylogs
423
425
  application_name myapp
@@ -433,13 +435,13 @@ class ElasticsearchOutput < Test::Unit::TestCase
433
435
  stub_request(:put, "https://john:doe@logs.google.com:777/es//_template/myapp_alias_template").
434
436
  to_return(:status => 200, :body => "", :headers => {})
435
437
  # creation of index which can rollover
436
- stub_request(:put, "https://john:doe@logs.google.com:777/es//%3Cmylogs-myapp-%7Bnow%2Fd%7D-000001%3E").
438
+ stub_request(:put, "https://john:doe@logs.google.com:777/es//%3Cmylogs-myapp-%7Bnow%2Fw%7Bxxxx.ww%7D%7D-000001%3E").
437
439
  to_return(:status => 200, :body => "", :headers => {})
438
440
  # check if alias exists
439
441
  stub_request(:head, "https://john:doe@logs.google.com:777/es//_alias/myapp_deflector").
440
442
  to_return(:status => 404, :body => "", :headers => {})
441
443
  # put the alias for the index
442
- stub_request(:put, "https://john:doe@logs.google.com:777/es//%3Cmylogs-myapp-%7Bnow%2Fd%7D-000001%3E/_alias/myapp_deflector").
444
+ stub_request(:put, "https://john:doe@logs.google.com:777/es//%3Cmylogs-myapp-%7Bnow%2Fw%7Bxxxx.ww%7D%7D-000001%3E/_alias/myapp_deflector").
443
445
  to_return(:status => 200, :body => "", :headers => {})
444
446
 
445
447
  driver(config)
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: 2.12.2
4
+ version: 2.12.3
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: 2018-11-24 00:00:00.000000000 Z
12
+ date: 2018-12-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: fluentd