fluentd 1.13.0-x64-mingw32 → 1.14.0-x64-mingw32

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 (90) hide show
  1. checksums.yaml +4 -4
  2. data/.github/ISSUE_TEMPLATE/bug_report.yaml +69 -0
  3. data/.github/ISSUE_TEMPLATE/feature_request.yaml +38 -0
  4. data/.github/workflows/linux-test.yaml +1 -1
  5. data/.github/workflows/windows-test.yaml +4 -4
  6. data/.gitlab-ci.yml +0 -22
  7. data/CHANGELOG.md +131 -0
  8. data/README.md +2 -2
  9. data/example/v0_12_filter.conf +2 -2
  10. data/fluentd.gemspec +1 -1
  11. data/lib/fluent/command/fluentd.rb +8 -0
  12. data/lib/fluent/command/plugin_generator.rb +15 -5
  13. data/lib/fluent/compat/output.rb +9 -6
  14. data/lib/fluent/config/section.rb +5 -0
  15. data/lib/fluent/config/types.rb +15 -0
  16. data/lib/fluent/config/v1_parser.rb +3 -2
  17. data/lib/fluent/config.rb +1 -1
  18. data/lib/fluent/env.rb +2 -1
  19. data/lib/fluent/event_router.rb +28 -1
  20. data/lib/fluent/oj_options.rb +62 -0
  21. data/lib/fluent/plugin/bare_output.rb +49 -8
  22. data/lib/fluent/plugin/buffer.rb +84 -22
  23. data/lib/fluent/plugin/file_wrapper.rb +22 -0
  24. data/lib/fluent/plugin/filter.rb +35 -1
  25. data/lib/fluent/plugin/formatter.rb +1 -0
  26. data/lib/fluent/plugin/formatter_json.rb +9 -7
  27. data/lib/fluent/plugin/in_http.rb +21 -2
  28. data/lib/fluent/plugin/in_monitor_agent.rb +4 -2
  29. data/lib/fluent/plugin/in_syslog.rb +13 -1
  30. data/lib/fluent/plugin/in_tail/position_file.rb +20 -18
  31. data/lib/fluent/plugin/in_tail.rb +45 -4
  32. data/lib/fluent/plugin/input.rb +39 -1
  33. data/lib/fluent/plugin/metrics.rb +119 -0
  34. data/lib/fluent/plugin/metrics_local.rb +96 -0
  35. data/lib/fluent/plugin/multi_output.rb +43 -6
  36. data/lib/fluent/plugin/out_forward.rb +1 -3
  37. data/lib/fluent/plugin/output.rb +74 -33
  38. data/lib/fluent/plugin/parser_json.rb +2 -3
  39. data/lib/fluent/plugin/service_discovery.rb +0 -15
  40. data/lib/fluent/plugin.rb +10 -1
  41. data/lib/fluent/plugin_helper/event_emitter.rb +8 -1
  42. data/lib/fluent/plugin_helper/http_server/router.rb +1 -1
  43. data/lib/fluent/plugin_helper/metrics.rb +129 -0
  44. data/lib/fluent/plugin_helper/server.rb +4 -2
  45. data/lib/fluent/plugin_helper.rb +1 -0
  46. data/lib/fluent/root_agent.rb +6 -0
  47. data/lib/fluent/supervisor.rb +2 -0
  48. data/lib/fluent/system_config.rb +9 -1
  49. data/lib/fluent/test/driver/storage.rb +30 -0
  50. data/lib/fluent/version.rb +1 -1
  51. data/templates/new_gem/lib/fluent/plugin/storage.rb.erb +40 -0
  52. data/templates/new_gem/test/plugin/test_storage.rb.erb +18 -0
  53. data/test/command/test_cat.rb +11 -8
  54. data/test/command/test_plugin_generator.rb +2 -1
  55. data/test/config/test_section.rb +9 -0
  56. data/test/config/test_system_config.rb +6 -0
  57. data/test/config/test_types.rb +7 -0
  58. data/test/plugin/in_tail/test_position_file.rb +48 -8
  59. data/test/plugin/test_bare_output.rb +13 -0
  60. data/test/plugin/test_buffer.rb +8 -2
  61. data/test/plugin/test_file_wrapper.rb +11 -0
  62. data/test/plugin/test_filter.rb +11 -0
  63. data/test/plugin/test_in_forward.rb +59 -83
  64. data/test/plugin/test_in_http.rb +86 -43
  65. data/test/plugin/test_in_monitor_agent.rb +214 -8
  66. data/test/plugin/test_in_syslog.rb +101 -56
  67. data/test/plugin/test_in_tail.rb +149 -48
  68. data/test/plugin/test_in_tcp.rb +45 -32
  69. data/test/plugin/test_in_udp.rb +47 -33
  70. data/test/plugin/test_input.rb +11 -0
  71. data/test/plugin/test_metrics.rb +294 -0
  72. data/test/plugin/test_metrics_local.rb +96 -0
  73. data/test/plugin/test_multi_output.rb +25 -1
  74. data/test/plugin/test_out_forward.rb +103 -89
  75. data/test/plugin/test_out_stream.rb +18 -8
  76. data/test/plugin/test_output.rb +16 -0
  77. data/test/plugin_helper/http_server/test_route.rb +1 -1
  78. data/test/plugin_helper/test_child_process.rb +1 -1
  79. data/test/plugin_helper/test_event_emitter.rb +29 -0
  80. data/test/plugin_helper/test_http_server_helper.rb +33 -26
  81. data/test/plugin_helper/test_metrics.rb +137 -0
  82. data/test/plugin_helper/test_server.rb +137 -138
  83. data/test/plugin_helper/test_socket.rb +16 -9
  84. data/test/test_event_time.rb +2 -2
  85. data/test/test_oj_options.rb +55 -0
  86. data/test/test_plugin_classes.rb +102 -0
  87. data/test/test_root_agent.rb +30 -1
  88. metadata +22 -7
  89. data/.github/ISSUE_TEMPLATE/bug_report.md +0 -40
  90. data/.github/ISSUE_TEMPLATE/feature_request.md +0 -23
