cloudfoundry/collector

View on GitHub

Showing 12 of 12 total issues

Method fetch has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
Open

    def fetch(type)
      @components.each do |job, instances|
        instances.each do |index, instance|
          next unless credentials_ok?(job, instance)

Severity: Minor
Found in lib/collector.rb - 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

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

  class Handler
    class LoggregatorRouter < Handler
      def process(context)
        varz_message = context.varz
        component_name = varz_message['name']
Severity: Major
Found in lib/collector/handlers/loggregator_trafficcontroller.rb and 2 other locations - About 2 hrs to fix
lib/collector/handlers/doppler_server.rb on lines 2..23
lib/collector/handlers/loggregator_dea_agent.rb on lines 2..23

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

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

  class Handler
    class LoggregatorDeaAgent < Handler
      def process(context)
        varz_message = context.varz
        component_name = varz_message['name']
Severity: Major
Found in lib/collector/handlers/loggregator_dea_agent.rb and 2 other locations - About 2 hrs to fix
lib/collector/handlers/doppler_server.rb on lines 2..23
lib/collector/handlers/loggregator_trafficcontroller.rb on lines 2..23

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

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

  class Handler
    class DopplerServer < Handler
      def process(context)
        varz_message = context.varz
        component_name = varz_message['name']
Severity: Major
Found in lib/collector/handlers/doppler_server.rb and 2 other locations - About 2 hrs to fix
lib/collector/handlers/loggregator_dea_agent.rb on lines 2..23
lib/collector/handlers/loggregator_trafficcontroller.rb on lines 2..23

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

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 fetch has 37 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    def fetch(type)
      @components.each do |job, instances|
        instances.each do |index, instance|
          next unless credentials_ok?(job, instance)

Severity: Minor
Found in lib/collector.rb - About 1 hr to fix

    Method process has 31 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

          def process(context)
            varz = context.varz
    
            send_metric("router.total_requests", varz["requests"], context)
            send_metric("router.total_routes", varz["urls"], context)
    Severity: Minor
    Found in lib/collector/handlers/router.rb - About 1 hr to fix

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

            def configure(config)
              @index = config["index"].to_i
              setup_logging(config["logging"])
      
              @deployment_name = config["deployment_name"] || "untitled_dev"
      Severity: Minor
      Found in lib/collector/config.rb - About 1 hr to fix

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

            def unbind
              if @port && @ip
                Config.logger.warn("#{@logger_name}-connection-lost")
                EM.add_timer(1.0) do
                  begin
        Severity: Minor
        Found in lib/collector/tcp_connection.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 do_process has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

            def do_process(context)
              varz = context.varz
        
              MEM_AND_CPU_STATS.each { |stat| send_metric(stat, varz[stat], context) if varz[stat] }
        
        
        Severity: Minor
        Found in lib/collector/handler.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 process_plan_score_metric has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

            def process_plan_score_metric(context)
              varz = context.varz
        
              return unless varz.include?("plans")
              if varz["plans"]
        Severity: Minor
        Found in lib/collector/service_gateway_handler.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 get_metrics_name has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

              def get_metrics_name(properties)
                # Given a properties hash like so
                # {:key=>"cpu_load_avg", :timestamp=>1394801347, :value=>0.25, :tags=>{:ip=>"172.30.5.74", :role=>"core", :job=>"CloudController", :index=>0, :name=>"CloudController/0", :deployment=>"CF"}}
                # One will get a metrics key like so
                # CF.CloudController.0.172-30-5-74.cpu_load_avg
        Severity: Minor
        Found in lib/collector/historian/graphite.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 process has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

              def process(context)
                varz = context.varz
        
                send_metric("router.total_requests", varz["requests"], context)
                send_metric("router.total_routes", varz["urls"], context)
        Severity: Minor
        Found in lib/collector/handlers/router.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

        Severity
        Category
        Status
        Source
        Language