karafka/waterdrop

View on GitHub

Showing 28 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

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

                        virtual do |config, errors|
                          next true unless errors.empty?
                          # Relevant only for the transactional producer
                          next true unless config.fetch(:transactional)
                  
                  
                  Severity: Minor
                  Found in lib/waterdrop/contracts/variant.rb and 1 other location - About 45 mins to fix
                  lib/waterdrop/contracts/variant.rb on lines 90..103

                  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 39.

                  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

                        virtual do |config, errors|
                          next true unless errors.empty?
                          # Relevant only for the transactional producer
                          next true unless config.fetch(:idempotent)
                  
                  
                  Severity: Minor
                  Found in lib/waterdrop/contracts/variant.rb and 1 other location - About 45 mins to fix
                  lib/waterdrop/contracts/variant.rb on lines 73..86

                  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 39.

                  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

                  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

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

                        def on_messages_produced_sync(event)
                          messages = event[:messages]
                          topics_count = messages.map { |message| "'#{message[:topic]}'" }.uniq.count
                  
                          info(event, "Sync producing of #{messages.size} messages to #{topics_count} topics")
                  Severity: Minor
                  Found in lib/waterdrop/instrumentation/logger_listener.rb and 1 other location - About 35 mins to fix
                  lib/waterdrop/instrumentation/logger_listener.rb on lines 48..56

                  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 35.

                  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 on_messages_produced_async(event)
                          messages = event[:messages]
                          topics_count = messages.map { |message| "'#{message[:topic]}'" }.uniq.count
                  
                          info(event, "Async producing of #{messages.size} messages to #{topics_count} topics")
                  Severity: Minor
                  Found in lib/waterdrop/instrumentation/logger_listener.rb and 1 other location - About 35 mins to fix
                  lib/waterdrop/instrumentation/logger_listener.rb on lines 60..68

                  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 35.

                  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

                        virtual do |config, errors|
                          next true unless errors.empty?
                  
                          errors = []
                  
                  
                  Severity: Minor
                  Found in lib/waterdrop/contracts/config.rb and 1 other location - About 30 mins to fix
                  lib/waterdrop/contracts/variant.rb on lines 41..52

                  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

                        virtual do |config, errors|
                          next true unless errors.empty?
                  
                          errors = []
                  
                  
                  Severity: Minor
                  Found in lib/waterdrop/contracts/variant.rb and 1 other location - About 30 mins to fix
                  lib/waterdrop/contracts/config.rb on lines 39..50

                  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

                  Severity
                  Category
                  Status
                  Source
                  Language