linkedin/kafka-tools

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

Summary

Maintainability
C
1 day
Test Coverage

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

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

        # Initialize broker deques for each position for remainder assignment
        ordered_brokers = sorted(self.cluster.brokers.keys())
Severity: Minor
Found in kafka/tools/assigner/actions/balancemodules/even.py - About 7 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

Avoid deeply nested control flow statements.
Open

                        if pmap[pos][partition.replicas[pos].id] <= target:
                            continue

                        # Find a new replica for the partition at this position
                        for bid in pmap[pos]:
Severity: Major
Found in kafka/tools/assigner/actions/balancemodules/even.py - About 45 mins to fix

    Avoid deeply nested control flow statements.
    Open

                            for bid in pmap[pos]:
                                if pmap[pos][bid] >= target:
                                    continue
                                broker = self.cluster.brokers[bid]
                                source = partition.replicas[pos]
    Severity: Major
    Found in kafka/tools/assigner/actions/balancemodules/even.py - About 45 mins to fix

      Function pmap_matches_target has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

      def pmap_matches_target(pmap, target):
          for pos in pmap:
              for broker_id in pos:
                  if pos[broker_id] != target:
                      return False
      Severity: Minor
      Found in kafka/tools/assigner/actions/balancemodules/even.py - 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

      There are no issues that match your filters.

      Category
      Status