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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 969a6a02d586a34539327fcecf6eff5c9bc72a8a9683e9b75d0176797f9480c1
4
- data.tar.gz: 9e1c70429456286de80d8a3f44b4a7d8ca15a66caf2f6e2dc461e676b5b384a6
3
+ metadata.gz: 64c35dab27cb19ba6b8f33edd023c6dbcc100256b0f372e7f51f8d4dc99a3197
4
+ data.tar.gz: aedff69e17e8d8ce189920ee3249e5385b3dbde50157b8b83630e40e276ad8cf
5
5
  SHA512:
6
- metadata.gz: 8f6bb96d9a1080d508adb9cbefc1432b2a246691129deadf0a4a42b1e422da8b11a39c76b8c6a6d06b7ad5276ab91812165347fce04b141d29bb329edef6373b
7
- data.tar.gz: 2982233e3a6f4f3add4b5bf223edfe1d3c3e552611339b7afd14534d2b350c8771f0c7f2e6897aa7b390d2ebae44c54f8622ca7d5ad318caee65c72aa8bc1d1f
6
+ metadata.gz: '028c5a09fc99fac1c8be4a36c4ab1d2bdbd7c88178336771696d6e6e22393b6e2de14d42c7cfc2509a1e12b01b2204845ab1b342f0007badd75e46b96c7cd1b2'
7
+ data.tar.gz: 1440e86c8bc39de6bcd6a68624254a624d4d2d235460430c22dc0ae1ded7cf54eb985b1662101f3ab7ebd25b0faf3ffd9e101de8909ef1df8ec1f79784a7ad2d
data/README.md CHANGED
@@ -30,13 +30,49 @@ $ bundle
30
30
 
31
31
  ## Configuration
32
32
 
33
- ### obsolete_plugins_yml (string) (optional)
33
+ ### Filter plugin
34
34
 
35
- Path to obsolete-plugins.yml
35
+ #### plugins_json (string) (optional)
36
36
 
37
- Default value: `https://raw.githubusercontent.com/fluent/fluentd-website/master/scripts/obsolete-plugins.yml`.
37
+ Path to `plugins.json`.
38
38
 
39
- ### raise_error (bool) (optional)
39
+ Default value: `https://raw.githubusercontent.com/fluent/fluentd-website/master/scripts/plugins.json`.
40
+
41
+ #### Deprecated: obsolete_plugins_yml (string) (optional)
42
+
43
+ Path to `obsolete-plugins.yml`. This parameter is deprecated. Please use `plugins_json` parameter instead.
44
+
45
+ Default value: `nil`
46
+
47
+ #### timeout (integer) (optional)
48
+
49
+ Timeout to read data of obsolete plugins.
50
+ If it occurs timeout, it just skips to detect obsolete plugins.
51
+
52
+ Default value: `5`
53
+
54
+ #### raise_error (bool) (optional)
55
+
56
+ Raise error if obsolete plugins are detected
57
+
58
+ Default value: `false`.
59
+
60
+ ### Input plugin
61
+
62
+ #### plugins_json (string) (optional)
63
+
64
+ Path to `plugins.json`.
65
+
66
+ Default value: `https://raw.githubusercontent.com/fluent/fluentd-website/master/scripts/plugins.json`.
67
+
68
+ #### timeout (integer) (optional)
69
+
70
+ Timeout to read data of obsolete plugins.
71
+ If it occurs timeout, it just skips to detect obsolete plugins.
72
+
73
+ Default value: `5`
74
+
75
+ #### raise_error (bool) (optional)
40
76
 
41
77
  Raise error if obsolete plugins are detected
42
78
 
@@ -3,7 +3,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
3
 
4
4
  Gem::Specification.new do |spec|
5
5
  spec.name = "fluent-plugin-obsolete-plugins"
6
- spec.version = "0.1.1"
6
+ spec.version = "0.2.0"
7
7
  spec.authors = ["okkez"]
8
8
  spec.email = ["okkez000@gmail.com"]
9
9
 
@@ -14,35 +14,39 @@
14
14
  # limitations under the License.
15
15
 
16
16
  require "fluent/plugin/filter"
17
- require "open-uri"
18
- require "yaml"
17
+ require "fluent/plugin/obsolete_plugins_utils"
19
18
 
20
19
  module Fluent
21
20
  module Plugin
22
21
  class ObsoletePluginsFilter < Fluent::Plugin::Filter
23
22
  Fluent::Plugin.register_filter("obsolete_plugins", self)
24
23
 
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"
26
25
 
27
26
  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
