fluent-plugin-obsolete-plugins 0.1.1 → 0.2.0

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.
data/test/helper.rb CHANGED
@@ -3,7 +3,6 @@ require "test-unit"
3
3
  require "test/unit/rr"
4
4
  require "timecop"
5
5
  require "fluent/test"
6
- require "fluent/test/driver/filter"
7
6
  require "fluent/test/helpers"
8
7
 
9
8
  Test::Unit::TestCase.include(Fluent::Test::Helpers)
@@ -1,14 +1,11 @@
1
1
  require "helper"
2
- require "fluent/plugin/filter_obsolete_plugins.rb"
2
+ require "fluent/test/driver/filter"
3
+ require "fluent/plugin/filter_obsolete_plugins"
3
4
 
4
5
  class ObsoletePluginsFilterTest < Test::Unit::TestCase
5
- CONFIG = %[
6
- obsolete_plugins_yml #{fixture_path("obsolete-plugins.yml")}
7
- ]
8
6
 
9
7
  setup do
10
8
  Fluent::Test.setup
11
- $log = Fluent::Test::TestLogger.new
12
9
  @time = Time.now
13
10
  Timecop.freeze(@time)
14
11
  end
@@ -17,46 +14,138 @@ class ObsoletePluginsFilterTest < Test::Unit::TestCase
17
14
  Timecop.return
18
15
  end
19
16
 
20
- test "no obsolete plugins" do
21
- d = create_driver(CONFIG)
22
- d.run(default_tag: "test") do
23
- d.feed({ message: "This is test message." })
17
+ sub_test_case "obsolete_plugins_yml" do
18
+ CONFIG_YAML = %[
19
+ obsolete_plugins_yml #{fixture_path("obsolete-plugins.yml")}
20
+ ]
21
+
22
+ test "no obsolete plugins" do
23
+ d = create_driver(CONFIG_YAML)
24
+ d.run(default_tag: "test") do
25
+ d.feed({ message: "This is test message." })
26
+ end
27
+ assert_equal([{ message: "This is test message." }], d.filtered_records)
28
+ expected_logs = [
29
+ "#{@time} [warn]: 'obsolete_plugins_yml' parameter is deprecated: use plugins_json parameter instead\n",
30
+ ]
31
+ assert_equal(expected_logs, d.logs)
24
32
  end
25
- assert_equal([{ message: "This is test message." }], d.filtered_records)
26
- assert_equal([], d.logs)
27
- end
28
33
 
29
- test "obsolete plugins" do
30
- mock(Gem).loaded_specs do
31
- {
32
- "fluent-plugin-tail-multiline" => nil,
33
- "fluent-plugin-hostname" => nil
34
- }
34
+ test "obsolete plugins" do
35
+ mock(Gem).loaded_specs do
36
+ {
37
+ "fluent-plugin-tail-multiline" => nil,
38
+ "fluent-plugin-hostname" => nil
39
+ }
40
+ end
41
+ d = create_driver(CONFIG_YAML)
42
+ d.run(default_tag: "test") do
43
+ d.feed({ message: "This is test message." })
44
+ end
45
+ assert_equal([{ message: "This is test message." }], d.filtered_records)
46
+ expected_logs = [
47
+ "#{@time} [warn]: 'obsolete_plugins_yml' parameter is deprecated: use plugins_json parameter instead\n",
48
+ "#{@time} [warn]: fluent-plugin-tail-multiline is obsolete: Merged in in_tail in Fluentd v0.10.45. [fluent/fluentd#269](https://github.com/fluent/fluentd/issues/269)\n",
49
+ "#{@time} [warn]: fluent-plugin-hostname is obsolete: Use [filter\\_record\\_transformer](http://docs.fluentd.org/v0.12/articles/filter_record_transformer) instead.\n"
50
+ ]
51
+ assert_equal(expected_logs, d.logs)
35
52
  end
