fluentd 0.10.62 → 0.12.0.pre.1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of fluentd might be problematic. Click here for more details.

Files changed (140) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -2
  3. data/.travis.yml +0 -4
  4. data/ChangeLog +0 -72
  5. data/Gemfile +0 -6
  6. data/Rakefile +12 -3
  7. data/example/in_http.conf +14 -0
  8. data/example/in_syslog.conf +15 -0
  9. data/example/in_tail.conf +14 -0
  10. data/example/in_tcp.conf +13 -0
  11. data/example/in_udp.conf +13 -0
  12. data/example/out_copy.conf +20 -0
  13. data/example/out_file.conf +13 -0
  14. data/example/out_forward.conf +30 -0
  15. data/fluent.conf +2 -12
  16. data/fluentd.gemspec +8 -11
  17. data/lib/fluent/agent.rb +180 -0
  18. data/lib/fluent/buffer.rb +6 -12
  19. data/lib/fluent/command/cat.rb +1 -3
  20. data/lib/fluent/command/debug.rb +1 -3
  21. data/lib/fluent/command/fluentd.rb +0 -10
  22. data/lib/fluent/config.rb +9 -3
  23. data/lib/fluent/config/basic_parser.rb +1 -6
  24. data/lib/fluent/config/configure_proxy.rb +25 -61
  25. data/lib/fluent/config/dsl.rb +16 -0
  26. data/lib/fluent/config/element.rb +21 -2
  27. data/lib/fluent/config/error.rb +16 -0
  28. data/lib/fluent/config/literal_parser.rb +9 -27
  29. data/lib/fluent/config/parser.rb +16 -0
  30. data/lib/fluent/config/section.rb +16 -2
  31. data/lib/fluent/config/types.rb +16 -1
  32. data/lib/fluent/config/v1_parser.rb +4 -12
  33. data/lib/fluent/configurable.rb +16 -0
  34. data/lib/fluent/engine.rb +43 -163
  35. data/lib/fluent/env.rb +16 -1
  36. data/lib/fluent/event.rb +20 -48
  37. data/lib/fluent/event_router.rb +187 -0
  38. data/lib/fluent/filter.rb +32 -0
  39. data/lib/fluent/formatter.rb +29 -101
  40. data/lib/fluent/input.rb +6 -4
  41. data/lib/fluent/label.rb +18 -0
  42. data/lib/fluent/load.rb +1 -3
  43. data/lib/fluent/log.rb +1 -3
  44. data/lib/fluent/match.rb +12 -19
  45. data/lib/fluent/mixin.rb +9 -25
  46. data/lib/fluent/output.rb +27 -45
  47. data/lib/fluent/parser.rb +93 -99
  48. data/lib/fluent/plugin.rb +22 -48
  49. data/lib/fluent/plugin/buf_file.rb +10 -7
  50. data/lib/fluent/plugin/buf_memory.rb +2 -3
  51. data/lib/fluent/plugin/buf_zfile.rb +75 -0
  52. data/lib/fluent/plugin/exec_util.rb +16 -0
  53. data/lib/fluent/plugin/in_debug_agent.rb +2 -3
  54. data/lib/fluent/plugin/in_exec.rb +2 -9
  55. data/lib/fluent/plugin/in_forward.rb +4 -22
  56. data/lib/fluent/plugin/in_gc_stat.rb +2 -3
  57. data/lib/fluent/plugin/in_http.rb +19 -59
  58. data/lib/fluent/plugin/in_monitor_agent.rb +21 -47
  59. data/lib/fluent/plugin/in_object_space.rb +2 -3
  60. data/lib/fluent/plugin/in_status.rb +2 -3
  61. data/lib/fluent/plugin/in_stream.rb +6 -16
  62. data/lib/fluent/plugin/in_syslog.rb +8 -17
  63. data/lib/fluent/plugin/in_tail.rb +17 -24
  64. data/lib/fluent/plugin/in_tcp.rb +16 -0
  65. data/lib/fluent/plugin/in_udp.rb +16 -0
  66. data/lib/fluent/plugin/out_copy.rb +3 -4
  67. data/lib/fluent/plugin/out_exec.rb +2 -4
  68. data/lib/fluent/plugin/out_exec_filter.rb +2 -13
  69. data/lib/fluent/plugin/out_file.rb +5 -6
  70. data/lib/fluent/plugin/out_forward.rb +4 -5
  71. data/lib/fluent/plugin/out_null.rb +2 -3
  72. data/lib/fluent/plugin/out_relabel.rb +26 -0
  73. data/lib/fluent/plugin/out_roundrobin.rb +3 -4
  74. data/lib/fluent/plugin/out_stdout.rb +2 -3
  75. data/lib/fluent/plugin/out_stream.rb +2 -3
  76. data/{test/scripts → lib}/fluent/plugin/out_test.rb +2 -3
  77. data/lib/fluent/plugin/socket_util.rb +19 -10
  78. data/lib/fluent/process.rb +4 -6
  79. data/lib/fluent/registry.rb +16 -0
  80. data/lib/fluent/root_agent.rb +212 -0
  81. data/lib/fluent/status.rb +2 -3
  82. data/lib/fluent/supervisor.rb +33 -54
  83. data/lib/fluent/test.rb +16 -0
  84. data/lib/fluent/test/base.rb +3 -17
  85. data/lib/fluent/test/input_test.rb +52 -7
  86. data/lib/fluent/test/output_test.rb +4 -20
  87. data/lib/fluent/version.rb +17 -1
  88. data/spec/config/config_parser_spec.rb +314 -0
  89. data/spec/config/configurable_spec.rb +524 -0
  90. data/spec/config/configure_proxy_spec.rb +96 -0
  91. data/spec/config/dsl_spec.rb +239 -0
  92. data/spec/config/helper.rb +49 -0
  93. data/spec/config/literal_parser_spec.rb +222 -0
  94. data/spec/config/section_spec.rb +97 -0
  95. data/spec/config/system_config_spec.rb +49 -0
  96. data/test/helper.rb +0 -25
  97. data/test/plugin/test_in_exec.rb +1 -1
  98. data/test/plugin/test_in_forward.rb +2 -1
  99. data/test/plugin/test_in_gc_stat.rb +1 -1
  100. data/test/plugin/test_in_http.rb +3 -78
  101. data/test/plugin/test_in_object_space.rb +1 -1
  102. data/test/plugin/test_in_status.rb +1 -1
  103. data/test/plugin/test_in_stream.rb +2 -1
  104. data/test/plugin/test_in_syslog.rb +2 -1
  105. data/test/plugin/test_in_tail.rb +6 -11
  106. data/test/plugin/test_in_tcp.rb +2 -1
  107. data/test/plugin/test_in_udp.rb +2 -1
  108. data/test/plugin/test_out_copy.rb +1 -12
  109. data/test/plugin/test_out_exec.rb +1 -1
  110. data/test/plugin/test_out_exec_filter.rb +1 -1
  111. data/test/plugin/test_out_file.rb +7 -96
  112. data/test/plugin/test_out_forward.rb +2 -1
  113. data/test/plugin/test_out_roundrobin.rb +1 -12
  114. data/test/plugin/test_out_stdout.rb +1 -1
  115. data/test/plugin/test_out_stream.rb +2 -1
  116. data/test/scripts/fluent/plugin/formatter_known.rb +1 -4
  117. data/test/scripts/fluent/plugin/parser_known.rb +1 -2
  118. data/test/test_config.rb +1 -1
  119. data/test/test_configdsl.rb +2 -1
  120. data/test/test_formatter.rb +3 -395
  121. data/test/test_match.rb +2 -1
  122. data/test/test_mixin.rb +3 -75
  123. data/test/test_output.rb +1 -112
  124. data/test/test_parser.rb +85 -152
  125. metadata +58 -167
  126. data/example/v1_literal_example.conf +0 -36
  127. data/lib/fluent/plugin/in_dummy.rb +0 -103
  128. data/lib/fluent/timezone.rb +0 -131
  129. data/test/config/assertions.rb +0 -42
  130. data/test/config/test_config_parser.rb +0 -389
  131. data/test/config/test_configurable.rb +0 -652
  132. data/test/config/test_configure_proxy.rb +0 -99
  133. data/test/config/test_dsl.rb +0 -237
  134. data/test/config/test_literal_parser.rb +0 -295
  135. data/test/config/test_section.rb +0 -112
  136. data/test/config/test_system_config.rb +0 -99
  137. data/test/config/test_types.rb +0 -63
  138. data/test/plugin/test_in_dummy.rb +0 -95
  139. data/test/test_event.rb +0 -168
  140. data/test/test_input.rb +0 -21
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cd3088d98e7106ccaf044045d71999404e1357c5
4
- data.tar.gz: f232ac836fea58e4719174883df438e2be8c9202
3
+ metadata.gz: 38b8348d98cec8b31c27e634bd22a9afee293ad0
4
+ data.tar.gz: 983f2d287d63a26637c95266ce4cd1a85dcd1757
5
5
  SHA512:
