fluent/fluentd

View on GitHub
lib/fluent/plugin_helper/server.rb

Summary

Maintainability
F
4 days
Test Coverage

File server.rb has 618 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require 'fluent/plugin_helper/event_loop'

require 'serverengine'
require 'cool.io'
require 'socket'
Severity: Major
Found in lib/fluent/plugin_helper/server.rb - About 1 day to fix

    Method server_create has a Cognitive Complexity of 39 (exceeds 5 allowed). Consider refactoring.
    Open

          def server_create(title, port, proto: nil, bind: '0.0.0.0', shared: true, socket: nil, backlog: nil, tls_options: nil, max_bytes: nil, flags: 0, **socket_options, &callback)
            proto ||= (@transport_config && @transport_config.protocol == :tls) ? :tls : :tcp
    
            raise ArgumentError, "BUG: title must be a symbol" unless title && title.is_a?(Symbol)
            raise ArgumentError, "BUG: port must be an integer" unless port && port.is_a?(Integer)
    Severity: Minor
    Found in lib/fluent/plugin_helper/server.rb - About 5 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Method server_create_connection has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
    Open

          def server_create_connection(title, port, proto: nil, bind: '0.0.0.0', shared: true, backlog: nil, tls_options: nil, **socket_options, &block)
            proto ||= (@transport_config && @transport_config.protocol == :tls) ? :tls : :tcp
    
            raise ArgumentError, "BUG: title must be a symbol" unless title && title.is_a?(Symbol)
            raise ArgumentError, "BUG: port must be an integer" unless port && port.is_a?(Integer)
    Severity: Minor
    Found in lib/fluent/plugin_helper/server.rb - About 3 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Method server_create has 55 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

          def server_create(title, port, proto: nil, bind: '0.0.0.0', shared: true, socket: nil, backlog: nil, tls_options: nil, max_bytes: nil, flags: 0, **socket_options, &callback)
            proto ||= (@transport_config && @transport_config.protocol == :tls) ? :tls : :tcp
    
            raise ArgumentError, "BUG: title must be a symbol" unless title && title.is_a?(Symbol)
            raise ArgumentError, "BUG: port must be an integer" unless port && port.is_a?(Integer)
    Severity: Major
    Found in lib/fluent/plugin_helper/server.rb - About 2 hrs to fix

      Method try_tls_accept has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
      Open

                def try_tls_accept
                  return true if @_handler_accepted
      
                  begin
                    result = @_handler_socket.accept_nonblock(exception: false) # this method call actually try to do handshake via TLS
      Severity: Minor
      Found in lib/fluent/plugin_helper/server.rb - About 2 hrs to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Method server_create_connection has 31 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

            def server_create_connection(title, port, proto: nil, bind: '0.0.0.0', shared: true, backlog: nil, tls_options: nil, **socket_options, &block)
              proto ||= (@transport_config && @transport_config.protocol == :tls) ? :tls : :tcp
      
              raise ArgumentError, "BUG: title must be a symbol" unless title && title.is_a?(Symbol)
              raise ArgumentError, "BUG: port must be an integer" unless port && port.is_a?(Integer)
      Severity: Minor
      Found in lib/fluent/plugin_helper/server.rb - About 1 hr to fix

        Method server_create_for_tls_connection has 7 arguments (exceeds 4 allowed). Consider refactoring.
        Open

              def server_create_for_tls_connection(shared, bind, port, conf, backlog, socket_option_setter, &block)
        Severity: Major
        Found in lib/fluent/plugin_helper/server.rb - About 50 mins to fix

          Method initialize has 7 arguments (exceeds 4 allowed). Consider refactoring.
          Open

                    def initialize(sock, context, socket_option_setter, close_callback, log, under_plugin_development, connect_callback)
          Severity: Major
          Found in lib/fluent/plugin_helper/server.rb - About 50 mins to fix

            Method initialize has 7 arguments (exceeds 4 allowed). Consider refactoring.
            Open

                      def initialize(sock, max_bytes, flags, close_socket, log, under_plugin_development, &callback)
            Severity: Major
            Found in lib/fluent/plugin_helper/server.rb - About 50 mins to fix

              Method server_attach has 6 arguments (exceeds 4 allowed). Consider refactoring.
              Open

                    def server_attach(title, proto, port, bind, shared, server)
              Severity: Minor
              Found in lib/fluent/plugin_helper/server.rb - About 45 mins to fix

                Method server_create_for_tcp_connection has 6 arguments (exceeds 4 allowed). Consider refactoring.
                Open

                      def server_create_for_tcp_connection(shared, bind, port, backlog, socket_option_setter, &block)
                Severity: Minor
                Found in lib/fluent/plugin_helper/server.rb - About 45 mins to fix

                  Method initialize has 6 arguments (exceeds 4 allowed). Consider refactoring.
                  Open

                            def initialize(sock, socket_option_setter, close_callback, log, under_plugin_development, connect_callback)
                  Severity: Minor
                  Found in lib/fluent/plugin_helper/server.rb - About 45 mins to fix

                    Method stop has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                    Open

                          def stop
                            @_server_mutex.synchronize do
                              @_servers.each do |si|
                                si.server.detach if si.server.attached?
                                # to refuse more connections: (connected sockets are still alive here)
                    Severity: Minor
                    Found in lib/fluent/plugin_helper/server.rb - About 25 mins to fix

                    Cognitive Complexity

                    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                    A method's cognitive complexity is based on a few simple rules:

                    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                    • Code is considered more complex for each "break in the linear flow of the code"
                    • Code is considered more complex when "flow breaking structures are nested"

                    Further reading

                    Identical blocks of code found in 2 locations. Consider refactoring.
                    Open

                              def on_read_with_connection(data)
                                @data_callback.call(data, @callback_connection)
                              rescue => e
                                @log.error "unexpected error on reading data", host: @callback_connection.remote_host, port: @callback_connection.remote_port, error: e
                                @log.error_backtrace
                    Severity: Minor
                    Found in lib/fluent/plugin_helper/server.rb and 1 other location - About 30 mins to fix
                    lib/fluent/plugin_helper/server.rb on lines 648..655

                    Duplicated Code

                    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                    Tuning

                    This issue has a mass of 33.

                    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                    Refactorings

                    Further Reading

                    Identical blocks of code found in 2 locations. Consider refactoring.
                    Open

                              def on_read_with_connection(data)
                                @data_callback.call(data, @callback_connection)
                              rescue => e
                                @log.error "unexpected error on reading data", host: @callback_connection.remote_host, port: @callback_connection.remote_port, error: e
                                @log.error_backtrace
                    Severity: Minor
                    Found in lib/fluent/plugin_helper/server.rb and 1 other location - About 30 mins to fix
                    lib/fluent/plugin_helper/server.rb on lines 807..814

                    Duplicated Code

                    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                    Tuning

                    This issue has a mass of 33.

                    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                    Refactorings

                    Further Reading

                    Identical blocks of code found in 2 locations. Consider refactoring.
                    Open

                              def on_read_without_connection(data)
                                @data_callback.call(data)
                              rescue => e
                                @log.error "unexpected error on reading data", host: @callback_connection.remote_host, port: @callback_connection.remote_port, error: e
                                @log.error_backtrace
                    Severity: Minor
                    Found in lib/fluent/plugin_helper/server.rb and 1 other location - About 30 mins to fix
                    lib/fluent/plugin_helper/server.rb on lines 639..646

                    Duplicated Code

                    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                    Tuning

                    This issue has a mass of 32.

                    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                    Refactorings

                    Further Reading

                    Identical blocks of code found in 2 locations. Consider refactoring.
                    Open

                              def on_read_without_connection(data)
                                @data_callback.call(data)
                              rescue => e
                                @log.error "unexpected error on reading data", host: @callback_connection.remote_host, port: @callback_connection.remote_port, error: e
                                @log.error_backtrace
                    Severity: Minor
                    Found in lib/fluent/plugin_helper/server.rb and 1 other location - About 30 mins to fix
                    lib/fluent/plugin_helper/server.rb on lines 798..805

                    Duplicated Code

                    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                    Tuning

                    This issue has a mass of 32.

                    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                    Refactorings

                    Further Reading

                    Similar blocks of code found in 2 locations. Consider refactoring.
                    Open

                          def server_create_udp_socket(shared, bind, port)
                            sock = if shared
                                     server_socket_manager_client.listen_udp(bind, port)
                                   else
                                     # UDPSocket.new doesn't set IPV6_V6ONLY flag, so use Addrinfo class instead.
                    Severity: Minor
                    Found in lib/fluent/plugin_helper/server.rb and 1 other location - About 25 mins to fix
                    lib/fluent/plugin_helper/server.rb on lines 370..382

                    Duplicated Code

                    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                    Tuning

                    This issue has a mass of 30.

                    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                    Refactorings

                    Further Reading

                    Identical blocks of code found in 2 locations. Consider refactoring.
                    Open

                              def data(&callback)
                                raise "data callback can be registered just once, but registered twice" if self.singleton_methods.include?(:on_read)
                                @data_callback = callback
                                on_read_impl = case callback.arity
                                               when 1 then :on_read_without_connection
                    Severity: Minor
                    Found in lib/fluent/plugin_helper/server.rb and 1 other location - About 25 mins to fix
                    lib/fluent/plugin_helper/server.rb on lines 700..709

                    Duplicated Code

                    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                    Tuning

                    This issue has a mass of 30.

                    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                    Refactorings

                    Further Reading

                    Identical blocks of code found in 2 locations. Consider refactoring.
                    Open

                              def data(&callback)
                                raise "data callback can be registered just once, but registered twice" if self.singleton_methods.include?(:on_read)
                                @data_callback = callback
                                on_read_impl = case callback.arity
                                               when 1 then :on_read_without_connection
                    Severity: Minor
                    Found in lib/fluent/plugin_helper/server.rb and 1 other location - About 25 mins to fix
                    lib/fluent/plugin_helper/server.rb on lines 608..617

                    Duplicated Code

                    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                    Tuning

                    This issue has a mass of 30.

                    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                    Refactorings

                    Further Reading

                    Similar blocks of code found in 2 locations. Consider refactoring.
                    Open

                          def server_create_tcp_socket(shared, bind, port)
                            sock = if shared
                                     server_socket_manager_client.listen_tcp(bind, port)
                                   else
                                     # TCPServer.new doesn't set IPV6_V6ONLY flag, so use Addrinfo class instead.
                    Severity: Minor
                    Found in lib/fluent/plugin_helper/server.rb and 1 other location - About 25 mins to fix
                    lib/fluent/plugin_helper/server.rb on lines 385..396

                    Duplicated Code

                    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                    Tuning

                    This issue has a mass of 30.

                    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                    Refactorings

                    Further Reading

                    There are no issues that match your filters.

                    Category
                    Status