36
- d = create_driver(CONFIG)
37
- d.run(default_tag: "test") do
38
- d.feed({ message: "This is test message." })
53
+
54
+ test "raise error when detect obsolete plugins" do
55
+ mock(Gem).loaded_specs do
56
+ {
57
+ "fluent-plugin-tail-multiline" => nil,
58
+ "fluent-plugin-hostname" => nil
59
+ }
60
+ end
61
+
62
+ ex = assert_raise(Fluent::ConfigError) do
63
+ create_driver(CONFIG_YAML + "raise_error yes")
64
+ end
65
+ assert_equal("Detected obsolete plugins", ex.message)
39
66
  end
40
- assert_equal([{ message: "This is test message." }], d.filtered_records)
41
- expected_logs = [
42
- "#{@time} [warn]: fluent-plugin-tail-multiline is obsolete: Merged in in_tail in Fluentd v0.10.45. [fluent/fluentd#269](https://github.com/fluent/fluentd/issues/269)\n",
43
- "#{@time} [warn]: fluent-plugin-hostname is obsolete: Use [filter\\_record\\_transformer](http://docs.fluentd.org/v0.12/articles/filter_record_transformer) instead.\n"
67
+ end
68
+
69
+ sub_test_case "plugins_json" do
70
+ CONFIG_JSON = %[
71
+ plugins_json #{fixture_path("plugins.json")}
44
72
  ]
45
- assert_equal(expected_logs, d.logs)
73
+
74
+ test "no obsolete plugins" do
75
+ d = create_driver(CONFIG_JSON)
76
+ d.run(default_tag: "test") do
77
+ d.feed({ message: "This is test message." })
78
+ end
79
+ assert_equal([{ message: "This is test message." }], d.filtered_records)
80
+ assert_equal([], d.logs)
81
+ end
82
+
83
+ test "obsolete plugins" do
84
+ mock(Gem).loaded_specs do
85
+ {
86
+ "fluent-plugin-tail-multiline" => nil,
87
+ "fluent-plugin-hostname" => nil
88
+ }
89
+ end
90
+ d = create_driver(CONFIG_JSON)
91
+ d.run(default_tag: "test") do
92
+ d.feed({ message: "This is test message." })
93
+ end
94
+ assert_equal([{ message: "This is test message." }], d.filtered_records)
95
+ expected_logs = [
96
+ "#{@time} [warn]: fluent-plugin-tail-multiline is obsolete: Merged in in_tail in Fluentd v0.10.45. [fluent/fluentd#269](https://github.com/fluent/fluentd/issues/269)\n",
97
+ "#{@time} [warn]: fluent-plugin-hostname is obsolete: Use [filter\\_record\\_transformer](http://docs.fluentd.org/v0.12/articles/filter_record_transformer) instead.\n"
98
+ ]
99
+ assert_equal(expected_logs, d.logs)
100
+ end
101
+
102
+ test "raise error when detect obsolete plugins" do
103
+ mock(Gem).loaded_specs do
104
+ {
105
+ "fluent-plugin-tail-multiline" => nil,
106
+ "fluent-plugin-hostname" => nil
107
+ }
108
+ end
109
+
110
+ ex = assert_raise(Fluent::ConfigError) do
111
+ create_driver(CONFIG_JSON + "raise_error yes")
112
+ end
113
+ assert_equal("Detected obsolete plugins", ex.message)
114
+ end
46
115
  end
47
116
 
48
- test "raise error when detect obsolete plugins" do
49
- mock(Gem).loaded_specs do
50
- {
51
- "fluent-plugin-tail-multiline" => nil,
52
- "fluent-plugin-hostname" => nil
53
- }
117
+ sub_test_case "error handling" do
118
+ test "invalid json" do
119
+ d = create_driver("plugins_json #{fixture_path('invalid.json')}")
120
+
121
+ expected_logs = [
122
+ "#{@time} [info]: Failed to notify obsolete plugins error_class=JSON::ParserError error=\"expected ',' or '}' after object value, got: EOF at line 11 column 1\"\n",
123
+ ]
124
+
125
+ assert_equal(expected_logs, d.logs)
54
126
  end
55
-
56
- ex = assert_raise(Fluent::ConfigError) do
57
- create_driver(CONFIG + "raise_error yes")
127
+
128
+ test "timeout with slow server" do
129
+ server = create_slow_webserver(port: 12345)
130
+
131
+ mock(Fluent::Plugin::ObsoletePluginsUtils).notify.never
132
+
133
+ d = create_driver(%[
134
+ plugins_json http://localhost:12345/plugins.json
135
+ timeout 1
136
+ ])
137
+
138
+ sleep 2
139
+
140
+ expected_logs = [
141
+ "#{@time} [info]: Failed to notify obsolete plugins error_class=Timeout::Error error=\"execution expired\"\n",
142
+ ]
143
+
144
+ assert_equal(expected_logs, d.logs)
145
+ ensure
146
+ server.shutdown
58
147
  end
59
- assert_equal("Detected obsolete plugins", ex.message)
148
+
60
149
  end
61
150
 
62
151
  private
@@ -64,4 +153,18 @@ class ObsoletePluginsFilterTest < Test::Unit::TestCase
64
153
  def create_driver(conf)
65
154
  Fluent::Test::Driver::Filter.new(Fluent::Plugin::ObsoletePluginsFilter).configure(conf)
66
155
  end
156
+
157
+ def create_slow_webserver(port: 12345)
158
+ require "webrick"
159
+
160
+ server = WEBrick::HTTPServer.new(Port: port)
161
+ server.mount_proc '/' do |req, res|
162
+ sleep 60
163
+
164
+ res['Content-Type'] = 'application/json'
165
+ res.body = File.read(fixture_path("plugins.json"))
166
+ end
167
+
168
+ server
169
+ end
67
170
  end
@@ -0,0 +1,115 @@
1
+ require "helper"
2
+ require "fluent/test/driver/input"
3
+ require "fluent/plugin/in_obsolete_plugins"
4
+ require "fluent/plugin/obsolete_plugins_utils"
5
+
6
+ class ObsoletePluginsInputTest < Test::Unit::TestCase
7
+
8
+ setup do
9
+ Fluent::Test.setup
10
+ @time = Time.now
11
+ Timecop.freeze(@time)
12
+ end
13
+
14
+ teardown do
15
+ Timecop.return
16
+ end
17
+
18
+ sub_test_case "plugins_json" do
19
+ CONFIG_JSON = %[
20
+ plugins_json #{fixture_path("plugins.json")}
21
+ ]
22
+
23
+ test "no obsolete plugins" do
24
+ d = create_driver(CONFIG_JSON)
25
+ d.run
26
+ assert_equal([], d.events)
27
+ assert_equal([], d.logs)
28
+ end
29
+
30
+ test "obsolete plugins" do
31
+ stub(Gem).loaded_specs do
32
+ {
33
+ "fluent-plugin-tail-multiline" => nil,
34
+ "fluent-plugin-hostname" => nil
35
+ }
36
+ end
37
+ d = create_driver(CONFIG_JSON)
38
+ d.run
39
+ assert_equal([], d.events)
40
+ expected_logs = [
41
+ "#{@time} [warn]: fluent-plugin-tail-multiline is obsolete: Merged in in_tail in Fluentd v0.10.45. [fluent/fluentd#269](https://github.com/fluent/fluentd/issues/269)\n",
42
+ "#{@time} [warn]: fluent-plugin-hostname is obsolete: Use [filter\\_record\\_transformer](http://docs.fluentd.org/v0.12/articles/filter_record_transformer) instead.\n"
43
+ ]
44
+ assert_equal(expected_logs, d.logs)
45
+ end
46
+
47
+ test "raise error when detect obsolete plugins" do
48
+ stub(Gem).loaded_specs do
49
+ {
50
+ "fluent-plugin-tail-multiline" => nil,
51
+ "fluent-plugin-hostname" => nil
52
+ }
53
+ end
54
+
55
+ ex = assert_raise(Fluent::ConfigError) do
56
+ create_driver(CONFIG_JSON + "raise_error yes")
57
+ end
58
+ assert_equal("Detected obsolete plugins", ex.message)
59
+ end
60
+ end
61
+
62
+ sub_test_case "error handling" do
63
+ test "invalid json" do
64
+ d = create_driver("plugins_json #{fixture_path('invalid.json')}")
65
+
66
+ expected_logs = [
67
+ "#{@time} [info]: Failed to notify obsolete plugins error_class=JSON::ParserError error=\"expected ',' or '}' after object value, got: EOF at line 11 column 1\"\n",
68
+ ]
69
+
70
+ assert_equal(expected_logs, d.logs)
71
+ end
72
+
73
+ test "timeout with slow server" do
74
+ server = create_slow_webserver(port: 12345)
75
+
76
+ mock(Fluent::Plugin::ObsoletePluginsUtils).notify.never
77
+
78
+ d = create_driver(%[
79
+ plugins_json http://localhost:12345/plugins.json
80
+ timeout 1
81
+ ])
82
+
83
+ sleep 2
84
+
85
+ expected_logs = [
86
+ "#{@time} [info]: Failed to notify obsolete plugins error_class=Timeout::Error error=\"execution expired\"\n",
87
+ ]
88
+
89
+ assert_equal(expected_logs, d.logs)
90
+ ensure
91
+ server.shutdown
92
+ end
93
+
94
+ end
95
+
96
+ private
97
+
98
+ def create_driver(conf)
99
+ Fluent::Test::Driver::Input.new(Fluent::Plugin::ObsoletePluginsInput).configure(conf)
100
+ end
101
+
102
+ def create_slow_webserver(port: 12345)
103
+ require "webrick"
104
+
105
+ server = WEBrick::HTTPServer.new(Port: port)
106
+ server.mount_proc '/' do |req, res|
107
+ sleep 60
108
+
109
+ res['Content-Type'] = 'application/json'
110
+ res.body = File.read(fixture_path("plugins.json"))
111
+ end
112
+
113
+ server
114
+ end
115
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-obsolete-plugins
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - okkez
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-04-23 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: bundler
@@ -114,9 +114,14 @@ files:
114
114
  - Rakefile
115
115
  - fluent-plugin-obsolete-plugins.gemspec
116
116
  - lib/fluent/plugin/filter_obsolete_plugins.rb
117
+ - lib/fluent/plugin/in_obsolete_plugins.rb
118
+ - lib/fluent/plugin/obsolete_plugins_utils.rb
119
+ - test/fixtures/invalid.json
117
120
  - test/fixtures/obsolete-plugins.yml
121
+ - test/fixtures/plugins.json
118
122
  - test/helper.rb
119
123
  - test/plugin/test_filter_obsolete_plugins.rb
124
+ - test/plugin/test_in_obsolete_plugins.rb
120
125
  homepage: https://github.com/okkez/fluent-plugin-obsolete-plugins
121
126
  licenses:
122
127
  - Apache-2.0
@@ -135,10 +140,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
135
140
  - !ruby/object:Gem::Version
136
141
  version: '0'
137
142
  requirements: []
138
- rubygems_version: 3.6.2
143
+ rubygems_version: 3.7.0
139
144
  specification_version: 4
140
145
  summary: Report obsolete plugins on boot
141
146
  test_files:
147
+ - test/fixtures/invalid.json
142
148
  - test/fixtures/obsolete-plugins.yml
149
+ - test/fixtures/plugins.json
143
150
  - test/helper.rb
144
151
  - test/plugin/test_filter_obsolete_plugins.rb
152
+ - test/plugin/test_in_obsolete_plugins.rb