6
- metadata.gz: 55e3054d9f035d210a8c40dca48dd0067749b3d942e8bc6bed63425d8898c11146cca21491d7a32aa614a2d4270dd8ad2f8c7b2e23a06f65ebc0d98b12b53a2e
7
- data.tar.gz: eb6293c1d478b3b384badba7024fe68d319797e37c6bebbc12dc7f1cbb89153776cd512b21b9f6ba7f449072906cadbe8907e244be0b76b37eb5bd56e5e1026a
6
+ metadata.gz: 0b62fb35a7a546cfa741564854091983fdf1d05ff7a85c44cae4dab1889b9f5eb3c5940b32e5739e05bd43a8c7fdbce05723d76a42959fb04cd7b9a6090aee6b
7
+ data.tar.gz: 8538fff4fcff3ca9fd72ac88681490a7d9e263d53ea51d410b82e486cf6896df7857d158fb6f5dceb55f5ef78072d2bfc3b3bf30faf3dbd00be1b7603452c761
data/.gitignore CHANGED
@@ -17,6 +17,5 @@ fluent-gem
17
17
  fluentd
18
18
  pkg/*
19
19
  test/tmp/*
20
- test/config/tmp/*
20
+ spec/config/tmp/*
21
21
  make_dist.sh
22
- Gemfile.local
data/.travis.yml CHANGED
@@ -14,16 +14,12 @@ os:
14
14
  branches:
15
15
  only:
16
16
  - master
17
- - v0.10
18
17
 
19
18
  gemfile:
20
19
  - Gemfile
21
- - Gemfile.cool.io.1.1.1
22
20
 
23
21
  script: bundle exec rake
24
22
 
25
- sudo: false
26
-
27
23
  matrix:
28
24
  allow_failures:
29
25
  - rvm: ruby-head
data/ChangeLog CHANGED
@@ -1,75 +1,3 @@
1
- Release 0.10.62 - 2016/12/15
2
-
3
- * Fix gem dependency to fix broken installation
4
-
5
- Release 0.10.61 - 2015/03/03
6
-
7
- * out_forward: Should handle ECONNREFUSED exeception on TCP heartbeat
8
- * test: BufferedOutputTestDriver must use correct buffer chunk type
9
-
10
- Release 0.10.60 - 2015/02/06
11
-
12
- * in_tail: Enable multiline mode if format contains 'multiline'
13
- * event: Improve EventStream#to_msgpack_stream performance
14
- * engine: Add tag information emit log
15
- * Update msgpack dependency to avoid incompatible encoding problem
16
-
17
- Release 0.10.59 - 2015/01/23
18
-
19
- * in_tail: Support 64bit inode environment in in_tail
20
- * parser: nginx and apache2 format can now parse access log without http-version
21
- * buffer: Fix broken calc_retry_wait if Integer is used for retry_wait parameter
22
- * buffer: Fix to flush a buffer by USR1 signal even on retrying
23
- * buffer: Fix TimeSlicedOutput doesn't flush with SIGUSR1
24
- * config: Support @ prefix build-in parameters
25
- * engine:Fix ThreadError occuring on Signal.trap SIGHUP
26
- * engine: Fix SIGHUP does not reload config
27
- * Revert fluent.conf since @type, @id are not available with v0 config
28
-
29
- Release 0.10.58 - 2014/12/14
30
-
31
- * parser/formatter: Add base class and Plugin.new_xxx/Plugin.register_xxx APIs
32
- * parser: Fix blank column handling of TSVParser
33
- * formatter: Add new CSV formatter
34
- * formatter: Add msgpack format to built-in Formatter to dump records
35
- * input: Add in_dummy plugin
36
- * in_http: Add respond_with_empty_img parameter to return empty gif image
37
- * in_http: Add cors_allow_origins parameter to support CORS request
38
- * config: Add self.name to configure_proxy error message
39
- * config: Fix system config using double memory
40
- * config: Fix v1 config to support multiple tag match
41
- * config: Fix Config.bool_value regression for nil value
42
- * buffer: Prevent an exception with large num_retries
43
- * out_file: Don't create world writable directory in daemon mode
44
- * add router.emit and router= for compatibility with v0.12
45
- * Use router instead of Engine.emit
46
-
47
- Release 0.10.57 - 2014/11/12
48
-
49
- * buffer: Make total_queued_chunk_size thread-safe to avoid race condition with in_monitor_agent
50
- * Add --no-supervisor option to disable the supervisor for supervision tools like runit
51
-
52
- Release 0.10.56 - 2014/10/30
53
-
54
- * config: Add Fluent::Config::Section#object_id to avoid NoMethodError by object dump tools
55
- * mixin: Fix SetTagKeyMixin and SetTimeKeyMixin which ignores config_set_default since 0.10.53
56
- * input/output: Support 'timezone' configuration parameter (e.g. "+09:00" for JST).
57
- * log: Use plugin_id instead of object_id in log message for consistency with in_monitor_agent
58
-
59
- Release 0.10.55 - 2014/10/17
60
-
61
- * config: Relax '@' handling in the plugin configuration for backward compatibility
62
-
63
- Release 0.10.54 - 2014/10/17
64
-
65
- * config: Change v1's non-quoted string literal behaviour to v0's behaviour
66
- * config: Add --use-v0-config for keeping old configuration
67
- * config: Add single quoted literal in v1 configuration
68
- * config: Improve error message of Array / Hash parse error
69
- * input: Reduce shutdown time in some network related plugins when use Cool.io 1.2
70
- * parser: Use ParserError instead of general exception classes
71
- * Remove unused zfile buffer plugin
72
-
73
1
  Release 0.10.53 - 2014/08/21
74
2
 
75
3
  * in_tail: Fix forget to detach Closer timer object
data/Gemfile CHANGED
@@ -1,9 +1,3 @@
1
1
  source 'https://rubygems.org/'
2
2
 
3
3
  gemspec
4
-
5
- local_gemfile = File.join(File.dirname(__FILE__), "Gemfile.local")
6
- if File.exist?(local_gemfile)
7
- puts "Loading Gemfile.local ..." if $DEBUG # `ruby -d` or `bundle -v`
8
- instance_eval File.read(local_gemfile)
9
- end
data/Rakefile CHANGED
@@ -4,8 +4,10 @@ require "bundler/gem_tasks"
4
4
  require 'fileutils'
5
5
  require 'rake/testtask'
6
6
  require 'rake/clean'
7
+ require 'rspec/core'
8
+ require 'rspec/core/rake_task'
7
9
 
8
- task :test => [:base_test]
10
+ task :test => [:base_test, :spec]
9
11
 
10
12
  desc 'Run test_unit based test'
11
13
  Rake::TestTask.new(:base_test) do |t|
@@ -13,7 +15,7 @@ Rake::TestTask.new(:base_test) do |t|
13
15
  # $ bundle exec rake base_test TEST=test/test_specified_path.rb
14
16
  # $ bundle exec rake base_test TEST=test/test_*.rb
15
17
  t.libs << "test"
16
- t.test_files = Dir["test/**/test_*.rb"].sort
18
+ t.test_files = (Dir["test/test_*.rb"] + Dir["test/plugin/test_*.rb"] - ["helper.rb"]).sort
17
19
  t.verbose = true
