karafka/waterdrop

View on GitHub

Showing 16 of 28 total issues

Method produce has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
Open

    def produce(message)
      produce_time ||= monotonic_now

      # This can happen only during flushing on closing, in case like this we don't have to
      # synchronize because we already own the lock
Severity: Minor
Found in lib/waterdrop/producer.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 close has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
Open

    def close(force: false)
      @operating_mutex.synchronize do
        return unless @status.active?

        @monitor.instrument(
Severity: Minor
Found in lib/waterdrop/producer.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

Class LoggerListener has 23 methods (exceeds 20 allowed). Consider refactoring.
Open

    class LoggerListener
      # @param logger [Object] logger we want to use
      # @param log_messages [Boolean] Should we report the messages content (payload and metadata)
      #   with each message operation.
      #
Severity: Minor
Found in lib/waterdrop/instrumentation/logger_listener.rb - About 2 hrs to fix

    Method transaction has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
    Open

          def transaction
            # This will safely allow us to support one operation transactions so a transactional
            # producer can work without the transactional block if needed
            return yield if @transaction_mutex.owned?
    
    
    Severity: Minor
    Found in lib/waterdrop/producer/transactions.rb - About 1 hr 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 produce has 40 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        def produce(message)
          produce_time ||= monotonic_now
    
          # This can happen only during flushing on closing, in case like this we don't have to
          # synchronize because we already own the lock
    Severity: Minor
    Found in lib/waterdrop/producer.rb - About 1 hr to fix

      Method transaction has 32 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

            def transaction
              # This will safely allow us to support one operation transactions so a transactional
              # producer can work without the transactional block if needed
              return yield if @transaction_mutex.owned?
      
      
      Severity: Minor
      Found in lib/waterdrop/producer/transactions.rb - About 1 hr to fix

        Method with_transactional_error_handling has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
        Open

              def with_transactional_error_handling(action, allow_abortable: true)
                attempt ||= 0
                attempt += 1
        
                yield
        Severity: Minor
        Found in lib/waterdrop/producer/transactions.rb - About 1 hr 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 report_metric has 30 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

                  def report_metric(metric, statistics)
                    case metric.scope
                    when :root
                      public_send(
                        metric.type,
        Severity: Minor
        Found in lib/waterdrop/instrumentation/vendors/datadog/metrics_listener.rb - About 1 hr to fix

          Method close has 29 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              def close(force: false)
                @operating_mutex.synchronize do
                  return unless @status.active?
          
                  @monitor.instrument(
          Severity: Minor
          Found in lib/waterdrop/producer.rb - About 1 hr to fix

            Method with_transactional_error_handling has 28 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                  def with_transactional_error_handling(action, allow_abortable: true)
                    attempt ||= 0
                    attempt += 1
            
                    yield
            Severity: Minor
            Found in lib/waterdrop/producer/transactions.rb - About 1 hr to fix

              Method transaction_mark_as_consumed has 27 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                    def transaction_mark_as_consumed(consumer, message, offset_metadata = nil)
                      raise Errors::TransactionRequiredError unless @transaction_mutex.owned?
              
                      CONTRACT.validate!(
                        {
              Severity: Minor
              Found in lib/waterdrop/producer/transactions.rb - About 1 hr to fix

                Method produce_many_async has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                      def produce_many_async(messages)
                        dispatched = []
                        messages = middleware.run_many(messages)
                        messages.each { |message| validate_message!(message) }
                
                
                Severity: Minor
                Found in lib/waterdrop/producer/async.rb - About 1 hr to fix

                  Method client has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                  Open

                      def client
                        return @client if @client && @pid == Process.pid
                  
                        # Don't allow to obtain a client reference for a producer that was not configured
                        raise Errors::ProducerNotConfiguredError, id if @status.initial?
                  Severity: Minor
                  Found in lib/waterdrop/producer.rb - About 45 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

                  Method transactional_reload_client_if_needed has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                  Open

                        def transactional_reload_client_if_needed(error)
                          rd_error = error.is_a?(Rdkafka::RdkafkaError) ? error : error.cause
                  
                          return unless rd_error.is_a?(Rdkafka::RdkafkaError)
                          return unless config.reload_on_transaction_fatal_error
                  Severity: Minor
                  Found in lib/waterdrop/producer/transactions.rb - About 35 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

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

                          def call(delivery_report)
                            error_code = delivery_report.error.to_i
                  
                            if error_code.zero?
                              instrument_acknowledged(delivery_report)
                  Severity: Minor
                  Found in lib/waterdrop/instrumentation/callbacks/delivery.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

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

                      def ensure_active!
                        return if @status.active?
                        return if @status.closing? && @operating_mutex.owned?
                  
                        raise Errors::ProducerNotConfiguredError, id if @status.initial?
                  Severity: Minor
                  Found in lib/waterdrop/producer.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

                  Severity
                  Category
                  Status
                  Source
                  Language