atlassian/themis

View on GitHub
themis/monitoring/emr_monitoring.py

Summary

Maintainability
F
3 days
Test Coverage

Function init_emr_config has a Cognitive Complexity of 49 (exceeds 5 allowed). Consider refactoring.
Open

def init_emr_config(run_parallel=False, role=None):
    cfg = ResourcesConfiguration()

    emr_client = aws_common.connect_emr(role=role)

Severity: Minor
Found in themis/monitoring/emr_monitoring.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

Function do_add_stats has a Cognitive Complexity of 47 (exceeds 5 allowed). Consider refactoring.
Open

def do_add_stats(nodelist, result_map):

    load_aggregates = ('average', 'sum', 'min', 'max')
    all_aggregates = load_aggregates + ('count', )
    load_metrics = ('cpu', 'mem', 'sysload')
Severity: Minor
Found in themis/monitoring/emr_monitoring.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

File emr_monitoring.py has 356 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import subprocess
import re
import os
import json
import math
Severity: Minor
Found in themis/monitoring/emr_monitoring.py - About 4 hrs to fix

    Function collect_info has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
    Open

    def collect_info(cluster, nodes=None, config=None,
            monitoring_interval_secs=MONITORING_INTERVAL_SECS):
        try:
            # LOG.info('Collect monitoring info for cluster %s' % cluster.id)
            result = {}
    Severity: Minor
    Found in themis/monitoring/emr_monitoring.py - 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

    Function get_node_load_part has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

    def get_node_load_part(cluster, host, type, monitoring_interval_secs=MONITORING_INTERVAL_SECS):
        ganglia_data = get_ganglia_datapoints(cluster, host, type, monitoring_interval_secs)
        if not ganglia_data:
            return float('NaN')
        curves_map = {}
    Severity: Minor
    Found in themis/monitoring/emr_monitoring.py - 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

    Avoid deeply nested control flow statements.
    Open

                        if item_value < map_min[metr]:
                            map_min[metr] = item_value
                        map_sum[metr] += item_value
    Severity: Major
    Found in themis/monitoring/emr_monitoring.py - About 45 mins to fix

      Avoid deeply nested control flow statements.
      Open

                          if item_value > map_max[metr]:
                              map_max[metr] = item_value
                          if item_value < map_min[metr]:
      Severity: Major
      Found in themis/monitoring/emr_monitoring.py - About 45 mins to fix

        Function get_node_queries has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

        def get_node_queries(cluster):
            cmd = ('presto-cli --execute \\"SELECT n.http_uri,count(q.node_id) from system.runtime.nodes n ' +
                'left join (select * from system.runtime.queries where state = \'RUNNING\' ) as q ' +
                'on q.node_id = n.node_id group by n.http_uri\\"')
        
        
        Severity: Minor
        Found in themis/monitoring/emr_monitoring.py - 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

        Avoid deeply nested control flow statements.
        Open

                                for inst in out2['Instances']:
                                    if inst['InstanceGroupId'] == g['Id']:
                                        cluster.ip = inst['PrivateDnsName']
                        cfg.emr.append(cluster)
        Severity: Major
        Found in themis/monitoring/emr_monitoring.py - About 45 mins to fix

          Function get_presto_node_states has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

          def get_presto_node_states(nodes, cluster_ip):
              def query(host, node_info):
                  node_info['presto_state'] = 'N/A'
                  try:
                      if node_info['state'] == aws_common.INSTANCE_STATE_RUNNING:
          Severity: Minor
          Found in themis/monitoring/emr_monitoring.py - 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

          Function remove_array_with_NaN has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

          def remove_array_with_NaN(array):
              i = 0
              while i < len(array):
                  for item in array[i]:
                      if item == 'NaN' or math.isnan(item):
          Severity: Minor
          Found in themis/monitoring/emr_monitoring.py - 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

          Avoid too many return statements within this function.
          Open

                      return float('NaN')
          Severity: Major
          Found in themis/monitoring/emr_monitoring.py - About 30 mins to fix

            Avoid too many return statements within this function.
            Open

                    return 1.0 - (mem_free / mem_total)
            Severity: Major
            Found in themis/monitoring/emr_monitoring.py - About 30 mins to fix

              Avoid too many return statements within this function.
              Open

                          return float('NaN')
              Severity: Major
              Found in themis/monitoring/emr_monitoring.py - About 30 mins to fix

                Avoid too many return statements within this function.
                Open

                    return float('NaN')
                Severity: Major
                Found in themis/monitoring/emr_monitoring.py - About 30 mins to fix

                  Avoid too many return statements within this function.
                  Open

                          return avg_load
                  Severity: Major
                  Found in themis/monitoring/emr_monitoring.py - About 30 mins to fix

                    Error: invalid syntax (<unknown>, line 70)</unknown>
                    Open

                            except Exception, e:
                    Severity: Minor
                    Found in themis/monitoring/emr_monitoring.py by radon

                    We encountered an error attempting to analyze this line.

                    TODO found
                    Open

                        # TODO
                    Severity: Minor
                    Found in themis/monitoring/emr_monitoring.py by fixme

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

                            core_nodes = [n for n in data['nodes_list'] if n['type'] == aws_common.INSTANCE_GROUP_TYPE_CORE]
                    Severity: Major
                    Found in themis/monitoring/emr_monitoring.py and 2 other locations - About 45 mins to fix
                    themis/monitoring/emr_monitoring.py on lines 297..297
                    themis/monitoring/emr_monitoring.py on lines 299..299

                    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 3 locations. Consider refactoring.
                    Open

                            task_nodes = [n for n in data['nodes_list'] if n['type'] == aws_common.INSTANCE_GROUP_TYPE_TASK]
                    Severity: Major
                    Found in themis/monitoring/emr_monitoring.py and 2 other locations - About 45 mins to fix
                    themis/monitoring/emr_monitoring.py on lines 299..299
                    themis/monitoring/emr_monitoring.py on lines 301..301

                    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 3 locations. Consider refactoring.
                    Open

                            master_nodes = [n for n in data['nodes_list'] if n['type'] == aws_common.INSTANCE_GROUP_TYPE_MASTER]
                    Severity: Major
                    Found in themis/monitoring/emr_monitoring.py and 2 other locations - About 45 mins to fix
                    themis/monitoring/emr_monitoring.py on lines 297..297
                    themis/monitoring/emr_monitoring.py on lines 301..301

                    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

                    There are no issues that match your filters.

                    Category
                    Status