18
20
  #t.warning = true
19
21
  end
@@ -24,7 +26,14 @@ task :parallel_test do
24
26
  FileUtils.rm_rf('./test/tmp')
25
27
  end
26
28
 
27
- desc 'Run test with simplecov'
29
+ desc 'Run rspec based test'
30
+ RSpec::Core::RakeTask.new(:spec) do |t|
31
+ t.rspec_opts = %w[-c -f progress -r ./spec/spec_helper.rb]
32
+ t.pattern = 'spec/**/*_spec.rb'
33
+ t.verbose = true
34
+ end
35
+
36
+ desc 'Run rspec with simplecov'
28
37
  task :coverage do |t|
29
38
  ENV['SIMPLE_COV'] = '1'
30
39
  Rake::Task["spec"].invoke
@@ -0,0 +1,14 @@
1
+ <source>
2
+ type http
3
+ bind 0.0.0.0
4
+ port 9880
5
+ body_size_limit 32MB
6
+ keepalive_timeout 10
7
+ # backlog 0
8
+ add_http_headers false
9
+ format default
10
+ </source>
11
+
12
+ <match test>
13
+ type stdout
14
+ </match>
@@ -0,0 +1,15 @@
1
+ <source>
2
+ type syslog
3
+ bind 0.0.0.0
4
+ port 5140
5
+ tag test
6
+ protocol_type udp
7
+ include_source_host false
8
+ source_host_key source_host
9
+ # format ...
10
+ # with_priority true
11
+ </source>
12
+
13
+ <match test>
14
+ type stdout
15
+ </match>
@@ -0,0 +1,14 @@
1
+ <source>
2
+ type tail
3
+ format none
4
+ path /var/log/fluentd_test.log
5
+ pos_file /var/log/fluentd_test.pos
6
+ tag test
7
+ rotate_wait 5
8
+ read_from_head true
9
+ refresh_interval 60
10
+ </source>
11
+
12
+ <match test>
13
+ type stdout
14
+ </match>
@@ -0,0 +1,13 @@
1
+ <source>
2
+ type tcp
3
+ format none
4
+ bind 0.0.0.0
5
+ port 5170
6
+ delimiter \n
7
+ source_host_key "host"
8
+ tag test
9
+ </source>
10
+
11
+ <match test>
12
+ type stdout
13
+ </match>
@@ -0,0 +1,13 @@
1
+ <source>
2
+ type udp
3
+ format none
4
+ bind 0.0.0.0
5
+ port 5160
6
+ body_size_limit 4KB
7
+ source_host_key "host"
8
+ tag test
9
+ </source>
10
+
11
+ <match test>
12
+ type stdout
13
+ </match>
@@ -0,0 +1,20 @@
1
+ <source>
2
+ type forward
3
+ </source>
4
+
5
+ <match test>
6
+ type copy
7
+ deep_copy false
8
+ <store>
9
+ type stdout
10
+ </store>
11
+ <store>
12
+ type file
13
+ path /var/log/fluentd/out_file_test
14
+ format json
15
+ buffer_type memory
16
+ # compress gzip
17
+ # symlink_path /path/to/symlink
18
+ append false
19
+ </store>
20
+ </match>
@@ -0,0 +1,13 @@
1
+ <source>
2
+ type forward
3
+ </source>
4
+
5
+ <match test>
6
+ type file
7
+ path /var/log/fluentd/out_file_test
8
+ format json
9
+ buffer_type memory
10
+ # compress gzip
11
+ # symlink_path /path/to/symlink
12
+ append false
13
+ </match>
@@ -0,0 +1,30 @@
1
+ <source>
2
+ type forward
3
+ </source>
4
+
5
+ <match test>
6
+ type forward
7
+
8
+ <server>
9
+ # first server
10
+ port 24224
11
+ </server>
12
+ <server>
13
+ # second server
14
+ port 24225
15
+ </server>
16
+ <server>
17
+ # second server
18
+ port 24226
19
+ standby
20
+ </server>
21
+
22
+ send_timeout 60
23
+ heartbeat_type udp
24
+ heartbeat_interval 1
25
+ recover_wait 10
26
+ hard_timeout 60
27
+ expire_dns_cache nil
28
+ phi_threshold 16
29
+ phi_failure_detector true
30
+ </match>
data/fluent.conf CHANGED
@@ -1,11 +1,8 @@
1
- # In v1 configuration, type and id are @ prefix parameters.
2
- # @type and @id are recommended. type and id are still available for backward compatibility
3
1
 
