fluent / fluentd

Fluentd: Unified Logging Layer (project under CNCF)
https://www.fluentd.org
Apache License 2.0
12.94k stars 1.34k forks source link

How to check the versions of fluentd plugin gems actually used #1799

Open cosmo0920 opened 6 years ago

cosmo0920 commented 6 years ago

Check CONTRIBUTING guideline first and here is the list to help us investigate the problem.

Currently, Fluentd supervisor prints fluentd plugins which are recognized by Fluend at start-up. But there is no short-hand way to confirm the versions of fluentd plugin gems actually used.

repeatedly commented 6 years ago

One easy way is storing loaded plugin info like below:

diff --git a/lib/fluent/engine.rb b/lib/fluent/engine.rb
index 5aa1a53..4cb9881 100644
--- a/lib/fluent/engine.rb
+++ b/lib/fluent/engine.rb
@@ -39,6 +39,7 @@ module Fluent
       @log_event_loop_graceful_stop = false
       @log_event_queue = []
       @log_event_verbose = false
+      @loaded_plugins = []

       @suppress_config_dump = false

@@ -269,8 +270,17 @@ module Fluent
       @_worker_id
     end

+    def add_loaded_plugin(name, type, ver, path)
+      ver = 'master' if ver.nil?
+      @loaded_plugins << [name, type, ver, path]
+    end
+
     private
+
     def start
+      @loaded_plugins.each { |name, type, ver, path|
+        $log.info :worker0, "#{name} #{type} plugin #{ver} is used in '#{path}'"
+      }
       @root_agent.start
     end

diff --git a/lib/fluent/registry.rb b/lib/fluent/registry.rb
index 32f14bd..0f848ed 100644
--- a/lib/fluent/registry.rb
+++ b/lib/fluent/registry.rb
@@ -65,7 +65,9 @@ module Fluent
         }.compact
         unless files.empty?
           # prefer newer version
-          require files.sort.last
+          target = files.sort.last
+          Fluent::Engine.add_loaded_plugin(type, @kind, nil, target)
+          require target
           return
         end
       end
@@ -83,7 +85,9 @@ module Fluent
       }.compact
       unless files.empty?
         # prefer newer version
-        require files.sort.last
+        target = files.sort.last
+        Fluent::Engine.add_loaded_plugin(type, @kind, nil, target)
+        require target
         return
       end

@@ -99,6 +103,7 @@ module Fluent
         spec.require_paths.each { |lib|
           file = "#{spec.full_gem_path}/#{lib}/#{path}"
           if File.exist?("#{file}.rb")
+            Fluent::Engine.add_loaded_plugin(type, @kind, spec.version, 'gem')
             require file
             return
           end
@@ -108,6 +113,7 @@ module Fluent
       # Lastly, load built-in plugin
       lpath = File.expand_path(File.join(FLUENT_LIB_PATH, "#{@search_prefix}#{type}.rb"))
       if File.exist?(lpath)
+        Fluent::Engine.add_loaded_plugin(type, @kind, Fluent::VERSION, 'core')
         require lpath
         return
       end
2018-02-08 05:28:00 +0900 [info]: kafka output plugin master is used in '/Users/repeatedly/dev/fluentd/fluent-plugin-kafka/lib/fluent/plugin/out_kafka.rb'
2018-02-08 05:28:00 +0900 [info]: stdout output plugin master is used in '/Users/repeatedly/dev/fluentd/fluentd/lib/fluent/plugin/out_stdout.rb'
2018-02-08 05:28:00 +0900 [info]: memory buffer plugin master is used in '/Users/repeatedly/dev/fluentd/fluentd/lib/fluent/plugin/buf_memory.rb'
2018-02-08 05:28:00 +0900 [info]: stdout formatter plugin master is used in '/Users/repeatedly/dev/fluentd/fluentd/lib/fluent/plugin/formatter_stdout.rb'
2018-02-08 05:28:00 +0900 [info]: json formatter plugin master is used in '/Users/repeatedly/dev/fluentd/fluentd/lib/fluent/plugin/formatter_json.rb'
2018-02-08 05:28:00 +0900 [info]: http input plugin master is used in '/Users/repeatedly/dev/fluentd/fluentd/lib/fluent/plugin/in_http.rb'
2018-02-08 05:28:00 +0900 [info]: msgpack parser plugin master is used in '/Users/repeatedly/dev/fluentd/fluentd/lib/fluent/plugin/parser_msgpack.rb'
2018-02-08 05:28:00 +0900 [info]: json parser plugin master is used in '/Users/repeatedly/dev/fluentd/fluentd/lib/fluent/plugin/parser_json.rb'
cosmo0920 commented 6 years ago

Thank you for your comment. I've confirm that the above patch works for me.

cosmo0920 commented 6 years ago

And the above patch also what I want. Awesome. Thanks!

dchimeno commented 6 years ago

This could be displayed with an appropiate log level for dev purposes.