@@ -19,29 +19,32 @@ class HttpInputTest < Test::Unit::TestCase
19
19
 
20
20
  def setup
21
21
  Fluent::Test.setup
22
+ @port = unused_port
22
23
  end
23
24
 
24
25
  def teardown
25
26
  Timecop.return
27
+ @port = nil
26
28
  end
27
29
 
28
- PORT = unused_port
29
- CONFIG = %[
30
- port #{PORT}
31
- bind "127.0.0.1"
32
- body_size_limit 10m
33
- keepalive_timeout 5
34
- respond_with_empty_img true
35
- use_204_response false
36
- ]
37
-
38
- def create_driver(conf=CONFIG)
30
+ def config
31
+ %[
32
+ port #{@port}
33
+ bind "127.0.0.1"
34
+ body_size_limit 10m
35
+ keepalive_timeout 5
36
+ respond_with_empty_img true
37
+ use_204_response false
38
+ ]
39
+ end
40
+
41
+ def create_driver(conf=config)
39
42
  Fluent::Test::Driver::Input.new(Fluent::Plugin::HttpInput).configure(conf)
40
43
  end
41
44
 
42
45
  def test_configure
43
46
  d = create_driver
44
- assert_equal PORT, d.instance.port
47
+ assert_equal @port, d.instance.port
45
48
  assert_equal '127.0.0.1', d.instance.bind
46
49
  assert_equal 10*1024*1024, d.instance.body_size_limit
47
50
  assert_equal 5, d.instance.keepalive_timeout
@@ -121,7 +124,7 @@ class HttpInputTest < Test::Unit::TestCase
121
124
  'msgpack' => ['msgpack', :to_msgpack])
122
125
  def test_default_with_time_format(data)
123
126
  param, method_name = data