4
2
  ## built-in TCP input
5
3
  ## $ echo <json> | fluent-cat <tag>
6
4
  <source>
7
5
  type forward
8
- id forward_input
9
6
  </source>
10
7
 
11
8
  ## built-in UNIX socket input
@@ -17,8 +14,6 @@
17
14
  # http://localhost:8888/<tag>?json=<json>
18
15
  <source>
19
16
  type http
20
- id http_input
21
-
22
17
  port 8888
23
18
  </source>
24
19
 
@@ -37,20 +32,17 @@
37
32
  # http://localhost:24220/api/plugins?tag=MYTAG
38
33
  <source>
39
34
  type monitor_agent
40
- id monitor_agent_input
41
-
42
35
  port 24220
43
36
  </source>
44
37
 
45
38
  # Listen DRb for debug
46
39
  <source>
47
40
  type debug_agent
48
- id debug_agent_input
49
-
50
41
  bind 127.0.0.1
51
42
  port 24230
52
43
  </source>
53
44
 
45
+
54
46
  ## match tag=apache.access and write to file
55
47
  #<match apache.access>
56
48
  # type file
@@ -60,14 +52,11 @@
60
52
  ## match tag=debug.** and dump to console
61
53
  <match debug.**>
62
54
  type stdout
63
- id stdout_output
64
55
  </match>
