-
Notifications
You must be signed in to change notification settings - Fork 3
Add input plugin #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
kenhys
merged 3 commits into
fluent-plugins-nursery:master
from
Watson1978:add-input-plugin
Aug 6, 2025
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| require "fluent/plugin/input" | ||
| require "fluent/plugin/obsolete_plugins_utils" | ||
|
|
||
| module Fluent | ||
| module Plugin | ||
| class ObsoletePluginsInput < Fluent::Plugin::Input | ||
| Fluent::Plugin.register_input("obsolete_plugins", self) | ||
|
|
||
| PLUGINS_JSON_URL = "https://raw.githubusercontent.com/fluent/fluentd-website/master/scripts/plugins.json" | ||
|
|
||
| desc "Path to plugins.json" | ||
| config_param :plugins_json, :string, default: PLUGINS_JSON_URL | ||
| desc "Timeout value to read data of obsolete plugins" | ||
| config_param :timeout, :integer, default: 5 | ||
| desc "Raise error if obsolete plugins are detected" | ||
| config_param :raise_error, :bool, default: false | ||
|
|
||
| def configure(conf) | ||
| super | ||
|
|
||
| obsolete_plugins = ObsoletePluginsUtils.obsolete_plugins_from_json(@plugins_json, timeout: @timeout) | ||
| ObsoletePluginsUtils.notify(log, obsolete_plugins, raise_error: @raise_error) | ||
| rescue Fluent::ConfigError | ||
| raise | ||
| rescue => e | ||
| log.info("Failed to notify obsolete plugins", error: e) | ||
| end | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| require "helper" | ||
| require "fluent/test/driver/input" | ||
| require "fluent/plugin/in_obsolete_plugins" | ||
| require "fluent/plugin/obsolete_plugins_utils" | ||
|
|
||
| class ObsoletePluginsInputTest < Test::Unit::TestCase | ||
|
|
||
| setup do | ||
| Fluent::Test.setup | ||
| $log = Fluent::Test::TestLogger.new | ||
| @time = Time.now | ||
| Timecop.freeze(@time) | ||
| end | ||
|
|
||
| teardown do | ||
| Timecop.return | ||
| end | ||
|
|
||
| sub_test_case "plugins_json" do | ||
| CONFIG_JSON = %[ | ||
| plugins_json #{fixture_path("plugins.json")} | ||
| ] | ||
|
|
||
| test "no obsolete plugins" do | ||
| d = create_driver(CONFIG_JSON) | ||
| d.run | ||
| assert_equal([], d.events) | ||
| assert_equal([], d.logs) | ||
| end | ||
|
|
||
| test "obsolete plugins" do | ||
| stub(Gem).loaded_specs do | ||
| { | ||
| "fluent-plugin-tail-multiline" => nil, | ||
| "fluent-plugin-hostname" => nil | ||
| } | ||
| end | ||
| d = create_driver(CONFIG_JSON) | ||
| d.run | ||
| assert_equal([], d.events) | ||
| expected_logs = [ | ||
| "#{@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", | ||
| "#{@time} [warn]: fluent-plugin-hostname is obsolete: Use [filter\\_record\\_transformer](http://docs.fluentd.org/v0.12/articles/filter_record_transformer) instead.\n" | ||
| ] | ||
| assert_equal(expected_logs, d.logs) | ||
| end | ||
|
|
||
| test "raise error when detect obsolete plugins" do | ||
| stub(Gem).loaded_specs do | ||
| { | ||
| "fluent-plugin-tail-multiline" => nil, | ||
| "fluent-plugin-hostname" => nil | ||
| } | ||
| end | ||
|
|
||
| ex = assert_raise(Fluent::ConfigError) do | ||
| create_driver(CONFIG_JSON + "raise_error yes") | ||
| end | ||
| assert_equal("Detected obsolete plugins", ex.message) | ||
| end | ||
| end | ||
|
|
||
| sub_test_case "error handling" do | ||
| test "invalid json" do | ||
| d = create_driver("plugins_json #{fixture_path('invalid.json')}") | ||
|
|
||
| expected_logs = [ | ||
| "#{@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", | ||
| ] | ||
|
|
||
| assert_equal(expected_logs, d.logs) | ||
| end | ||
|
|
||
| test "timeout with slow server" do | ||
| server = create_slow_webserver(port: 12345) | ||
|
|
||
| mock(Fluent::Plugin::ObsoletePluginsUtils).notify.never | ||
|
|
||
| d = create_driver(%[ | ||
| plugins_json http://localhost:12345/plugins.json | ||
| timeout 1 | ||
| ]) | ||
|
|
||
| sleep 2 | ||
|
|
||
| expected_logs = [ | ||
| "#{@time} [info]: Failed to notify obsolete plugins error_class=Timeout::Error error=\"execution expired\"\n", | ||
| ] | ||
|
|
||
| assert_equal(expected_logs, d.logs) | ||
| ensure | ||
| server.shutdown | ||
| end | ||
|
|
||
| end | ||
|
|
||
| private | ||
|
|
||
| def create_driver(conf) | ||
| Fluent::Test::Driver::Input.new(Fluent::Plugin::ObsoletePluginsInput).configure(conf) | ||
| end | ||
|
|
||
| def create_slow_webserver(port: 12345) | ||
| require "webrick" | ||
|
|
||
| server = WEBrick::HTTPServer.new(Port: port) | ||
| server.mount_proc '/' do |req, res| | ||
| sleep 60 | ||
|
|
||
| res['Content-Type'] = 'application/json' | ||
| res.body = File.read(fixture_path("plugins.json")) | ||
| end | ||
|
|
||
| server | ||
| end | ||
| end | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.