124
- d = create_driver(CONFIG + %[
127
+ d = create_driver(config + %[
125
128
  <parse>
126
129
  keep_time_key
127
130
  time_format %iso8601
@@ -198,7 +201,7 @@ class HttpInputTest < Test::Unit::TestCase
198
201
  'msgpack' => ['msgpack', :to_msgpack])
199
202
  def test_default_multi_with_time_format(data)
200
203
  param, method_name = data
201
- d = create_driver(CONFIG + %[
204
+ d = create_driver(config + %[
202
205
  <parse>
203
206
  keep_time_key
204
207
  time_format %iso8601
@@ -222,7 +225,7 @@ class HttpInputTest < Test::Unit::TestCase
222
225
  end
223
226
 
224
227
  def test_multi_json_with_nonexistent_time_key
225
- d = create_driver(CONFIG + %[
228
+ d = create_driver(config + %[
226
229
  <parse>
227
230
  time_key missing
228
231
  </parse>
@@ -245,7 +248,7 @@ class HttpInputTest < Test::Unit::TestCase
245
248
  end
246
249
 
247
250
  def test_json_with_add_remote_addr
248
- d = create_driver(CONFIG + "add_remote_addr true")
251
+ d = create_driver(config + "add_remote_addr true")
249
252
  time = event_time("2011-01-02 13:14:15 UTC")
250
253
  time_i = time.to_i
251
254
 
@@ -267,7 +270,7 @@ class HttpInputTest < Test::Unit::TestCase
267
270
  end
268
271
 
269
272
  def test_exact_match_for_expect
270
- d = create_driver(CONFIG)
273
+ d = create_driver(config)
271
274
  records = [{ "a" => 1}, { "a" => 2 }]
272
275
  tag = "tag1"
273
276
  res_codes = []
@@ -280,7 +283,7 @@ class HttpInputTest < Test::Unit::TestCase
280
283
  end
281
284
 
282
285
  def test_exact_match_for_expect_with_other_header
283
- d = create_driver(CONFIG)
286
+ d = create_driver(config)
284
287
 
285
288
  records = [{ "a" => 1}, { "a" => 2 }]
286
289
  tag = "tag1"
@@ -299,7 +302,7 @@ class HttpInputTest < Test::Unit::TestCase
299
302
  end
300
303
 
301
304
  def test_multi_json_with_add_remote_addr
302
- d = create_driver(CONFIG + "add_remote_addr true")
305
+ d = create_driver(config + "add_remote_addr true")
303
306
  time = event_time("2011-01-02 13:14:15 UTC")
304
307
  time_i = time.to_i
305
308
 
@@ -324,7 +327,7 @@ class HttpInputTest < Test::Unit::TestCase
324
327
  end
325
328
 
326
329
  def test_json_with_add_remote_addr_given_x_forwarded_for
327
- d = create_driver(CONFIG + "add_remote_addr true")
330
+ d = create_driver(config + "add_remote_addr true")
328
331
  time = event_time("2011-01-02 13:14:15 UTC")
329
332
  time_i = time.to_i
330
333
 
@@ -352,7 +355,7 @@ class HttpInputTest < Test::Unit::TestCase
352
355
  end
353
356
 
354
357
  def test_multi_json_with_add_remote_addr_given_x_forwarded_for
355
- d = create_driver(CONFIG + "add_remote_addr true")
358
+ d = create_driver(config + "add_remote_addr true")
356
359
 
357
360
  tag = "tag1"
358
361
  time = event_time("2011-01-02 13:14:15 UTC")
@@ -375,7 +378,7 @@ class HttpInputTest < Test::Unit::TestCase
375
378
  end
376
379
 
377
380
  def test_add_remote_addr_given_multi_x_forwarded_for
378
- d = create_driver(CONFIG + "add_remote_addr true")
381
+ d = create_driver(config + "add_remote_addr true")
379
382
 
380
383
  tag = "tag1"
381
384
  time = event_time("2011-01-02 13:14:15 UTC")
@@ -406,7 +409,7 @@ class HttpInputTest < Test::Unit::TestCase
406
409
  end
407
410
 
408
411
  def test_multi_json_with_add_http_headers
409
- d = create_driver(CONFIG + "add_http_headers true")
412
+ d = create_driver(config + "add_http_headers true")
410
413
  time = event_time("2011-01-02 13:14:15 UTC")
411
414
  time_i = time.to_i
412
415
  records = [{"a"=>1},{"a"=>2}]
@@ -432,7 +435,7 @@ class HttpInputTest < Test::Unit::TestCase
432
435
  end
433
436
 
434
437
  def test_json_with_add_http_headers
435
- d = create_driver(CONFIG + "add_http_headers true")
438
+ d = create_driver(config + "add_http_headers true")
436
439
  time = event_time("2011-01-02 13:14:15 UTC")
437
440
  time_i = time.to_i
438
441
  events = [
@@ -462,7 +465,7 @@ class HttpInputTest < Test::Unit::TestCase
462
465
  end
463
466
 
464
467
  def test_multi_json_with_custom_parser
465
- d = create_driver(CONFIG + %[
468
+ d = create_driver(config + %[
466
469
  <parse>
467
470
  @type json
468
471
  keep_time_key true
@@ -584,7 +587,7 @@ class HttpInputTest < Test::Unit::TestCase
584
587
  end
585
588
 
586
589
  def test_with_regexp
587
- d = create_driver(CONFIG + %[
590
+ d = create_driver(config + %[
588
591
  format /^(?<field_1>\\d+):(?<field_2>\\w+)$/
589
592
  types field_1:integer
590
593
  ])
@@ -615,7 +618,7 @@ class HttpInputTest < Test::Unit::TestCase
615
618
  def test_with_csv
616
619
  require 'csv'
617
620
 
618
- d = create_driver(CONFIG + %[
621
+ d = create_driver(config + %[
619
622
  format csv
620
623
  keys foo,bar
621
624
  ])
@@ -641,7 +644,7 @@ class HttpInputTest < Test::Unit::TestCase
641
644
  end
642
645
 
643
646
  def test_response_with_empty_img
644
- d = create_driver(CONFIG)
647
+ d = create_driver(config)
645
648
  assert_equal true, d.instance.respond_with_empty_img
646
649
 
647
650
  time = event_time("2011-01-02 13:14:15 UTC")
@@ -669,7 +672,7 @@ class HttpInputTest < Test::Unit::TestCase
669
672
  end
670
673
 
671
674
  def test_response_without_empty_img
672
- d = create_driver(CONFIG + "respond_with_empty_img false")
675
+ d = create_driver(config + "respond_with_empty_img false")
673
676
  assert_equal false, d.instance.respond_with_empty_img
674
677
 
675
678
  time = event_time("2011-01-02 13:14:15 UTC")
@@ -695,7 +698,7 @@ class HttpInputTest < Test::Unit::TestCase
695
698
  end
696
699
 
697
700
  def test_response_use_204_response
698
- d = create_driver(CONFIG + %[
701
+ d = create_driver(config + %[
699
702
  respond_with_empty_img false
700
703
  use_204_response true
701
704
  ])
@@ -724,7 +727,7 @@ class HttpInputTest < Test::Unit::TestCase
724
727
  end
725
728
 
726
729
  def test_cors_allowed
727
- d = create_driver(CONFIG + "cors_allow_origins [\"http://foo.com\"]")
730
+ d = create_driver(config + "cors_allow_origins [\"http://foo.com\"]")
728
731
  assert_equal ["http://foo.com"], d.instance.cors_allow_origins
729
732
 
730
733
  time = event_time("2011-01-02 13:14:15 UTC")
@@ -751,7 +754,7 @@ class HttpInputTest < Test::Unit::TestCase
751
754
  end
752
755
 
753
756
  def test_cors_allowed_wildcard
754
- d = create_driver(CONFIG + 'cors_allow_origins ["*"]')
757
+ d = create_driver(config + 'cors_allow_origins ["*"]')
755
758
 
756
759
  time = event_time("2011-01-02 13:14:15 UTC")
757
760
  events = [
@@ -771,7 +774,7 @@ class HttpInputTest < Test::Unit::TestCase
771
774
  end
772
775
 
773
776
  def test_get_request
774
- d = create_driver(CONFIG)
777
+ d = create_driver(config)
775
778
 
776
779
  d.run do
777
780
  res = get("/cors.test", {}, {})
@@ -780,7 +783,7 @@ class HttpInputTest < Test::Unit::TestCase
780
783
  end
781
784
 
782
785
  def test_cors_preflight
783
- d = create_driver(CONFIG + 'cors_allow_origins ["*"]')
786
+ d = create_driver(config + 'cors_allow_origins ["*"]')
784
787
 
785
788
  d.run do
786
789
  header = {
@@ -797,7 +800,7 @@ class HttpInputTest < Test::Unit::TestCase
797
800
  end
798
801
 
799
802
  def test_cors_allowed_wildcard_for_subdomain
800
- d = create_driver(CONFIG + 'cors_allow_origins ["http://*.foo.com"]')
803
+ d = create_driver(config + 'cors_allow_origins ["http://*.foo.com"]')
801
804
 
802
805
  time = event_time("2011-01-02 13:14:15 UTC")
803
806
  events = [
@@ -817,7 +820,7 @@ class HttpInputTest < Test::Unit::TestCase
817
820
  end
818
821
 
819
822
  def test_cors_allowed_exclude_empty_string
820
- d = create_driver(CONFIG + 'cors_allow_origins ["", "http://*.foo.com"]')
823
+ d = create_driver(config + 'cors_allow_origins ["", "http://*.foo.com"]')
821
824
 
822
825
  time = event_time("2011-01-02 13:14:15 UTC")
823
826
  events = [
@@ -837,7 +840,7 @@ class HttpInputTest < Test::Unit::TestCase
837
840
  end
838
841
 
839
842
  def test_cors_allowed_wildcard_preflight_for_subdomain
840
- d = create_driver(CONFIG + 'cors_allow_origins ["http://*.foo.com"]')
843
+ d = create_driver(config + 'cors_allow_origins ["http://*.foo.com"]')
841
844
 
842
845
  d.run do
843
846
  header = {
@@ -853,6 +856,46 @@ class HttpInputTest < Test::Unit::TestCase
853
856
  end
854
857
  end
855
858
 
859
+ def test_cors_allow_credentials
860
+ d = create_driver(config + %[
861
+ cors_allow_origins ["http://foo.com"]
862
+ cors_allow_credentials
863
+ ])
864
+ assert_equal true, d.instance.cors_allow_credentials
865
+
866
+ time = event_time("2011-01-02 13:14:15 UTC")
867
+ event = ["tag1", time, {"a"=>1}]
868
+ res_code = nil
869
+ res_header = nil
870
+
871
+ d.run do
872
+ res = post("/#{event[0]}", {"json"=>event[2].to_json, "time"=>time.to_i.to_s}, {"Origin"=>"http://foo.com"})
873
+ res_code = res.code
874
+ res_header = res["Access-Control-Allow-Credentials"]
875
+ end
876
+ assert_equal(
877
+ {
878
+ response_code: "200",
879
+ allow_credentials_header: "true",
880
+ events: [event]
881
+ },
882
+ {
883
+ response_code: res_code,
884
+ allow_credentials_header: res_header,
885
+ events: d.events
886
+ }
887
+ )
888
+ end
889
+
890
+ def test_cors_allow_credentials_for_wildcard_origins
891
+ assert_raise(Fluent::ConfigError) do
892
+ create_driver(config + %[
893
+ cors_allow_origins ["*"]
894
+ cors_allow_credentials
895
+ ])
896
+ end
897
+ end
898
+
856
899
  def test_content_encoding_gzip
857
900
  d = create_driver
858
901
 
@@ -900,7 +943,7 @@ class HttpInputTest < Test::Unit::TestCase
900
943
  end
901
944
 
902
945
  def test_cors_disallowed
903
- d = create_driver(CONFIG + "cors_allow_origins [\"http://foo.com\"]")
946
+ d = create_driver(config + "cors_allow_origins [\"http://foo.com\"]")
904
947
  assert_equal ["http://foo.com"], d.instance.cors_allow_origins
905
948
 
906
949
  time = event_time("2011-01-02 13:14:15 UTC")
@@ -918,7 +961,7 @@ class HttpInputTest < Test::Unit::TestCase
918
961
  end
919
962
 
920
963
  def test_add_query_params
921
- d = create_driver(CONFIG + "add_query_params true")
964
+ d = create_driver(config + "add_query_params true")
922
965
  assert_equal true, d.instance.add_query_params
923
966
 
924
967
  time = event_time("2011-01-02 13:14:15 UTC")
@@ -978,7 +1021,7 @@ class HttpInputTest < Test::Unit::TestCase
978
1021
  $test_in_http_content_types_flag = true
979
1022
  d.run do
980
1023
  # Send two requests the second one has no Content-Type in Keep-Alive
981
- Net::HTTP.start("127.0.0.1", PORT) do |http|
1024
+ Net::HTTP.start("127.0.0.1", @port) do |http|
982
1025
  req = Net::HTTP::Post.new("/foodb/bartbl", {"connection" => "keepalive", "Content-Type" => "application/json"})
983
1026
  http.request(req)
984
1027
  req = Net::HTTP::Get.new("/foodb/bartbl", {"connection" => "keepalive"})
@@ -995,19 +1038,19 @@ class HttpInputTest < Test::Unit::TestCase
995
1038
  end
996
1039
 
997
1040
  def get(path, params, header = {})
998
- http = Net::HTTP.new("127.0.0.1", PORT)
1041
+ http = Net::HTTP.new("127.0.0.1", @port)
999
1042
  req = Net::HTTP::Get.new(path, header)
1000
1043
  http.request(req)
1001
1044
  end
1002
1045
 
1003
1046
  def options(path, params, header = {})
1004
- http = Net::HTTP.new("127.0.0.1", PORT)
1047
+ http = Net::HTTP.new("127.0.0.1", @port)
1005
1048
  req = Net::HTTP::Options.new(path, header)
1006
1049
  http.request(req)
1007
1050
  end
1008
1051
 
1009
1052
  def post(path, params, header = {}, &block)
1010
- http = Net::HTTP.new("127.0.0.1", PORT)
1053
+ http = Net::HTTP.new("127.0.0.1", @port)
1011
1054
  req = Net::HTTP::Post.new(path, header)
1012
1055
  block.call(http, req) if block
1013
1056
  if params.is_a?(String)
@@ -37,6 +37,194 @@ class MonitorAgentInputTest < Test::Unit::TestCase
37
37
  assert_true d.instance.include_config
38
38
  end
39
39
 
40
+ sub_test_case "collect in_monitor_agent plugin statistics" do
41
+ # Input Test Driver does not register metric callbacks.
42
+ # We should stub them here.
43
+ class TestEventMetricRouter < Fluent::Test::Driver::TestEventRouter
44
+ def initialize(driver)
45
+ super
46
+
47
+ raise ArgumentError, "plugin does not respond metric_callback method" unless @driver.instance.respond_to?(:metric_callback)
48
+ end
49
+
50
+ def emit(tag, time, record)
51
+ super
52
+ @driver.instance.metric_callback(OneEventStream.new(time, record))
53
+ end
54
+
55
+ def emit_array(tag, array)
56
+ super
57
+ @driver.instance.metric_callback(ArrayEventStream.new(array))
58
+ end
59
+
60
+ def emit_stream(tag, es)
61
+ super
62
+ @driver.instance.metric_callback(es)
63
+ end
64
+ end
65
+
66
+ class MetricInputDriver < Fluent::Test::Driver::Input
67
+ def configure(conf, syntax: :v1)
68
+ if conf.is_a?(Fluent::Config::Element)
69
+ @config = conf
70
+ else
71
+ @config = Fluent::Config.parse(conf, "(test)", "(test_dir)", syntax: syntax)
72
+ end
73
+
74
+ if @instance.respond_to?(:router=)
75
+ @event_streams = []
76
+ @error_events = []
77
+
78
+ driver = self
79
+ mojule = Module.new do
80
+ define_method(:event_emitter_router) do |label_name|
81
+ TestEventMetricRouter.new(driver)
82
+ end
83
+ end
84
+ @instance.singleton_class.prepend mojule
85
+ end
86
+
87
+ @instance.configure(@config)
88
+ self
89
+ end
90
+ end
91
+
92
+ setup do
93
+ # check @type and type in one configuration
94
+ conf = <<-EOC
95
+ <source>
96
+ @type test_in_gen
97
+ @id test_in_gen
98
+ num 10
99
+ </source>
100
+ <filter>
101
+ @type test_filter
102
+ @id test_filter
103
+ </filter>
104
+ <match **>
105
+ @type relabel
106
+ @id test_relabel
107
+ @label @test
108
+ </match>
109
+ <label @test>
110
+ <match **>
111
+ @type test_out
112
+ @id test_out
113
+ </match>
114
+ </label>
115
+ <label @copy>
116
+ <match **>
117
+ @type copy
118
+ <store>
119
+ @type test_out
120
+ @id copy_out_1
121
+ </store>
122
+ <store>
123
+ @type test_out
124
+ @id copy_out_2
125
+ </store>
126
+ </match>
127
+ </label>
128
+ <label @ERROR>
129
+ <match>
130
+ @type null
131
+ @id null
132
+ </match>
133
+ </label>
134
+ EOC
135
+ @ra = Fluent::RootAgent.new(log: $log)
136
+ stub(Fluent::Engine).root_agent { @ra }
137
+ @ra = configure_ra(@ra, conf)
138
+ end
139
+
140
+ data(:with_config_yes => true,
141
+ :with_config_no => false)
142
+ def test_enable_input_metrics(with_config)
143
+ monitor_agent_conf = <<-CONF
144
+ tag test.monitor
145
+ emit_interval 1
146
+ CONF
147
+ @ra.inputs.first.context_router.emit("test.event", Fluent::Engine.now, {"message":"ok"})
148
+ d = MetricInputDriver.new(Fluent::Plugin::MonitorAgentInput).configure(monitor_agent_conf)
149
+ d.run(expect_emits: 1, timeout: 3)
150
+
151
+ test_label = @ra.labels['@test']
152
+ error_label = @ra.labels['@ERROR']
153
+ input_info = {
154
+ "output_plugin" => false,
155
+ "plugin_category"=> "input",
156
+ "plugin_id" => "test_in_gen",
157
+ "retry_count" => nil,
158
+ "type" => "test_in_gen",
159
+ "emit_records" => 0, # This field is not updated due to not to be assigned metric callback.
160
+ "emit_size" => 0, # Ditto.
161
+ }
162
+ input_info.merge!("config" => {"@id" => "test_in_gen", "@type" => "test_in_gen", "num" => "10"}) if with_config
163
+ filter_info = {
164
+ "output_plugin" => false,
165
+ "plugin_category" => "filter",
166
+ "plugin_id" => "test_filter",
167
+ "retry_count" => nil,
168
+ "type" => "test_filter",
169
+ "emit_records" => Integer,
170
+ "emit_size" => Integer,
171
+ }
172
+ filter_info.merge!("config" => {"@id" => "test_filter", "@type" => "test_filter"}) if with_config
173
+ output_info = {
174
+ "output_plugin" => true,
175
+ "plugin_category" => "output",
176
+ "plugin_id" => "test_out",
177
+ "retry_count" => 0,
178
+ "type" => "test_out",
179
+ "emit_count" => Integer,
180
+ "emit_records" => Integer,
181
+ "emit_size" => Integer,
182
+ "write_count" => Integer,
183
+ "rollback_count" => Integer,
184
+ "slow_flush_count" => Integer,
185
+ "flush_time_count" => Integer,
186
+ }
187
+ output_info.merge!("config" => {"@id" => "test_out", "@type" => "test_out"}) if with_config
188
+ error_label_info = {
189
+ "buffer_queue_length" => 0,
190
+ "buffer_timekeys" => [],
191
+ "buffer_total_queued_size" => 0,
192
+ "output_plugin" => true,
193
+ "plugin_category" => "output",
194
+ "plugin_id" => "null",
195
+ "retry_count" => 0,
196
+ "type" => "null",
197
+ "buffer_available_buffer_space_ratios" => Float,
198
+ "buffer_queue_byte_size" => Integer,
199
+ "buffer_stage_byte_size" => Integer,
200
+ "buffer_stage_length" => Integer,
201
+ "emit_count" => Integer,
202
+ "emit_records" => Integer,
203
+ "emit_size" => Integer,
204
+ "write_count" => Integer,
205
+ "rollback_count" => Integer,
206
+ "slow_flush_count" => Integer,
207
+ "flush_time_count" => Integer,
208
+ }
209
+ error_label_info.merge!("config" => {"@id"=>"null", "@type" => "null"}) if with_config
210
+ opts = {with_config: with_config}
211
+ assert_equal(input_info, d.instance.get_monitor_info(@ra.inputs.first, opts))
212
+ assert_fuzzy_equal(filter_info, d.instance.get_monitor_info(@ra.filters.first, opts))
213
+ assert_fuzzy_equal(output_info, d.instance.get_monitor_info(test_label.outputs.first, opts))
214
+ assert_fuzzy_equal(error_label_info, d.instance.get_monitor_info(error_label.outputs.first, opts))
215
+ monitor_agent_emit_info = {
216
+ "emit_records" => Integer,
217
+ "emit_size" => Integer,
218
+ }
219
+ filter_statistics_info = {
220
+ "emit_records" => Integer,
221
+ "emit_size" => Integer,
222
+ }
223
+ assert_fuzzy_equal(monitor_agent_emit_info, d.instance.statistics["input"])
224
+ assert_fuzzy_equal(filter_statistics_info, @ra.filters.first.statistics["filter"])
225
+ end
226
+ end
227
+
40
228
  sub_test_case "collect plugin information" do
41
229
  setup do
42
230
  # check @type and type in one configuration
@@ -106,7 +294,9 @@ EOC
106
294
  "plugin_category"=> "input",
107
295
  "plugin_id" => "test_in",
108
296
  "retry_count" => nil,
109
- "type" => "test_in"
297
+ "type" => "test_in",
298
+ "emit_records" => 0,
299
+ "emit_size" => 0,
110
300
  }
111
301
  input_info.merge!("config" => {"@id" => "test_in", "@type" => "test_in"}) if with_config
112
302
  filter_info = {
@@ -114,7 +304,9 @@ EOC
114
304
  "plugin_category" => "filter",
115
305
  "plugin_id" => "test_filter",
116
306
  "retry_count" => nil,
117
- "type" => "test_filter"
307
+ "type" => "test_filter",
308
+ "emit_records" => 0,
309
+ "emit_size" => 0,
118
310
  }
119
311
  filter_info.merge!("config" => {"@id" => "test_filter", "@type" => "test_filter"}) if with_config
120
312
  output_info = {
@@ -125,6 +317,7 @@ EOC
125
317
  "type" => "test_out",
126
318
  "emit_count" => Integer,
127
319
  "emit_records" => Integer,
320
+ "emit_size" => Integer,
128
321
  "write_count" => Integer,
129
322
  "rollback_count" => Integer,
130
323
  "slow_flush_count" => Integer,
@@ -146,6 +339,7 @@ EOC
146
339
  "buffer_stage_length" => Integer,
147
340
  "emit_count" => Integer,
148
341
  "emit_records" => Integer,
342
+ "emit_size" => Integer,
149
343
  "write_count" => Integer,
150
344
  "rollback_count" => Integer,
151
345
  "slow_flush_count" => Integer,
@@ -220,6 +414,7 @@ EOC
220
414
  "retry_count" => 0,
221
415
  "emit_count" => Integer,
222
416
  "emit_records" => Integer,
417
+ "emit_size" => Integer,
223
418
  "write_count" => Integer,
224
419
  "rollback_count" => Integer,
225
420
  "slow_flush_count" => Integer,
@@ -233,6 +428,7 @@ EOC
233
428
  "retry_count" => 0,
234
429
  "emit_count" => Integer,
235
430
  "emit_records" => Integer,
431
+ "emit_size" => Integer,
236
432
  "write_count" => Integer,
237
433
  "rollback_count" => Integer,
238
434
  "slow_flush_count" => Integer,
@@ -322,9 +518,9 @@ EOC
322
518
  ")
323
519
  d.instance.start
324
520
  expected_test_in_response = "\
325
- plugin_id:test_in\tplugin_category:input\ttype:test_in\toutput_plugin:false\tretry_count:"
521
+ plugin_id:test_in\tplugin_category:input\ttype:test_in\toutput_plugin:false\tretry_count:\temit_records:0\temit_size:0"
326
522
  expected_test_filter_response = "\
327
- plugin_id:test_filter\tplugin_category:filter\ttype:test_filter\toutput_plugin:false\tretry_count:"
523
+ plugin_id:test_filter\tplugin_category:filter\ttype:test_filter\toutput_plugin:false\tretry_count:\temit_records:0\temit_size:0"
328
524
 
329
525
  response = get("http://127.0.0.1:#{@port}/api/plugins").body
330
526
  test_in = response.split("\n")[0]
@@ -350,7 +546,9 @@ plugin_id:test_filter\tplugin_category:filter\ttype:test_filter\toutput_plugin:f
350
546
  "plugin_category" => "input",
351
547
  "plugin_id" => "test_in",
352
548
  "retry_count" => nil,
353
- "type" => "test_in"
549
+ "type" => "test_in",
550
+ "emit_records" => 0,
551
+ "emit_size" => 0,
354
552
  }
355
553
  expected_test_in_response.merge!("config" => {"@id" => "test_in", "@type" => "test_in"}) if with_config
356
554
  expected_null_response = {
@@ -368,6 +566,7 @@ plugin_id:test_filter\tplugin_category:filter\ttype:test_filter\toutput_plugin:f
368
566
  "buffer_stage_length" => Integer,
369
567
  "emit_count" => Integer,
370
568
  "emit_records" => Integer,
569
+ "emit_size" => Integer,
371
570
  "write_count" => Integer,
372
571
  "rollback_count" => Integer,
373
572
  "slow_flush_count" => Integer,
@@ -412,7 +611,9 @@ plugin_id:test_filter\tplugin_category:filter\ttype:test_filter\toutput_plugin:f
412
611
  "plugin_category" => "input",
413
612
  "plugin_id" => "test_in",
414
613
  "retry_count" => nil,
415
- "type" => "test_in"
614
+ "type" => "test_in",
615
+ "emit_records" => 0,
616
+ "emit_size" => 0,
416
617
  }
417
618
  expected_test_in_response.merge!("config" => {"@id" => "test_in", "@type" => "test_in"}) if with_config
418
619
  expected_null_response = {
@@ -430,6 +631,7 @@ plugin_id:test_filter\tplugin_category:filter\ttype:test_filter\toutput_plugin:f
430
631
  "buffer_stage_length" => Integer,
431
632
  "emit_count" => Integer,
432
633
  "emit_records" => Integer,
634
+ "emit_size" => Integer,
433
635
  "write_count" => Integer,
434
636
  "rollback_count" => Integer,
435
637
  "slow_flush_count" => Integer,
@@ -458,7 +660,9 @@ plugin_id:test_filter\tplugin_category:filter\ttype:test_filter\toutput_plugin:f
458
660
  "plugin_id" => "test_in",
459
661
  "retry_count" => nil,
460
662
  "type" => "test_in",
461
- "instance_variables" => {"id" => "test_in"}
663
+ "instance_variables" => {"id" => "test_in"},
664
+ "emit_records" => 0,
665
+ "emit_size" => 0,
462
666
  }
463
667
  expected_null_response = {
464
668
  "buffer_queue_length" => 0,
@@ -469,13 +673,14 @@ plugin_id:test_filter\tplugin_category:filter\ttype:test_filter\toutput_plugin:f
469
673
  "plugin_id" => "null",
470
674
  "retry_count" => 0,
471
675
  "type" => "null",
472
- "instance_variables" => {"id" => "null", "num_errors" => 0},
676
+ "instance_variables" => {"id" => "null"},
473
677
  "buffer_available_buffer_space_ratios" => Float,
474
678
  "buffer_queue_byte_size" => Integer,
475
679
  "buffer_stage_byte_size" => Integer,
476
680
  "buffer_stage_length" => Integer,
477
681
  "emit_count" => Integer,
478
682
  "emit_records" => Integer,
683
+ "emit_size" => Integer,
479
684
  "write_count" => Integer,
480
685
  "rollback_count" => Integer,
481
686
  "slow_flush_count" => Integer,
@@ -606,6 +811,7 @@ plugin_id:test_filter\tplugin_category:filter\ttype:test_filter\toutput_plugin:f
606
811
  "buffer_stage_length" => Integer,
607
812
  "emit_count" => Integer,
608
813
  "emit_records" => Integer,
814
+ "emit_size" => Integer,
609
815
  "write_count" => Integer,
610
816
  "rollback_count" => Integer,
611
817
  'slow_flush_count' => Integer,