65
56
 
66
57
  # match tag=system.** and forward to another fluent server
67
58
  <match system.**>
68
59
  type forward
69
- id forward_output
70
-
71
60
  <server>
72
61
  host 192.168.0.11
73
62
  </server>
@@ -108,3 +97,4 @@
108
97
  # path /var/log/fluent/else
109
98
  # compress gz
110
99
  #</match>
100
+
data/fluentd.gemspec CHANGED
@@ -16,23 +16,20 @@ Gem::Specification.new do |gem|
16
16
  gem.require_paths = ["lib"]
17
17
  gem.has_rdoc = false
18
18
 
19
- gem.required_ruby_version = '>= 1.9.3'
19
+ gem.required_ruby_version = '>= 1.9.2'
20
20
 
21
- gem.add_runtime_dependency("msgpack", [">= 0.4.4", "!= 0.5.0", "!= 0.5.1", "!= 0.5.2", "!= 0.5.3", "!= 0.5.4",
22
- "!= 0.5.5", "!= 0.5.6", "!= 0.5.7", "!= 0.5.8", "!= 0.5.9", "!= 0.5.10", "< 0.6.0"])
23
- gem.add_runtime_dependency("json", [">= 1.4.3", "< 2.0.0"])
21
+ gem.add_runtime_dependency("msgpack", [">= 0.5.4", "< 0.6.0"])
22
+ gem.add_runtime_dependency("json", [">= 1.4.3"])
24
23
  gem.add_runtime_dependency("yajl-ruby", ["~> 1.0"])
