linkedin/kafka-tools

View on GitHub
kafka/tools/assigner/actions/balancemodules/count.py

Summary

Maintainability
D
2 days
Test Coverage

Function process_cluster has a Cognitive Complexity of 105 (exceeds 5 allowed). Consider refactoring.
Open

    def process_cluster(self):
        log.info("Starting partition balance by count")

        # Figure out the max RF for the cluster and sort all partition lists by size (ascending)
        max_pos = self.cluster.max_replication_factor()
Severity: Minor
Found in kafka/tools/assigner/actions/balancemodules/count.py - About 2 days 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

Avoid deeply nested control flow statements.
Open

                        if diff == 0:
                            break
                        if (pos in target.partitions) and (target.num_partitions_at_position(pos) > (max_count[pos][0] + 1)):
Severity: Major
Found in kafka/tools/assigner/actions/balancemodules/count.py - About 45 mins to fix

    Avoid deeply nested control flow statements.
    Open

                            if pos not in source.partitions:
                                continue
    
    
    Severity: Major
    Found in kafka/tools/assigner/actions/balancemodules/count.py - About 45 mins to fix

      Avoid deeply nested control flow statements.
      Open

                              if (pos in target.partitions) and (target.num_partitions_at_position(pos) > (max_count[pos][0] + 1)):
                                  continue
      
      
      Severity: Major
      Found in kafka/tools/assigner/actions/balancemodules/count.py - About 45 mins to fix

        Avoid deeply nested control flow statements.
        Open

                                for partition in iterlist:
                                    # If we have moved enough partitions to this broker, exit out of the inner loop
                                    if ((pos in target.partitions) and (target.num_partitions_at_position(pos) >= max_count[pos][0])) or (diff == 0):
                                        break
                                    # Skip partitions that are already on the target broker or are being excluded
        Severity: Major
        Found in kafka/tools/assigner/actions/balancemodules/count.py - About 45 mins to fix

          Avoid deeply nested control flow statements.
          Open

                                  for partition in iterlist:
                                      # If we have moved enough partitions from this broker, exit out of the inner loop
                                      if (source.num_partitions_at_position(pos) < max_count[pos][0]) or (diff == 0):
                                          break
          
          
          Severity: Major
          Found in kafka/tools/assigner/actions/balancemodules/count.py - About 45 mins to fix

            Avoid deeply nested control flow statements.
            Open

                                    if diff == 0:
                                        break
                                    if pos not in source.partitions:
            Severity: Major
            Found in kafka/tools/assigner/actions/balancemodules/count.py - About 45 mins to fix

              There are no issues that match your filters.

              Category
              Status