Skip to content

Commit 5ed4a58

Browse files
authored
Add parameter to collect obsolete info using plugins.json (#5)
The obsolete information written in `obsolete-plugins.yml` is also included in `plugins.json`. In additional, there is a mechanism to automatically update obsolete information in `plugins.json`. Ref. fluent/fluentd-website#383 So, we can detect more obsolete plugins by switching to `plugin.json`.
1 parent b1e7152 commit 5ed4a58

File tree

5 files changed

+13295
-53
lines changed

5 files changed

+13295
-53
lines changed

README.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,18 @@ $ bundle
3030

3131
## Configuration
3232

33-
### obsolete_plugins_yml (string) (optional)
33+
### plugins_json (string) (optional)
3434

35-
Path to obsolete-plugins.yml
35+
Path to `plugins.json`.
3636

37-
Default value: `https://raw.githubusercontent.com/fluent/fluentd-website/master/scripts/obsolete-plugins.yml`.
37+
Default value: `https://raw.githubusercontent.com/fluent/fluentd-website/master/scripts/plugins.json`.
38+
39+
40+
### Deprecated: obsolete_plugins_yml (string) (optional)
41+
42+
Path to `obsolete-plugins.yml`. This parameter is deprecated. Please use `plugins_json` parameter instead.
43+
44+
Default value: `nil`
3845

3946
### raise_error (bool) (optional)
4047

lib/fluent/plugin/filter_obsolete_plugins.rb

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,35 +14,33 @@
1414
# limitations under the License.
1515

1616
require "fluent/plugin/filter"
17-
require "open-uri"
18-
require "yaml"
17+
require "fluent/plugin/obsolete_plugins_utils"
1918

2019
module Fluent
2120
module Plugin
2221
class ObsoletePluginsFilter < Fluent::Plugin::Filter
2322
Fluent::Plugin.register_filter("obsolete_plugins", self)
2423

25-
OBSOLETE_PLUGINS_URL = "https://raw.githubusercontent.com/fluent/fluentd-website/master/scripts/obsolete-plugins.yml"
24+
PLUGINS_JSON_URL = "https://raw.githubusercontent.com/fluent/fluentd-website/master/scripts/plugins.json"
2625

2726
desc "Path to obsolete-plugins.yml"
28-
config_param :obsolete_plugins_yml, :string, default: OBSOLETE_PLUGINS_URL
27+
config_param :obsolete_plugins_yml, :string, default: nil, deprecated: "use plugins_json parameter instead"
28+
desc "Path to plugins.json"
29+
config_param :plugins_json, :string, default: PLUGINS_JSON_URL
2930
desc "Raise error if obsolete plugins are detected"
3031
config_param :raise_error, :bool, default: false
3132

3233
def configure(conf)
3334
super
3435

35-
@obsolete_plugins = URI.open(@obsolete_plugins_yml) do |io|
36-
YAML.safe_load(io.read)
37-
end
38-
39-
obsolete_plugins = Gem.loaded_specs.keys & @obsolete_plugins.keys
40-
obsolete_plugins.each do |name|
41-
log.warn("#{name} is obsolete: #{@obsolete_plugins[name].chomp}")
42-
end
43-
if @raise_error && !obsolete_plugins.empty?
44-
raise Fluent::ConfigError, "Detected obsolete plugins"
45-
end
36+
obsolete_plugins =
37+
if @obsolete_plugins_yml
38+
ObsoletePluginsUtils.obsolete_plugins_from_yaml(@obsolete_plugins_yml)
39+
else
40+
ObsoletePluginsUtils.obsolete_plugins_from_json(@plugins_json)
41+
end
42+
43+
ObsoletePluginsUtils.notify(log, obsolete_plugins, raise_error: @raise_error)
4644
end
4745

4846
def filter(tag, time, record)
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
require "fluent/config/error"
2+
require "open-uri"
3+
require "yaml"
4+
require "json"
5+
6+
class Fluent::Plugin::ObsoletePluginsUtils
7+
def self.obsolete_plugins_from_yaml(url)
8+
URI.open(url) do |io|
9+
YAML.safe_load(io.read)
10+
end
11+
end
12+
13+
def self.obsolete_plugins_from_json(url)
14+
plugins = URI.open(url) do |io|
15+
# io.read causes Encoding::UndefinedConversionError with UTF-8 data when Ruby is started with "-Eascii-8bit:ascii-8bit".
16+
# It set the proper encoding to avoid the error.
17+
io.set_encoding("UTF-8", "UTF-8")
18+
JSON.parse(io.read)
19+
end
20+
plugins.select { |plugin| plugin["obsolete"] }.reduce({}) do |result, plugin|
21+
result[plugin["name"]] = plugin["note"]
22+
result
23+
end
24+
end
25+
26+
def self.notify(logger, obsolete_plugins, raise_error: false)
27+
plugins = Gem.loaded_specs.keys & obsolete_plugins.keys
28+
plugins.each do |name|
29+
logger.warn("#{name} is obsolete: #{obsolete_plugins[name].chomp}")
30+
end
31+
if raise_error && !plugins.empty?
32+
raise Fluent::ConfigError, "Detected obsolete plugins"
33+
end
34+
end
35+
end

0 commit comments

Comments
 (0)