25
- gem.add_runtime_dependency("cool.io", [">= 1.1.1", "!= 1.2.0", "< 2.0.0"])
24
+ gem.add_runtime_dependency("cool.io", [">= 1.2.2", "< 2.0.0"])
26
25
  gem.add_runtime_dependency("http_parser.rb", [">= 0.5.1", "< 0.7.0"])
27
26
  gem.add_runtime_dependency("sigdump", ["~> 0.2.2"])
28
- gem.add_runtime_dependency("tzinfo", [">= 1.0.0"])
29
- gem.add_runtime_dependency("tzinfo-data", [">= 1.0.0"])
30
27
 
31
28
  gem.add_development_dependency("rake", [">= 0.9.2"])
32
- gem.add_development_dependency("flexmock", ["< 2.0.0"])
33
- gem.add_development_dependency("parallel_tests", [">= 0.15.3", "< 2.0.0"])
29
+ gem.add_development_dependency("flexmock")
30
+ gem.add_development_dependency("parallel_tests", [">= 0.15.3"])
31
+ gem.add_development_dependency("rspec", ["~> 3.0.0"])
34
32
  gem.add_development_dependency("simplecov", ["~> 0.6.4"])
35
- gem.add_development_dependency("rr", ["~> 1.1.2"])
33
+ gem.add_development_dependency("rr", [">= 1.0.0"])
36
34
  gem.add_development_dependency("timecop", [">= 0.3.0"])
37
- gem.add_development_dependency("test-unit", ["~> 3.0.2"])
38
35
  end