30
+ desc "Timeout value to read data of obsolete plugins"
31
+ config_param :timeout, :integer, default: 5
29
32
  desc "Raise error if obsolete plugins are detected"
30
33
  config_param :raise_error, :bool, default: false
31
34
 
32
35
  def configure(conf)
33
36
  super
34
37
 
35
- @obsolete_plugins = 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
38
+ obsolete_plugins =
39
+ if @obsolete_plugins_yml
40
+ ObsoletePluginsUtils.obsolete_plugins_from_yaml(@obsolete_plugins_yml, timeout: @timeout)
41
+ else
42
+ ObsoletePluginsUtils.obsolete_plugins_from_json(@plugins_json, timeout: @timeout)
43
+ end
44
+
45
+ ObsoletePluginsUtils.notify(log, obsolete_plugins, raise_error: @raise_error)
46
+ rescue Fluent::ConfigError
47
+ raise
48
+ rescue => e
49
+ log.info("Failed to notify obsolete plugins", error: e)
46
50
  end
47
51
 
48
52
  def filter(tag, time, record)
@@ -0,0 +1,30 @@
1
+ require "fluent/plugin/input"
2
+ require "fluent/plugin/obsolete_plugins_utils"
3
+
4
+ module Fluent
5
+ module Plugin
6
+ class ObsoletePluginsInput < Fluent::Plugin::Input
7
+ Fluent::Plugin.register_input("obsolete_plugins", self)
8
+
9
+ PLUGINS_JSON_URL = "https://raw.githubusercontent.com/fluent/fluentd-website/master/scripts/plugins.json"
10
+
11
+ desc "Path to plugins.json"
12
+ config_param :plugins_json, :string, default: PLUGINS_JSON_URL
13
+ desc "Timeout value to read data of obsolete plugins"
14
+ config_param :timeout, :integer, default: 5
15
+ desc "Raise error if obsolete plugins are detected"
16
+ config_param :raise_error, :bool, default: false
17
+
18
+ def configure(conf)
19
+ super
20
+
21
+ obsolete_plugins = ObsoletePluginsUtils.obsolete_plugins_from_json(@plugins_json, timeout: @timeout)
22
+ ObsoletePluginsUtils.notify(log, obsolete_plugins, raise_error: @raise_error)
23
+ rescue Fluent::ConfigError
24
+ raise
25
+ rescue => e
26
+ log.info("Failed to notify obsolete plugins", error: e)
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,40 @@
1
+ require "fluent/config/error"
2
+ require "open-uri"
3
+ require "yaml"
4
+ require "json"
5
+ require "timeout"
6
+
7
+ class Fluent::Plugin::ObsoletePluginsUtils
8
+ def self.obsolete_plugins_from_yaml(url, timeout: 5)
9
+ Timeout.timeout(timeout) do
10
+ URI.open(url) do |io|
11
+ YAML.safe_load(io.read)
12
+ end
13
+ end
14
+ end
15
+
16
+ def self.obsolete_plugins_from_json(url, timeout: 5)
17
+ plugins = Timeout.timeout(timeout) do
18
+ URI.open(url) do |io|
19
+ # io.read causes Encoding::UndefinedConversionError with UTF-8 data when Ruby is started with "-Eascii-8bit:ascii-8bit".
20
+ # It set the proper encoding to avoid the error.
21
+ io.set_encoding("UTF-8", "UTF-8")
22
+ JSON.parse(io.read)
23
+ end
24
+ end
25
+ plugins.select { |plugin| plugin["obsolete"] }.reduce({}) do |result, plugin|
26
+ result[plugin["name"]] = plugin["note"]
27
+ result
28
+ end
29
+ end
30
+
31
+ def self.notify(logger, obsolete_plugins, raise_error: false)
32
+ plugins = Gem.loaded_specs.keys & obsolete_plugins.keys
33
+ plugins.each do |name|
34
+ logger.warn("#{name} is obsolete: #{obsolete_plugins[name].chomp}")
35
+ end
36
+ if raise_error && !plugins.empty?
37
+ raise Fluent::ConfigError, "Detected obsolete plugins"
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,11 @@
1
+ [
2
+ {
3
+ "obsolete": null,
4
+ "note": null,
5
+ "name": "fluent-plugin-s3",
6
+ "info": "Amazon S3 output plugin for Fluentd event collector",
7
+ "authors": "Sadayuki Furuhashi, Masahiro Nakagawa",
8
+ "version": "1.8.3",
9
+ "downloads": 134522742,
10
+ "homepage_uri": "https://github.com/fluent/fluent-plugin-s3",
11
+ "source_code_uri": null