fluentd icon indicating copy to clipboard operation
fluentd copied to clipboard

How to check the versions of fluentd plugin gems actually used

Open cosmo0920 opened this issue 6 years ago • 4 comments

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

  • fluentd or td-agent version. Fluentd v0.14
  • Your problem explanation. If you have an error logs, write it together.

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.

cosmo0920 avatar Dec 21 '17 02:12 cosmo0920

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
  • log example:
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'

repeatedly avatar Feb 07 '18 20:02 repeatedly

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

cosmo0920 avatar Feb 08 '18 08:02 cosmo0920

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

cosmo0920 avatar Feb 08 '18 09:02 cosmo0920

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

dchimeno avatar Aug 06 '18 09:08 dchimeno