@@ -0,0 +1,180 @@
1
+ #
2
+ # Fluentd
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+ module Fluent
17
+ require 'fluent/configurable'
18
+ require 'fluent/engine'
19
+
20
+ #
21
+ # Agent is a resource unit who manages emittable plugins
22
+ #
23
+ # Next step: `fluentd/root_agent.rb`
24
+ # Next step: `fluentd/label.rb`
25
+ #
26
+ class Agent
27
+ include Configurable
28
+
29
+ def initialize(opts = {})
30
+ # initialize Configurable
31
+ super()
32
+
33
+ @context = nil
34
+ @outputs = []
35
+ @filters = []
36
+ @started_outputs = []
37
+ @started_filters = []
38
+
39
+ @log = Engine.log
40
+ @event_router = EventRouter.new(self, NoMatchMatch.new(log))
41
+ @error_collector = nil
42
+ end
43
+
44
+ attr_reader :log
45
+ attr_reader :outputs
46
+ attr_reader :context
47
+ attr_reader :event_router
48
+ attr_reader :error_collector
49
+
50
+ def configure(conf)
51
+ super
52
+
53
+ # initialize <match> and <filter> elements
54
+ conf.elements.select { |e| e.name == 'filter' || e.name == 'match' }.each { |e|
55
+ pattern = e.arg.empty? ? '**' : e.arg
56
+ type = e['type']
57
+ if e.name == 'filter'
58
+ add_filter(type, pattern, e)
59
+ else
60
+ add_match(type, pattern, e)
61
+ end
62
+ }
63
+ end
64
+
65
+ # agent API called by Worker
66
+ def start
67
+ @outputs.each { |o|
68
+ o.start
69
+ @started_outputs << o
70
+ }
71
+
72
+ @filters.each { |f|
73
+ f.start
74
+ @started_filters << f
75
+ }
76
+ end
77
+
78
+ # agent API called by Worker
79
+ def shutdown
80
+ @started_filters.map { |f|
81
+ Thread.new do
82
+ begin
83
+ f.shutdown
84
+ rescue => e
85
+ log.warn "unexpected error while shutting down filter plugins", :plugin => f.class, :plugin_id => f.plugin_id, :error_class => e.class, :error => e
86
+ log.warn_backtrace
87
+ end
88
+ end
89
+ }.each { |t| t.join }
90
+
91
+ # Output plugin as filter emits records at shutdown so emit problem still exist.
92
+ # This problem will be resolved after actual filter mechanizm.
93
+ @started_outputs.map { |o|
94
+ Thread.new do
95
+ begin
96
+ o.shutdown
97
+ rescue => e
98
+ log.warn "unexpected error while shutting down output plugins", :plugin => o.class, :plugin_id => o.plugin_id, :error_class => e.class, :error => e
99
+ log.warn_backtrace
100
+ end
101
+ end
102
+ }.each { |t| t.join }
103
+ end
104
+
105
+ def flush!
106
+ flush_recursive(@outputs)
107
+ end
108
+
109
+ def flush_recursive(array)
110
+ array.each { |o|
111
+ begin
112
+ if o.is_a?(BufferedOutput)
113
+ o.force_flush
114
+ elsif o.is_a?(MultiOutput)
115
+ flush_recursive(o.outputs)
116
+ end
117
+ rescue => e
118
+ log.debug "error while force flushing", :error_class => e.class, :error => e
119
+ log.debug_backtrace
120
+ end
121
+ }
122
+ end
123
+
124
+ def add_match(type, pattern, conf)
125
+ log.info "adding match#{@context.nil? ? '' : " in #{@context}"}", pattern: pattern, type: type
126
+
127
+ output = Plugin.new_output(type)
128
+ output.router = @event_router
129
+ output.configure(conf)
130
+ @outputs << output
131
+ @event_router.add_rule(pattern, output)
132
+
133
+ output
134
+ end
135
+
136
+ def add_filter(type, pattern, conf)
137
+ log.info "adding filter#{@context.nil? ? '' : " in #{@context}"}", pattern: pattern, type: type
138
+
139
+ filter = Plugin.new_filter(type)
140
+ filter.configure(conf)
141
+ @filters << filter
142
+ @event_router.add_rule(pattern, filter)
143
+
144
+ filter
145
+ end
146
+
147
+ def handle_emits_error(tag, es, e)
148
+ end
149
+
150
+ class NoMatchMatch
151
+ def initialize(log)
152
+ @log = log
153
+ @count = 0
154
+ end
155
+
156
+ def emit(tag, es, chain)
157
+ # TODO use time instead of num of records
158
+ c = (@count += 1)
159
+ if c < 512
160
+ if Math.log(c) / Math.log(2) % 1.0 == 0
161
+ @log.warn "no patterns matched", :tag => tag
162
+ return
163
+ end
164
+ else
165
+ if c % 512 == 0
166
+ @log.warn "no patterns matched", :tag => tag
167
+ return
168
+ end
169
+ end
170
+ @log.on_trace { @log.trace "no patterns matched", :tag => tag }
171
+ end
172
+
173
+ def start
174
+ end
175
+
176
+ def shutdown
177
+ end
178
+ end
179
+ end
180
+ end