fluent-plugin-elasticsearch 2.0.0.rc.2 → 2.0.0.rc.3

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: 9c2133b6bd8b8961cb98cf10e6de22c9b86d6b17
4
- data.tar.gz: 797ad2184b49f1a3fa508df533dd82d300a10af8
3
+ metadata.gz: e14a0ebc5d22a662c135e3738a181582f5d30053
4
+ data.tar.gz: 2fa9a955a38f91afbd466ee4a926a08f3b4cc304
5
5
  SHA512:
6
- metadata.gz: cc690dfb2d06e658c3cd14f9efac8f37c07f97de7420624ac3e358c79c4dda5a492dbd0bd055edd8bb4ed10a4ff2f7defedf81811e8cdeb9d47502e110f10ffb
7
- data.tar.gz: 04a4eb3bed694306c50b1b8c7b257ab83142d5049de10e4c7fe931371bf6b3024be7ef6a7580c47fcb009420430456792180e3deb4a3c5ffc2773916de0a0c9e
6
+ metadata.gz: 1c765923fa3e279ee3a0c621c28f5a80396e7ba5c867002e376e24c1f5c312b059f93c7858999dd249a8a66d3262cc7208634517871e5af6494af26ed65e363d
7
+ data.tar.gz: ac9285cf50af63cf6f4233474dd8c6683d273aab3742cefa74187814dd1e80327adc1ed6b644593173146b790c128dd713a9d1a0b23e94369334f282d9ca095d
data/History.md CHANGED
@@ -4,6 +4,10 @@
4
4
  - Log ES response errors (#230)
5
5
  - Use latest elasticsearch-ruby (#240)
6
6
 
7
+ ### 2.0.0.rc.3
8
+ - add built-in placeholders support (#288, #293)
9
+ - permit multi workers feature (#291)
10
+
7
11
  ### 2.0.0.rc.2
8
12
  - add pipeline parameter (#290)
9
13
 
data/README.md CHANGED
@@ -53,6 +53,8 @@ Current maintainers: @cosmo0920
53
53
  + [Hash flattening](#hash-flattening)
54
54
  + [Not seeing a config you need?](#not-seeing-a-config-you-need)
55
55
  + [Dynamic configuration](#dynamic-configuration)
56
+ + [Placeholders](#placeholders)
57
+ + [Multi workers](#multi-workers)
56
58
  * [Contact](#contact)
57
59
  * [Contributing](#contributing)
58
60
  * [Running tests](#running-tests)
@@ -527,6 +529,69 @@ If you want configurations to depend on information in messages, you can use `el
527
529
 
528
530
  **Please note, this uses Ruby's `eval` for every message, so there are performance and security implications.**
529
531
 
532
+ ### Placeholders
533
+
534
+ v0.14 placeholders can handle `${tag}` for tag, `%Y%m%d` like strftime format, and custom record keys like as `record["mykey"]`.
535
+
536
+ Note that custom chunk key is diffrent notations for `record_reformer` and `record_modifier`.
537
+ They uses `record["some_key"]` to specify placeholders, but this feature uses `${key1}`, `${key2}` notation. And tag, time, and some arbitrary keys must be included in buffer directive attributes.
538
+
539
+ They are used as below:
540
+
541
+ #### tag
542
+
543
+ ```aconf
544
+ <match my.logs>
545
+ @type elasticsearch
546
+ index_name elastic.${tag} #=> replaced with each event's tag. e.g.) elastic.test.tag
547
+ <buffer tag>
548
+ @type memory
549
+ </buffer>
550
+ # <snip>
551
+ </match>
552
+ ```
553
+
554
+ #### time
555
+
556
+ ```aconf
557
+ <match my.logs>
558
+ @type elasticsearch
559
+ index_name elastic.%Y%m%d #=> e.g.) elastic.20170811
560
+ <buffer tag, time>
561
+ @type memory
562
+ timekey 3600
563
+ </buffer>
564
+ # <snip>
565
+ </match>
566
+ ```
567
+
568
+ #### custom key
569
+
570
+ ```log
571
+ records = {key1: "value1", key2: "value2"}
572
+ ```
573
+
574
+ ```aconf
575
+ <match my.logs>
576
+ @type elasticsearch
577
+ index_name elastic.${key1}.${key2} # => e.g.) elastic.value1.value2
578
+ <buffer tag, key1, key2>
579
+ @type memory
580
+ </buffer>
581
+ # <snip>
582
+ </match>
583
+ ```
584
+
585
+ ## Multi workers
586
+
587
+ Since Fluentd v0.14, multi workers feature had been implemented to increase throughput with multiple processes. This feature allows Fluentd processes to use one or more CPUs. This feature will be enabled by the following system configuration:
588
+
589
+ ```
590
+ <system>
591
+ workers N # where N is a natural number (N >= 1).
592
+ </system>
593
+ ```
594
+
530
595
  ## Contact
531
596
 
532
597
  If you have a question, [open an Issue](https://github.com/uken/fluent-plugin-elasticsearch/issues).
@@ -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.0.0.rc.2'
6
+ s.version = '2.0.0.rc.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}
@@ -72,6 +72,7 @@ module Fluent::Plugin
72
72
  config_section :buffer do
73
73
  config_set_default :@type, DEFAULT_BUFFER_TYPE
74
74
  config_set_default :chunk_keys, ['tag']
75
+ config_set_default :timekey_use_utc, true
75
76
  end
76
77
 
77
78
  include Fluent::ElasticsearchIndexTemplate
@@ -292,12 +293,23 @@ module Fluent::Plugin
292
293
  ret
293
294
  end
294
295
 
296
+ def expand_placeholders(metadata)
297
+ logstash_prefix = extract_placeholders(@logstash_prefix, metadata)
298
+ index_name = extract_placeholders(@index_name, metadata)
299
+ return logstash_prefix, index_name
300
+ end
301
+
302
+ def multi_workers_ready?
303
+ true
304
+ end
305
+
295
306
  def write(chunk)
296
307
  bulk_message = ''
297
308
  header = {}
298
309
  meta = {}
299
310
 
300
311
  tag = chunk.metadata.tag
312
+ logstash_prefix, index_name = expand_placeholders(chunk.metadata)
301
313
 
302
314
  chunk.msgpack_each do |time, record|
303
315
  next unless record.is_a? Hash
@@ -322,9 +334,9 @@ module Fluent::Plugin
322
334
  record[TIMESTAMP_FIELD] = dt.iso8601(@time_precision)
323
335
  end
324
336
  dt = dt.new_offset(0) if @utc_index
325
- target_index = "#{@logstash_prefix}-#{dt.strftime(@logstash_dateformat)}"
337
+ target_index = "#{logstash_prefix}-#{dt.strftime(@logstash_dateformat)}"
326
338
  else
327
- target_index = @index_name
339
+ target_index = index_name
328
340
  end
329
341
 
330
342
  # Change target_index to lower-case since Elasticsearch doesn't
@@ -108,6 +108,10 @@ module Fluent::Plugin
108
108
  end.join(', ')
109
109
  end
110
110
 
111
+ def multi_workers_ready?
112
+ true
113
+ end
114
+
111
115
  def write(chunk)
112
116
  bulk_message = Hash.new { |h,k| h[k] = '' }
113
117
  dynamic_conf = @dynamic_config.clone
@@ -389,6 +389,59 @@ class ElasticsearchOutput < Test::Unit::TestCase
389
389
  assert_equal('myindex', index_cmds.first['index']['_index'])
390
390
  end
391
391
 
392
+ class IndexNamePlaceholdersTest < self
393
+ def test_writes_to_speficied_index_with_tag_placeholder
394
+ driver.configure("index_name myindex.${tag}\n")
395
+ stub_elastic_ping
396
+ stub_elastic
397
+ driver.run(default_tag: 'test') do
398
+ driver.feed(sample_record)
399
+ end
400
+ assert_equal('myindex.test', index_cmds.first['index']['_index'])
401
+ end
402
+
403
+ def test_writes_to_speficied_index_with_time_placeholder
404
+ driver.configure(Fluent::Config::Element.new(
405
+ 'ROOT', '', {
406
+ '@type' => 'elasticsearch',
407
+ 'index_name' => 'myindex.%Y.%m.%d',
408
+ }, [
409
+ Fluent::Config::Element.new('buffer', 'tag,time', {
410
+ 'chunk_keys' => ['tag', 'time'],
411
+ 'timekey' => 3600,
412
+ }, [])
413
+ ]
414
+ ))
415
+ stub_elastic_ping
416
+ stub_elastic
417
+ time = Time.parse Date.today.to_s
418
+ driver.run(default_tag: 'test') do
419
+ driver.feed(time.to_i, sample_record)
420
+ end
421
+ assert_equal("myindex.#{time.utc.strftime("%Y.%m.%d")}", index_cmds.first['index']['_index'])
422
+ end
423
+
424
+ def test_writes_to_speficied_index_with_custom_key_placeholder
425
+ driver.configure(Fluent::Config::Element.new(
426
+ 'ROOT', '', {
427
+ '@type' => 'elasticsearch',
428
+ 'index_name' => 'myindex.${pipeline_id}',
429
+ }, [
430
+ Fluent::Config::Element.new('buffer', 'tag,pipeline_id', {}, [])
431
+ ]
432
+ ))
433
+ time = Time.parse Date.today.to_s
434
+ pipeline_id = "mypipeline"
435
+ logstash_index = "myindex.#{pipeline_id}"
436
+ stub_elastic_ping
437
+ stub_elastic
438
+ driver.run(default_tag: 'test') do
439
+ driver.feed(time.to_i, sample_record.merge({"pipeline_id" => pipeline_id}))
440
+ end
441
+ assert_equal(logstash_index, index_cmds.first['index']['_index'])
442
+ end
443
+ end
444
+
392
445
  def test_writes_to_speficied_index_uppercase
393
446
  driver.configure("index_name MyIndex\n")
394
447
  stub_elastic_ping
@@ -695,6 +748,65 @@ class ElasticsearchOutput < Test::Unit::TestCase
695
748
  assert_equal(logstash_index, index_cmds.first['index']['_index'])
696
749
  end
697
750
 
751
+ class LogStashPrefixPlaceholdersTest < self
752
+ def test_writes_to_logstash_index_with_specified_prefix_and_tag_placeholder
753
+ driver.configure("logstash_format true
754
+ logstash_prefix myprefix-${tag}")
755
+ time = Time.parse Date.today.to_s
756
+ logstash_index = "myprefix-test-#{time.getutc.strftime("%Y.%m.%d")}"
757
+ stub_elastic_ping
758
+ stub_elastic
759
+ driver.run(default_tag: 'test') do
760
+ driver.feed(time.to_i, sample_record)
761
+ end
762
+ assert_equal(logstash_index, index_cmds.first['index']['_index'])
763
+ end
764
+
765
+ def test_writes_to_logstash_index_with_specified_prefix_and_time_placeholder
766
+ driver.configure(Fluent::Config::Element.new(
767
+ 'ROOT', '', {
768
+ '@type' => 'elasticsearch',
769
+ 'logstash_format' => true,
770
+ 'logstash_prefix' => 'myprefix-%H',
771
+ }, [
772
+ Fluent::Config::Element.new('buffer', 'tag,time', {
773
+ 'chunk_keys' => ['tag', 'time'],
774
+ 'timekey' => 3600,
775
+ }, [])
776
+ ]
777
+ ))
778
+ time = Time.parse Date.today.to_s
779
+ logstash_index = "myprefix-#{time.getutc.strftime("%H")}-#{time.getutc.strftime("%Y.%m.%d")}"
780
+ stub_elastic_ping
781
+ stub_elastic
782
+ driver.run(default_tag: 'test') do
783
+ driver.feed(time.to_i, sample_record)
784
+ end
785
+ assert_equal(logstash_index, index_cmds.first['index']['_index'])
786
+ end
787
+
788
+ def test_writes_to_logstash_index_with_specified_prefix_and_custom_key_placeholder
789
+ driver.configure(Fluent::Config::Element.new(
790
+ 'ROOT', '', {
791
+ '@type' => 'elasticsearch',
792
+ 'logstash_format' => true,
793
+ 'logstash_prefix' => 'myprefix-${pipeline_id}',
794
+ }, [
795
+ Fluent::Config::Element.new('buffer', 'tag,pipeline_id', {}, [])
796
+ ]
797
+ ))
798
+ time = Time.parse Date.today.to_s
799
+ pipeline_id = "mypipeline"
800
+ logstash_index = "myprefix-#{pipeline_id}-#{time.getutc.strftime("%Y.%m.%d")}"
801
+ stub_elastic_ping
802
+ stub_elastic
803
+ driver.run(default_tag: 'test') do
804
+ driver.feed(time.to_i, sample_record.merge({"pipeline_id" => pipeline_id}))
805
+ end
806
+ assert_equal(logstash_index, index_cmds.first['index']['_index'])
807
+ end
808
+ end
809
+
698
810
  def test_writes_to_logstash_index_with_specified_prefix_uppercase
699
811
  driver.configure("logstash_format true
700
812
  logstash_prefix MyPrefix")
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.0.0.rc.2
4
+ version: 2.0.0.rc.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: 2017-09-11 00:00:00.000000000 Z
12
+ date: 2017-09-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: fluentd